Tidy up property code style (#3391)

Use decorator if properties only have a getter and existing syntax if there's getter and setter
This commit is contained in:
Ines Montani 2019-03-11 15:59:09 +01:00 committed by Matthew Honnibal
parent c3df4d1108
commit 47e9c274ef
7 changed files with 490 additions and 491 deletions

View File

@ -161,15 +161,15 @@ cdef class Lexeme:
Lexeme.c_from_bytes(self.c, lex_data)
self.orth = self.c.orth
property has_vector:
@property
def has_vector(self):
"""RETURNS (bool): Whether a word vector is associated with the object.
"""
def __get__(self):
return self.vocab.has_vector(self.c.orth)
property vector_norm:
@property
def vector_norm(self):
"""RETURNS (float): The L2 norm of the vector representation."""
def __get__(self):
vector = self.vector
return numpy.sqrt((vector**2).sum())
@ -209,16 +209,16 @@ cdef class Lexeme:
def __set__(self, float sentiment):
self.c.sentiment = sentiment
property orth_:
@property
def orth_(self):
"""RETURNS (unicode): The original verbatim text of the lexeme
(identical to `Lexeme.text`). Exists mostly for consistency with
the other attributes."""
def __get__(self):
return self.vocab.strings[self.c.orth]
property text:
@property
def text(self):
"""RETURNS (unicode): The original verbatim text of the lexeme."""
def __get__(self):
return self.orth_
property lower:

View File

@ -369,8 +369,8 @@ cdef class ArcEager(TransitionSystem):
actions[LEFT].setdefault('dep', 0)
return actions
property action_types:
def __get__(self):
@property
def action_types(self):
return (SHIFT, REDUCE, LEFT, RIGHT, BREAK)
def get_cost(self, StateClass state, GoldParse gold, action):

View File

@ -80,8 +80,8 @@ cdef class BiluoPushDown(TransitionSystem):
actions[action][label] += 1
return actions
property action_types:
def __get__(self):
@property
def action_types(self):
return (BEGIN, IN, LAST, UNIT, OUT)
def move_name(self, int move, attr_t label):

View File

@ -384,7 +384,8 @@ cdef class Doc:
xp = get_array_module(vector)
return xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
property has_vector:
@property
def has_vector(self):
"""A boolean value indicating whether a word vector is associated with
the object.
@ -392,7 +393,6 @@ cdef class Doc:
DOCS: https://spacy.io/api/doc#has_vector
"""
def __get__(self):
if "has_vector" in self.user_hooks:
return self.user_hooks["has_vector"](self)
elif self.vocab.vectors.data.size:
@ -453,21 +453,21 @@ cdef class Doc:
def __set__(self, value):
self._vector_norm = value
property text:
@property
def text(self):
"""A unicode representation of the document text.
RETURNS (unicode): The original verbatim text of the document.
"""
def __get__(self):
return "".join(t.text_with_ws for t in self)
property text_with_ws:
@property
def text_with_ws(self):
"""An alias of `Doc.text`, provided for duck-type compatibility with
`Span` and `Token`.
RETURNS (unicode): The original verbatim text of the document.
"""
def __get__(self):
return self.text
property ents:
@ -545,7 +545,8 @@ cdef class Doc:
# Set start as B
self.c[start].ent_iob = 3
property noun_chunks:
@property
def noun_chunks(self):
"""Iterate over the base noun phrases in the document. Yields base
noun-phrase #[code Span] objects, if the document has been
syntactically parsed. A base noun phrase, or "NP chunk", is a noun
@ -557,7 +558,6 @@ cdef class Doc:
DOCS: https://spacy.io/api/doc#noun_chunks
"""
def __get__(self):
if not self.is_parsed:
raise ValueError(Errors.E029)
# Accumulate the result before beginning to iterate over it. This
@ -572,7 +572,8 @@ cdef class Doc:
for span in spans:
yield span
property sents:
@property
def sents(self):
"""Iterate over the sentences in the document. Yields sentence `Span`
objects. Sentence spans have no label. To improve accuracy on informal
texts, spaCy calculates sentence boundaries from the syntactic
@ -583,7 +584,6 @@ cdef class Doc:
DOCS: https://spacy.io/api/doc#sents
"""
def __get__(self):
if not self.is_sentenced:
raise ValueError(Errors.E030)
if "sents" in self.user_hooks:

View File

@ -322,14 +322,14 @@ cdef class Span:
self.start = start
self.end = end + 1
property vocab:
@property
def vocab(self):
"""RETURNS (Vocab): The Span's Doc's vocab."""
def __get__(self):
return self.doc.vocab
property sent:
@property
def sent(self):
"""RETURNS (Span): The sentence span that the span is a part of."""
def __get__(self):
if "sent" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["sent"](self)
# This should raise if not parsed / no custom sentence boundaries
@ -361,7 +361,8 @@ cdef class Span:
break
return self.doc[start:end]
property ents:
@property
def ents(self):
"""The named entities in the span. Returns a tuple of named entity
`Span` objects, if the entity recognizer has been applied.
@ -369,14 +370,14 @@ cdef class Span:
DOCS: https://spacy.io/api/span#ents
"""
def __get__(self):
ents = []
for ent in self.doc.ents:
if ent.start >= self.start and ent.end <= self.end:
ents.append(ent)
return ents
property has_vector:
@property
def has_vector(self):
"""A boolean value indicating whether a word vector is associated with
the object.
@ -384,7 +385,6 @@ cdef class Span:
DOCS: https://spacy.io/api/span#has_vector
"""
def __get__(self):
if "has_vector" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["has_vector"](self)
elif self.vocab.vectors.data.size > 0:
@ -394,7 +394,8 @@ cdef class Span:
else:
return False
property vector:
@property
def vector(self):
"""A real-valued meaning representation. Defaults to an average of the
token vectors.
@ -403,21 +404,20 @@ cdef class Span:
DOCS: https://spacy.io/api/span#vector
"""
def __get__(self):
if "vector" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["vector"](self)
if self._vector is None:
self._vector = sum(t.vector for t in self) / len(self)
return self._vector
property vector_norm:
@property
def vector_norm(self):
"""The L2 norm of the span's vector representation.
RETURNS (float): The L2 norm of the vector representation.
DOCS: https://spacy.io/api/span#vector_norm
"""
def __get__(self):
if "vector_norm" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["vector"](self)
cdef float value
@ -429,35 +429,36 @@ cdef class Span:
self._vector_norm = sqrt(norm) if norm != 0 else 0
return self._vector_norm
property sentiment:
@property
def sentiment(self):
"""RETURNS (float): A scalar value indicating the positivity or
negativity of the span.
"""
def __get__(self):
if "sentiment" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["sentiment"](self)
else:
return sum([token.sentiment for token in self]) / len(self)
property text:
@property
def text(self):
"""RETURNS (unicode): The original verbatim text of the span."""
def __get__(self):
text = self.text_with_ws
if self[-1].whitespace_:
text = text[:-1]
return text
property text_with_ws:
@property
def text_with_ws(self):
"""The text content of the span with a trailing whitespace character if
the last token has one.
RETURNS (unicode): The text content of the span (with trailing
whitespace).
"""
def __get__(self):
return "".join([t.text_with_ws for t in self])
property noun_chunks:
@property
def noun_chunks(self):
"""Yields base noun-phrase `Span` objects, if the document has been
syntactically parsed. A base noun phrase, or "NP chunk", is a noun
phrase that does not permit other NPs to be nested within it so no
@ -468,7 +469,6 @@ cdef class Span:
DOCS: https://spacy.io/api/span#noun_chunks
"""
def __get__(self):
if not self.doc.is_parsed:
raise ValueError(Errors.E029)
# Accumulate the result before beginning to iterate over it. This
@ -484,7 +484,8 @@ cdef class Span:
for span in spans:
yield span
property root:
@property
def root(self):
"""The token with the shortest path to the root of the
sentence (or the root itself). If multiple tokens are equally
high in the tree, the first token is taken.
@ -493,7 +494,6 @@ cdef class Span:
DOCS: https://spacy.io/api/span#root
"""
def __get__(self):
self._recalculate_indices()
if "root" in self.doc.user_span_hooks:
return self.doc.user_span_hooks["root"](self)
@ -527,7 +527,8 @@ cdef class Span:
else:
return self.doc[root]
property lefts:
@property
def lefts(self):
"""Tokens that are to the left of the span, whose head is within the
`Span`.
@ -535,13 +536,13 @@ cdef class Span:
DOCS: https://spacy.io/api/span#lefts
"""
def __get__(self):
for token in reversed(self): # Reverse, so we get tokens in order
for left in token.lefts:
if left.i < self.start:
yield left
property rights:
@property
def rights(self):
"""Tokens that are to the right of the Span, whose head is within the
`Span`.
@ -549,13 +550,13 @@ cdef class Span:
DOCS: https://spacy.io/api/span#rights
"""
def __get__(self):
for token in self:
for right in token.rights:
if right.i >= self.end:
yield right
property n_lefts:
@property
def n_lefts(self):
"""The number of tokens that are to the left of the span, whose
heads are within the span.
@ -564,10 +565,10 @@ cdef class Span:
DOCS: https://spacy.io/api/span#n_lefts
"""
def __get__(self):
return len(list(self.lefts))
property n_rights:
@property
def n_rights(self):
"""The number of tokens that are to the right of the span, whose
heads are within the span.
@ -576,17 +577,16 @@ cdef class Span:
DOCS: https://spacy.io/api/span#n_rights
"""
def __get__(self):
return len(list(self.rights))
property subtree:
@property
def subtree(self):
"""Tokens within the span and tokens which descend from them.
YIELDS (Token): A token within the span, or a descendant from it.
DOCS: https://spacy.io/api/span#subtree
"""
def __get__(self):
for word in self.lefts:
yield from word.subtree
yield from self
@ -609,32 +609,32 @@ cdef class Span:
def __set__(self, hash_t key):
raise NotImplementedError(TempErrors.T007.format(attr="ent_id_"))
property orth_:
@property
def orth_(self):
"""Verbatim text content (identical to `Span.text`). Exists mostly for
consistency with other attributes.
RETURNS (unicode): The span's text."""
def __get__(self):
return self.text
property lemma_:
@property
def lemma_(self):
"""RETURNS (unicode): The span's lemma."""
def __get__(self):
return " ".join([t.lemma_ for t in self]).strip()
property upper_:
@property
def upper_(self):
"""Deprecated. Use `Span.text.upper()` instead."""
def __get__(self):
return "".join([t.text_with_ws.upper() for t in self]).strip()
property lower_:
@property
def lower_(self):
"""Deprecated. Use `Span.text.lower()` instead."""
def __get__(self):
return "".join([t.text_with_ws.lower() for t in self]).strip()
property string:
@property
def string(self):
"""Deprecated: Use `Span.text_with_ws` instead."""
def __get__(self):
return "".join([t.text_with_ws for t in self])
property label_:

View File

@ -218,110 +218,110 @@ cdef class Token:
xp = get_array_module(vector)
return (xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm))
property lex_id:
@property
def lex_id(self):
"""RETURNS (int): Sequential ID of the token's lexical type."""
def __get__(self):
return self.c.lex.id
property rank:
@property
def rank(self):
"""RETURNS (int): Sequential ID of the token's lexical type, used to
index into tables, e.g. for word vectors."""
def __get__(self):
return self.c.lex.id
property string:
@property
def string(self):
"""Deprecated: Use Token.text_with_ws instead."""
def __get__(self):
return self.text_with_ws
property text:
@property
def text(self):
"""RETURNS (unicode): The original verbatim text of the token."""
def __get__(self):
return self.orth_
property text_with_ws:
@property
def text_with_ws(self):
"""RETURNS (unicode): The text content of the span (with trailing
whitespace).
"""
def __get__(self):
cdef unicode orth = self.vocab.strings[self.c.lex.orth]
if self.c.spacy:
return orth + " "
else:
return orth
property prob:
@property
def prob(self):
"""RETURNS (float): Smoothed log probability estimate of token type."""
def __get__(self):
return self.c.lex.prob
property sentiment:
@property
def sentiment(self):
"""RETURNS (float): A scalar value indicating the positivity or
negativity of the token."""
def __get__(self):
if "sentiment" in self.doc.user_token_hooks:
return self.doc.user_token_hooks["sentiment"](self)
return self.c.lex.sentiment
property lang:
@property
def lang(self):
"""RETURNS (uint64): ID of the language of the parent document's
vocabulary.
"""
def __get__(self):
return self.c.lex.lang
property idx:
@property
def idx(self):
"""RETURNS (int): The character offset of the token within the parent
document.
"""
def __get__(self):
return self.c.idx
property cluster:
@property
def cluster(self):
"""RETURNS (int): Brown cluster ID."""
def __get__(self):
return self.c.lex.cluster
property orth:
@property
def orth(self):
"""RETURNS (uint64): ID of the verbatim text content."""
def __get__(self):
return self.c.lex.orth
property lower:
@property
def lower(self):
"""RETURNS (uint64): ID of the lowercase token text."""
def __get__(self):
return self.c.lex.lower
property norm:
@property
def norm(self):
"""RETURNS (uint64): ID of the token's norm, i.e. a normalised form of
the token text. Usually set in the language's tokenizer exceptions
or norm exceptions.
"""
def __get__(self):
if self.c.norm == 0:
return self.c.lex.norm
else:
return self.c.norm
property shape:
@property
def shape(self):
"""RETURNS (uint64): ID of the token's shape, a transform of the
tokens's string, to show orthographic features (e.g. "Xxxx", "dd").
"""
def __get__(self):
return self.c.lex.shape
property prefix:
@property
def prefix(self):
"""RETURNS (uint64): ID of a length-N substring from the start of the
token. Defaults to `N=1`.
"""
def __get__(self):
return self.c.lex.prefix
property suffix:
@property
def suffix(self):
"""RETURNS (uint64): ID of a length-N substring from the end of the
token. Defaults to `N=3`.
"""
def __get__(self):
return self.c.lex.suffix
property lemma:
@ -362,7 +362,8 @@ cdef class Token:
def __set__(self, attr_t label):
self.c.dep = label
property has_vector:
@property
def has_vector(self):
"""A boolean value indicating whether a word vector is associated with
the object.
@ -370,14 +371,14 @@ cdef class Token:
DOCS: https://spacy.io/api/token#has_vector
"""
def __get__(self):
if 'has_vector' in self.doc.user_token_hooks:
if "has_vector" in self.doc.user_token_hooks:
return self.doc.user_token_hooks["has_vector"](self)
if self.vocab.vectors.size == 0 and self.doc.tensor.size != 0:
return True
return self.vocab.has_vector(self.c.lex.orth)
property vector:
@property
def vector(self):
"""A real-valued meaning representation.
RETURNS (numpy.ndarray[ndim=1, dtype='float32']): A 1D numpy array
@ -385,28 +386,28 @@ cdef class Token:
DOCS: https://spacy.io/api/token#vector
"""
def __get__(self):
if 'vector' in self.doc.user_token_hooks:
if "vector" in self.doc.user_token_hooks:
return self.doc.user_token_hooks["vector"](self)
if self.vocab.vectors.size == 0 and self.doc.tensor.size != 0:
return self.doc.tensor[self.i]
else:
return self.vocab.get_vector(self.c.lex.orth)
property vector_norm:
@property
def vector_norm(self):
"""The L2 norm of the token's vector representation.
RETURNS (float): The L2 norm of the vector representation.
DOCS: https://spacy.io/api/token#vector_norm
"""
def __get__(self):
if 'vector_norm' in self.doc.user_token_hooks:
if "vector_norm" in self.doc.user_token_hooks:
return self.doc.user_token_hooks["vector_norm"](self)
vector = self.vector
return numpy.sqrt((vector ** 2).sum())
property n_lefts:
@property
def n_lefts(self):
"""The number of leftward immediate children of the word, in the
syntactic dependency parse.
@ -415,10 +416,10 @@ cdef class Token:
DOCS: https://spacy.io/api/token#n_lefts
"""
def __get__(self):
return self.c.l_kids
property n_rights:
@property
def n_rights(self):
"""The number of rightward immediate children of the word, in the
syntactic dependency parse.
@ -427,12 +428,11 @@ cdef class Token:
DOCS: https://spacy.io/api/token#n_rights
"""
def __get__(self):
return self.c.r_kids
property sent:
@property
def sent(self):
"""RETURNS (Span): The sentence span that the token is a part of."""
def __get__(self):
if 'sent' in self.doc.user_token_hooks:
return self.doc.user_token_hooks["sent"](self)
return self.doc[self.i : self.i+1].sent
@ -479,7 +479,8 @@ cdef class Token:
else:
raise ValueError(Errors.E044.format(value=value))
property lefts:
@property
def lefts(self):
"""The leftward immediate children of the word, in the syntactic
dependency parse.
@ -487,7 +488,6 @@ cdef class Token:
DOCS: https://spacy.io/api/token#lefts
"""
def __get__(self):
cdef int nr_iter = 0
cdef const TokenC* ptr = self.c - (self.i - self.c.l_edge)
while ptr < self.c:
@ -499,7 +499,8 @@ cdef class Token:
if nr_iter >= 10000000:
raise RuntimeError(Errors.E045.format(attr="token.lefts"))
property rights:
@property
def rights(self):
"""The rightward immediate children of the word, in the syntactic
dependency parse.
@ -507,7 +508,6 @@ cdef class Token:
DOCS: https://spacy.io/api/token#rights
"""
def __get__(self):
cdef const TokenC* ptr = self.c + (self.c.r_edge - self.i)
tokens = []
cdef int nr_iter = 0
@ -522,18 +522,19 @@ cdef class Token:
for t in tokens:
yield t
property children:
@property
def children(self):
"""A sequence of the token's immediate syntactic children.
YIELDS (Token): A child token such that `child.head==self`.
DOCS: https://spacy.io/api/token#children
"""
def __get__(self):
yield from self.lefts
yield from self.rights
property subtree:
@property
def subtree(self):
"""A sequence containing the token and all the token's syntactic
descendants.
@ -542,30 +543,30 @@ cdef class Token:
DOCS: https://spacy.io/api/token#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:
@property
def left_edge(self):
"""The leftmost token of this token's syntactic descendents.
RETURNS (Token): The first token such that `self.is_ancestor(token)`.
"""
def __get__(self):
return self.doc[self.c.l_edge]
property right_edge:
@property
def right_edge(self):
"""The rightmost token of this token's syntactic descendents.
RETURNS (Token): The last token such that `self.is_ancestor(token)`.
"""
def __get__(self):
return self.doc[self.c.r_edge]
property ancestors:
@property
def ancestors(self):
"""A sequence of this token's syntactic ancestors.
YIELDS (Token): A sequence of ancestor tokens such that
@ -573,7 +574,6 @@ cdef class Token:
DOCS: https://spacy.io/api/token#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.
@ -685,14 +685,14 @@ cdef class Token:
# Set new head
self.c.head = rel_newhead_i
property conjuncts:
@property
def conjuncts(self):
"""A sequence of coordinated tokens, including the token itself.
YIELDS (Token): A coordinated token.
DOCS: https://spacy.io/api/token#conjuncts
"""
def __get__(self):
cdef Token word
if "conjuncts" in self.doc.user_token_hooks:
yield from self.doc.user_token_hooks["conjuncts"](self)
@ -711,15 +711,6 @@ cdef class Token:
def __set__(self, ent_type):
self.c.ent_type = ent_type
property ent_iob:
"""IOB code of named entity tag. `1="I", 2="O", 3="B"`. 0 means no tag
is assigned.
RETURNS (uint64): IOB code of named entity tag.
"""
def __get__(self):
return self.c.ent_iob
property ent_type_:
"""RETURNS (unicode): Named entity type."""
def __get__(self):
@ -728,14 +719,23 @@ cdef class Token:
def __set__(self, ent_type):
self.c.ent_type = self.vocab.strings.add(ent_type)
property ent_iob_:
@property
def ent_iob(self):
"""IOB code of named entity tag. `1="I", 2="O", 3="B"`. 0 means no tag
is assigned.
RETURNS (uint64): IOB code of named entity tag.
"""
return self.c.ent_iob
@property
def ent_iob_(self):
"""IOB code of named entity tag. "B" means the token begins an entity,
"I" means it is inside an entity, "O" means it is outside an entity,
and "" means no entity tag is set.
RETURNS (unicode): IOB code of named entity tag.
"""
def __get__(self):
iob_strings = ("", "I", "O", "B")
return iob_strings[self.c.ent_iob]
@ -759,25 +759,24 @@ cdef class Token:
def __set__(self, name):
self.c.ent_id = self.vocab.strings.add(name)
property whitespace_:
"""RETURNS (unicode): The trailing whitespace character, if present.
"""
def __get__(self):
@property
def whitespace_(self):
"""RETURNS (unicode): The trailing whitespace character, if present."""
return " " if self.c.spacy else ""
property orth_:
@property
def orth_(self):
"""RETURNS (unicode): Verbatim text content (identical to
`Token.text`). Exists mostly for consistency with the other
attributes.
"""
def __get__(self):
return self.vocab.strings[self.c.lex.orth]
property lower_:
@property
def lower_(self):
"""RETURNS (unicode): The lowercase token text. Equivalent to
`Token.text.lower()`.
"""
def __get__(self):
return self.vocab.strings[self.c.lex.lower]
property norm_:
@ -791,32 +790,32 @@ cdef class Token:
def __set__(self, unicode norm_):
self.c.norm = self.vocab.strings.add(norm_)
property shape_:
@property
def shape_(self):
"""RETURNS (unicode): Transform of the tokens's string, to show
orthographic features. For example, "Xxxx" or "dd".
"""
def __get__(self):
return self.vocab.strings[self.c.lex.shape]
property prefix_:
@property
def prefix_(self):
"""RETURNS (unicode): A length-N substring from the start of the token.
Defaults to `N=1`.
"""
def __get__(self):
return self.vocab.strings[self.c.lex.prefix]
property suffix_:
@property
def suffix_(self):
"""RETURNS (unicode): A length-N substring from the end of the token.
Defaults to `N=3`.
"""
def __get__(self):
return self.vocab.strings[self.c.lex.suffix]
property lang_:
@property
def lang_(self):
"""RETURNS (unicode): Language of the parent document's vocabulary,
e.g. 'en'.
"""
def __get__(self):
return self.vocab.strings[self.c.lex.lang]
property lemma_:
@ -856,110 +855,110 @@ cdef class Token:
def __set__(self, unicode label):
self.c.dep = self.vocab.strings.add(label)
property is_oov:
@property
def is_oov(self):
"""RETURNS (bool): Whether the token is out-of-vocabulary."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_OOV)
property is_stop:
@property
def is_stop(self):
"""RETURNS (bool): Whether the token is a stop word, i.e. part of a
"stop list" defined by the language data.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_STOP)
property is_alpha:
@property
def is_alpha(self):
"""RETURNS (bool): Whether the token consists of alpha characters.
Equivalent to `token.text.isalpha()`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_ALPHA)
property is_ascii:
@property
def is_ascii(self):
"""RETURNS (bool): Whether the token consists of ASCII characters.
Equivalent to `[any(ord(c) >= 128 for c in token.text)]`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_ASCII)
property is_digit:
@property
def is_digit(self):
"""RETURNS (bool): Whether the token consists of digits. Equivalent to
`token.text.isdigit()`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_DIGIT)
property is_lower:
@property
def is_lower(self):
"""RETURNS (bool): Whether the token is in lowercase. Equivalent to
`token.text.islower()`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_LOWER)
property is_upper:
@property
def is_upper(self):
"""RETURNS (bool): Whether the token is in uppercase. Equivalent to
`token.text.isupper()`
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_UPPER)
property is_title:
@property
def is_title(self):
"""RETURNS (bool): Whether the token is in titlecase. Equivalent to
`token.text.istitle()`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_TITLE)
property is_punct:
@property
def is_punct(self):
"""RETURNS (bool): Whether the token is punctuation."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_PUNCT)
property is_space:
@property
def is_space(self):
"""RETURNS (bool): Whether the token consists of whitespace characters.
Equivalent to `token.text.isspace()`.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_SPACE)
property is_bracket:
@property
def is_bracket(self):
"""RETURNS (bool): Whether the token is a bracket."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_BRACKET)
property is_quote:
@property
def is_quote(self):
"""RETURNS (bool): Whether the token is a quotation mark."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_QUOTE)
property is_left_punct:
@property
def is_left_punct(self):
"""RETURNS (bool): Whether the token is a left punctuation mark."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_LEFT_PUNCT)
property is_right_punct:
@property
def is_right_punct(self):
"""RETURNS (bool): Whether the token is a right punctuation mark."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_RIGHT_PUNCT)
property is_currency:
@property
def is_currency(self):
"""RETURNS (bool): Whether the token is a currency symbol."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, IS_CURRENCY)
property like_url:
@property
def like_url(self):
"""RETURNS (bool): Whether the token resembles a URL."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, LIKE_URL)
property like_num:
@property
def like_num(self):
"""RETURNS (bool): Whether the token resembles a number, e.g. "10.9",
"10", "ten", etc.
"""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, LIKE_NUM)
property like_email:
@property
def like_email(self):
"""RETURNS (bool): Whether the token resembles an email address."""
def __get__(self):
return Lexeme.c_check_flag(self.c.lex, LIKE_EMAIL)

View File

@ -60,8 +60,8 @@ cdef class Vocab:
self.morphology = Morphology(self.strings, tag_map, lemmatizer)
self.vectors = Vectors()
property lang:
def __get__(self):
@property
def lang(self):
langfunc = None
if self.lex_attr_getters:
langfunc = self.lex_attr_getters.get(LANG, None)