2015-07-13 17:20:48 +00:00
|
|
|
from libc.string cimport memcpy
|
|
|
|
from cpython.mem cimport PyMem_Malloc, PyMem_Free
|
|
|
|
# Compiler crashes on memory view coercion without this. Should report bug.
|
|
|
|
from cython.view cimport array as cvarray
|
2015-07-13 18:20:58 +00:00
|
|
|
cimport numpy as np
|
|
|
|
np.import_array()
|
|
|
|
|
|
|
|
import numpy
|
2015-11-02 18:22:18 +00:00
|
|
|
import six
|
2015-07-13 18:20:58 +00:00
|
|
|
|
|
|
|
|
2016-09-23 12:22:06 +00:00
|
|
|
from ..typedefs cimport hash_t
|
2015-09-06 17:45:15 +00:00
|
|
|
from ..lexeme cimport Lexeme
|
2015-10-10 06:55:55 +00:00
|
|
|
from .. import parts_of_speech
|
2015-07-13 18:20:58 +00:00
|
|
|
|
2015-07-16 09:23:25 +00:00
|
|
|
from ..attrs cimport LEMMA
|
|
|
|
from ..attrs cimport ID, ORTH, NORM, LOWER, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER
|
|
|
|
from ..attrs cimport POS, LEMMA, TAG, DEP
|
2015-07-13 18:20:58 +00:00
|
|
|
from ..parts_of_speech cimport CONJ, PUNCT
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
from ..attrs cimport IS_ALPHA, IS_ASCII, IS_DIGIT, IS_LOWER, IS_PUNCT, IS_SPACE
|
2016-03-10 12:01:34 +00:00
|
|
|
from ..attrs cimport IS_BRACKET
|
|
|
|
from ..attrs cimport IS_QUOTE
|
|
|
|
from ..attrs cimport IS_LEFT_PUNCT
|
|
|
|
from ..attrs cimport IS_RIGHT_PUNCT
|
2015-07-26 14:37:16 +00:00
|
|
|
from ..attrs cimport IS_TITLE, IS_UPPER, LIKE_URL, LIKE_NUM, LIKE_EMAIL, IS_STOP
|
2015-07-26 23:50:06 +00:00
|
|
|
from ..attrs cimport IS_OOV
|
2015-07-26 14:37:16 +00:00
|
|
|
|
2015-08-23 18:49:18 +00:00
|
|
|
from ..lexeme cimport Lexeme
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2016-04-12 03:17:59 +00:00
|
|
|
_STR_TRAILING_WHITESPACE = False
|
|
|
|
|
|
|
|
def use_deprecated_Token__str__semantics(value):
|
|
|
|
'''
|
|
|
|
Preserve deprecated semantics for Token.__str__ and Token.__unicode__ methods.
|
|
|
|
|
|
|
|
spaCy < 0.100.7 had a bug in the semantics of the Token.__str__ and Token.__unicode__
|
|
|
|
built-ins: they included a trailing space. To ease the transition to the
|
|
|
|
new semantics, you can use this function to switch the old semantics back on.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
from spacy.tokens.token import keep_deprecated_Token.__str__semantics
|
|
|
|
keep_deprecated_Token.__str__semantics(True)
|
|
|
|
|
|
|
|
This function will not remain in future versions --- it's a temporary shim.
|
|
|
|
'''
|
|
|
|
global _STR_TRAILING_WHITESPACE
|
|
|
|
_STR_TRAILING_WHITESPACE = value
|
|
|
|
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
cdef class Token:
|
|
|
|
"""An individual token --- i.e. a word, a punctuation symbol, etc. Created
|
|
|
|
via Doc.__getitem__ and Doc.__iter__.
|
|
|
|
"""
|
2015-07-13 22:10:11 +00:00
|
|
|
def __cinit__(self, Vocab vocab, Doc doc, int offset):
|
2015-07-13 17:20:48 +00:00
|
|
|
self.vocab = vocab
|
2015-07-13 22:10:11 +00:00
|
|
|
self.doc = doc
|
2015-11-03 13:15:14 +00:00
|
|
|
self.c = &self.doc.c[offset]
|
2015-07-13 22:10:11 +00:00
|
|
|
self.i = offset
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return self.c.lex.length
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2016-04-12 03:17:59 +00:00
|
|
|
# Users can toggle this on to preserve former buggy semantics.
|
|
|
|
# Remove this in future versions.
|
|
|
|
if _STR_TRAILING_WHITESPACE:
|
|
|
|
return self.text_with_ws
|
|
|
|
else:
|
|
|
|
return self.text
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-11-02 18:22:18 +00:00
|
|
|
def __bytes__(self):
|
2016-04-12 03:17:59 +00:00
|
|
|
# Users can toggle this on to preserve former buggy semantics.
|
|
|
|
# Remove this in future versions.
|
|
|
|
if _STR_TRAILING_WHITESPACE:
|
|
|
|
return self.text_with_ws.encode('utf8')
|
|
|
|
else:
|
|
|
|
return self.text.encode('utf8')
|
2015-11-02 18:22:18 +00:00
|
|
|
|
2015-07-24 01:49:30 +00:00
|
|
|
def __str__(self):
|
2015-11-02 18:22:18 +00:00
|
|
|
if six.PY3:
|
|
|
|
return self.__unicode__()
|
|
|
|
return self.__bytes__()
|
2015-07-24 01:49:30 +00:00
|
|
|
|
2015-10-21 11:11:46 +00:00
|
|
|
def __repr__(self):
|
2015-11-02 18:22:18 +00:00
|
|
|
return self.__str__()
|
2015-10-21 11:11:46 +00:00
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
cpdef bint check_flag(self, attr_id_t flag_id) except -1:
|
2015-09-15 03:06:18 +00:00
|
|
|
return Lexeme.c_check_flag(self.c.lex, flag_id)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
def nbor(self, int i=1):
|
2015-07-13 22:10:11 +00:00
|
|
|
return self.doc[self.i+i]
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-09-14 07:49:58 +00:00
|
|
|
def similarity(self, other):
|
2015-09-22 00:10:01 +00:00
|
|
|
if self.vector_norm == 0 or other.vector_norm == 0:
|
|
|
|
return 0.0
|
2015-09-14 07:49:58 +00:00
|
|
|
return numpy.dot(self.vector, other.vector) / (self.vector_norm * other.vector_norm)
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property lex_id:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.id
|
|
|
|
|
2015-11-08 15:18:25 +00:00
|
|
|
property rank:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.id
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property string:
|
|
|
|
def __get__(self):
|
2016-01-16 16:14:34 +00:00
|
|
|
return self.text_with_ws
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-09-13 00:27:42 +00:00
|
|
|
property text:
|
|
|
|
def __get__(self):
|
|
|
|
return self.orth_
|
|
|
|
|
|
|
|
property text_with_ws:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
orth_ = self.orth_
|
2015-09-13 00:27:42 +00:00
|
|
|
if self.c.spacy:
|
2016-09-30 08:14:47 +00:00
|
|
|
return orth_ + u' '
|
2015-09-13 00:27:42 +00:00
|
|
|
else:
|
2016-09-30 08:14:47 +00:00
|
|
|
return orth_
|
2015-09-13 00:27:42 +00:00
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property prob:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.prob
|
|
|
|
|
2016-03-10 12:01:34 +00:00
|
|
|
property lang:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.lang
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property idx:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.idx
|
|
|
|
|
|
|
|
property cluster:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.cluster
|
|
|
|
|
|
|
|
property orth:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.orth
|
|
|
|
|
|
|
|
property lower:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.lower
|
|
|
|
|
|
|
|
property norm:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.norm
|
|
|
|
|
|
|
|
property shape:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.shape
|
|
|
|
|
|
|
|
property prefix:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.prefix
|
|
|
|
|
|
|
|
property suffix:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.suffix
|
|
|
|
|
|
|
|
property lemma:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lemma
|
|
|
|
|
|
|
|
property pos:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.pos
|
|
|
|
|
|
|
|
property tag:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.tag
|
|
|
|
|
|
|
|
property dep:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.dep
|
2016-03-11 16:31:06 +00:00
|
|
|
def __set__(self, int label):
|
|
|
|
self.c.dep = label
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-09-21 09:52:43 +00:00
|
|
|
property has_vector:
|
|
|
|
def __get__(self):
|
2015-09-21 23:43:16 +00:00
|
|
|
cdef int i
|
|
|
|
for i in range(self.vocab.vectors_length):
|
2015-11-03 12:47:59 +00:00
|
|
|
if self.c.lex.vector[i] != 0:
|
2015-09-21 23:43:16 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2015-09-21 09:52:43 +00:00
|
|
|
|
2015-09-14 07:49:58 +00:00
|
|
|
property vector:
|
2015-07-13 17:20:48 +00:00
|
|
|
def __get__(self):
|
2015-09-21 08:10:51 +00:00
|
|
|
cdef int length = self.vocab.vectors_length
|
2015-09-21 08:35:40 +00:00
|
|
|
if length == 0:
|
|
|
|
raise ValueError(
|
|
|
|
"Word vectors set to length 0. This may be because the "
|
|
|
|
"data is not installed. If you haven't already, run"
|
2016-03-24 10:47:09 +00:00
|
|
|
"\npython -m spacy.%s.download all\n"
|
|
|
|
"to install the data." % self.vocab.lang
|
2015-09-21 08:35:40 +00:00
|
|
|
)
|
2015-11-03 12:47:59 +00:00
|
|
|
vector_view = <float[:length,]>self.c.lex.vector
|
|
|
|
return numpy.asarray(vector_view)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2015-09-14 07:49:58 +00:00
|
|
|
property repvec:
|
|
|
|
def __get__(self):
|
|
|
|
return self.vector
|
|
|
|
|
|
|
|
property vector_norm:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.lex.l2_norm
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property n_lefts:
|
|
|
|
def __get__(self):
|
2016-03-21 15:10:25 +00:00
|
|
|
return self.c.l_kids
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property n_rights:
|
|
|
|
def __get__(self):
|
2016-03-21 15:10:25 +00:00
|
|
|
return self.c.r_kids
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property lefts:
|
|
|
|
def __get__(self):
|
|
|
|
"""The leftward immediate children of the word, in the syntactic
|
|
|
|
dependency parse.
|
|
|
|
"""
|
2016-01-16 15:18:17 +00:00
|
|
|
cdef int nr_iter = 0
|
2015-09-06 08:48:36 +00:00
|
|
|
cdef const TokenC* ptr = self.c - (self.i - self.c.l_edge)
|
2015-07-13 17:20:48 +00:00
|
|
|
while ptr < self.c:
|
2016-03-01 09:09:08 +00:00
|
|
|
if ptr + ptr.head == self.c:
|
2015-07-13 22:10:11 +00:00
|
|
|
yield self.doc[ptr - (self.c - self.i)]
|
2016-03-01 09:09:08 +00:00
|
|
|
ptr += 1
|
2016-01-16 15:18:17 +00:00
|
|
|
nr_iter += 1
|
|
|
|
# This is ugly, but it's a way to guard out infinite loops
|
|
|
|
if nr_iter >= 10000000:
|
|
|
|
raise RuntimeError(
|
|
|
|
"Possibly infinite loop encountered while looking for token.lefts")
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property rights:
|
|
|
|
def __get__(self):
|
|
|
|
"""The rightward immediate children of the word, in the syntactic
|
|
|
|
dependency parse."""
|
2015-09-06 08:48:36 +00:00
|
|
|
cdef const TokenC* ptr = self.c + (self.c.r_edge - self.i)
|
2015-07-13 17:20:48 +00:00
|
|
|
tokens = []
|
2016-01-16 15:18:17 +00:00
|
|
|
cdef int nr_iter = 0
|
2015-07-13 17:20:48 +00:00
|
|
|
while ptr > self.c:
|
2016-03-01 09:09:08 +00:00
|
|
|
if ptr + ptr.head == self.c:
|
2015-07-13 22:10:11 +00:00
|
|
|
tokens.append(self.doc[ptr - (self.c - self.i)])
|
2016-03-01 09:09:08 +00:00
|
|
|
ptr -= 1
|
|
|
|
nr_iter += 1
|
2016-01-16 15:18:17 +00:00
|
|
|
if nr_iter >= 10000000:
|
|
|
|
raise RuntimeError(
|
|
|
|
"Possibly infinite loop encountered while looking for token.rights")
|
2015-07-13 17:20:48 +00:00
|
|
|
tokens.reverse()
|
|
|
|
for t in tokens:
|
|
|
|
yield t
|
|
|
|
|
|
|
|
property children:
|
|
|
|
def __get__(self):
|
|
|
|
yield from self.lefts
|
|
|
|
yield from self.rights
|
|
|
|
|
|
|
|
property subtree:
|
|
|
|
def __get__(self):
|
|
|
|
for word in self.lefts:
|
|
|
|
yield from word.subtree
|
|
|
|
yield self
|
|
|
|
for word in self.rights:
|
|
|
|
yield from word.subtree
|
|
|
|
|
|
|
|
property left_edge:
|
|
|
|
def __get__(self):
|
2015-07-13 22:10:11 +00:00
|
|
|
return self.doc[self.c.l_edge]
|
2015-08-08 21:37:44 +00:00
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property right_edge:
|
|
|
|
def __get__(self):
|
2015-07-13 22:10:11 +00:00
|
|
|
return self.doc[self.c.r_edge]
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2016-03-11 16:31:06 +00:00
|
|
|
property ancestors:
|
|
|
|
def __get__(self):
|
|
|
|
cdef const TokenC* head_ptr = self.c
|
|
|
|
# guard against infinite loop, no token can have
|
|
|
|
# more ancestors than tokens in the tree
|
|
|
|
cdef int i = 0
|
|
|
|
while head_ptr.head != 0 and i < self.doc.length:
|
|
|
|
head_ptr += head_ptr.head
|
|
|
|
yield self.doc[head_ptr - (self.c - self.i)]
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
def is_ancestor_of(self, descendant):
|
|
|
|
return any( ancestor.i == self.i for ancestor in descendant.ancestors )
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property head:
|
|
|
|
def __get__(self):
|
|
|
|
"""The token predicted by the parser to be the head of the current token."""
|
2015-07-13 22:10:11 +00:00
|
|
|
return self.doc[self.i + self.c.head]
|
2016-03-11 16:31:06 +00:00
|
|
|
def __set__(self, Token new_head):
|
|
|
|
# this function sets the head of self to new_head
|
|
|
|
# and updates the counters for left/right dependents
|
|
|
|
# and left/right corner for the new and the old head
|
|
|
|
|
|
|
|
# do nothing if old head is new head
|
|
|
|
if self.i + self.c.head == new_head.i:
|
|
|
|
return
|
|
|
|
|
|
|
|
cdef Token old_head = self.head
|
|
|
|
cdef int rel_newhead_i = new_head.i - self.i
|
|
|
|
|
|
|
|
# is the new head a descendant of the old head
|
|
|
|
cdef bint is_desc = old_head.is_ancestor_of(new_head)
|
|
|
|
|
|
|
|
cdef int new_edge
|
2016-03-14 12:43:48 +00:00
|
|
|
cdef Token anc, child
|
2016-03-11 16:31:06 +00:00
|
|
|
|
|
|
|
# update number of deps of old head
|
|
|
|
if self.c.head > 0: # left dependent
|
|
|
|
old_head.c.l_kids -= 1
|
|
|
|
if self.c.l_edge == old_head.c.l_edge:
|
|
|
|
# the token dominates the left edge so the left edge of the head
|
|
|
|
# may change when the token is reattached
|
|
|
|
# it may not change if the new head is a descendant of the current head
|
|
|
|
|
|
|
|
new_edge = self.c.l_edge
|
2016-03-14 12:43:48 +00:00
|
|
|
# the new l_edge is the left-most l_edge on any of the other dependents
|
|
|
|
# where the l_edge is left of the head, otherwise it is the head
|
2016-03-11 16:31:06 +00:00
|
|
|
if not is_desc:
|
2016-03-14 12:43:48 +00:00
|
|
|
new_edge = old_head.i
|
|
|
|
for child in old_head.children:
|
|
|
|
if child == self:
|
|
|
|
continue
|
|
|
|
if child.c.l_edge < new_edge:
|
|
|
|
new_edge = child.c.l_edge
|
|
|
|
old_head.c.l_edge = new_edge
|
|
|
|
|
2016-03-11 16:31:06 +00:00
|
|
|
# walk up the tree from old_head and assign new l_edge to ancestors
|
|
|
|
# until an ancestor already has an l_edge that's further left
|
|
|
|
for anc in old_head.ancestors:
|
|
|
|
if anc.c.l_edge <= new_edge:
|
|
|
|
break
|
|
|
|
anc.c.l_edge = new_edge
|
|
|
|
|
|
|
|
elif self.c.head < 0: # right dependent
|
|
|
|
old_head.c.r_kids -= 1
|
|
|
|
# do the same thing as for l_edge
|
|
|
|
if self.c.r_edge == old_head.c.r_edge:
|
|
|
|
new_edge = self.c.r_edge
|
2016-03-14 12:43:48 +00:00
|
|
|
|
2016-03-11 16:31:06 +00:00
|
|
|
if not is_desc:
|
2016-03-14 12:43:48 +00:00
|
|
|
new_edge = old_head.i
|
|
|
|
for child in old_head.children:
|
|
|
|
if child == self:
|
|
|
|
continue
|
|
|
|
if child.c.r_edge > new_edge:
|
|
|
|
new_edge = child.c.r_edge
|
|
|
|
old_head.c.r_edge = new_edge
|
|
|
|
|
2016-03-11 16:31:06 +00:00
|
|
|
for anc in old_head.ancestors:
|
|
|
|
if anc.c.r_edge >= new_edge:
|
|
|
|
break
|
|
|
|
anc.c.r_edge = new_edge
|
|
|
|
|
|
|
|
# update number of deps of new head
|
|
|
|
if rel_newhead_i > 0: # left dependent
|
|
|
|
new_head.c.l_kids += 1
|
|
|
|
# walk up the tree from new head and set l_edge to self.l_edge
|
|
|
|
# until you hit a token with an l_edge further to the left
|
|
|
|
if self.c.l_edge < new_head.c.l_edge:
|
2016-03-14 12:43:48 +00:00
|
|
|
new_head.c.l_edge = self.c.l_edge
|
2016-03-11 16:31:06 +00:00
|
|
|
for anc in new_head.ancestors:
|
2016-03-14 12:43:48 +00:00
|
|
|
if anc.c.l_edge <= self.c.l_edge:
|
2016-03-11 16:31:06 +00:00
|
|
|
break
|
2016-03-14 12:43:48 +00:00
|
|
|
anc.c.l_edge = self.c.l_edge
|
2016-03-11 16:31:06 +00:00
|
|
|
|
|
|
|
elif rel_newhead_i < 0: # right dependent
|
|
|
|
new_head.c.r_kids += 1
|
|
|
|
# do the same as for l_edge
|
|
|
|
if self.c.r_edge > new_head.c.r_edge:
|
2016-03-14 12:43:48 +00:00
|
|
|
new_head.c.r_edge = self.c.r_edge
|
2016-03-11 16:31:06 +00:00
|
|
|
for anc in new_head.ancestors:
|
2016-03-14 12:43:48 +00:00
|
|
|
if anc.c.r_edge >= self.c.r_edge:
|
2016-03-11 16:31:06 +00:00
|
|
|
break
|
2016-03-14 12:43:48 +00:00
|
|
|
anc.c.r_edge = self.c.r_edge
|
2016-03-11 16:31:06 +00:00
|
|
|
|
|
|
|
# set new head
|
|
|
|
self.c.head = rel_newhead_i
|
2015-08-08 21:37:44 +00:00
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property conjuncts:
|
|
|
|
def __get__(self):
|
2015-10-14 16:34:57 +00:00
|
|
|
"""Get a list of conjoined words."""
|
2015-07-13 17:20:48 +00:00
|
|
|
cdef Token word
|
2015-10-14 16:49:45 +00:00
|
|
|
if self.dep_ != 'conj':
|
2015-10-14 16:34:57 +00:00
|
|
|
for word in self.rights:
|
2015-10-14 16:47:45 +00:00
|
|
|
if word.dep_ == 'conj':
|
|
|
|
yield word
|
|
|
|
yield from word.conjuncts
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property ent_type:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.ent_type
|
|
|
|
|
|
|
|
property ent_iob:
|
|
|
|
def __get__(self):
|
|
|
|
return self.c.ent_iob
|
|
|
|
|
|
|
|
property ent_type_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.ent_type, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property ent_iob_:
|
|
|
|
def __get__(self):
|
|
|
|
iob_strings = ('', 'I', 'O', 'B')
|
|
|
|
return iob_strings[self.c.ent_iob]
|
|
|
|
|
2016-09-21 12:54:55 +00:00
|
|
|
property ent_id:
|
|
|
|
'''An (integer) entity ID. Usually assigned by patterns in the Matcher.'''
|
|
|
|
def __get__(self):
|
2016-09-23 13:07:07 +00:00
|
|
|
return self.c.ent_id
|
2016-09-21 12:54:55 +00:00
|
|
|
|
|
|
|
def __set__(self, hash_t key):
|
|
|
|
# TODO
|
|
|
|
raise NotImplementedError(
|
|
|
|
"Can't yet set ent_id from Token. Vote for this feature on the issue "
|
|
|
|
"tracker: http://github.com/spacy-io/spaCy")
|
|
|
|
|
|
|
|
property ent_id_:
|
|
|
|
'''A (string) entity ID. Usually assigned by patterns in the Matcher.'''
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.ent_id, mem=self.mem)
|
2016-09-21 12:54:55 +00:00
|
|
|
|
|
|
|
def __set__(self, hash_t key):
|
|
|
|
# TODO
|
|
|
|
raise NotImplementedError(
|
|
|
|
"Can't yet set ent_id_ from Token. Vote for this feature on the issue "
|
|
|
|
"tracker: http://github.com/spacy-io/spaCy")
|
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property whitespace_:
|
|
|
|
def __get__(self):
|
2015-10-18 06:21:11 +00:00
|
|
|
return ' ' if self.c.spacy else ''
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property orth_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.orth, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property lower_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.lower, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property norm_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.norm, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property shape_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.shape, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property prefix_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.prefix, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property suffix_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.suffix, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
2016-03-10 12:01:34 +00:00
|
|
|
property lang_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lex.lang, mem=self.mem)
|
2016-03-10 12:01:34 +00:00
|
|
|
|
2015-07-13 17:20:48 +00:00
|
|
|
property lemma_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.lemma, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property pos_:
|
|
|
|
def __get__(self):
|
2015-10-10 06:55:55 +00:00
|
|
|
return parts_of_speech.NAMES[self.c.pos]
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property tag_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.strings.decode_int(self.c.tag, mem=self.mem)
|
2015-07-13 17:20:48 +00:00
|
|
|
|
|
|
|
property dep_:
|
|
|
|
def __get__(self):
|
2016-09-30 08:14:47 +00:00
|
|
|
return self.vocab.decode_int(self.c.dep, mem=self.mem)
|
2016-03-11 16:31:06 +00:00
|
|
|
def __set__(self, unicode label):
|
2016-09-30 08:14:47 +00:00
|
|
|
self.c.dep = self.vocab.strings.intern(label, mem=self.mem)
|
2015-07-13 18:20:58 +00:00
|
|
|
|
2015-07-26 23:50:06 +00:00
|
|
|
property is_oov:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_OOV)
|
2015-07-26 23:50:06 +00:00
|
|
|
|
2015-09-14 07:49:58 +00:00
|
|
|
property is_stop:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_STOP)
|
2015-09-14 07:49:58 +00:00
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
property is_alpha:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_ALPHA)
|
2015-08-08 21:37:44 +00:00
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
property is_ascii:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_ASCII)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_digit:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_DIGIT)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_lower:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_LOWER)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_title:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_TITLE)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_punct:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_PUNCT)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_space:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_SPACE)
|
2016-02-04 12:04:16 +00:00
|
|
|
|
|
|
|
property is_bracket:
|
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_BRACKET)
|
|
|
|
|
|
|
|
property is_quote:
|
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_QUOTE)
|
|
|
|
|
|
|
|
property is_left_punct:
|
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_LEFT_PUNCT)
|
|
|
|
|
|
|
|
property is_right_punct:
|
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, IS_RIGHT_PUNCT)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property like_url:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, LIKE_URL)
|
2015-08-08 21:37:44 +00:00
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
property like_num:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, LIKE_NUM)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property like_email:
|
2015-09-15 03:06:18 +00:00
|
|
|
def __get__(self): return Lexeme.c_check_flag(self.c.lex, LIKE_EMAIL)
|