spaCy/spacy/lexeme.pyx

557 lines
16 KiB
Cython
Raw Normal View History

# cython: embedsignature=True
# cython: profile=False
# Compiler crashes on memory view coercion without this. Should report bug.
cimport numpy as np
from libc.string cimport memset
np.import_array()
import warnings
import numpy
2020-02-18 14:38:18 +00:00
from thinc.api import get_array_module
from .attrs cimport (
IS_ALPHA,
IS_ASCII,
IS_BRACKET,
IS_CURRENCY,
IS_DIGIT,
IS_LEFT_PUNCT,
IS_LOWER,
IS_PUNCT,
IS_QUOTE,
IS_RIGHT_PUNCT,
IS_SPACE,
IS_STOP,
IS_TITLE,
IS_UPPER,
LIKE_EMAIL,
LIKE_NUM,
LIKE_URL,
)
from .typedefs cimport attr_t, flags_t
2017-10-30 10:49:11 +00:00
from .attrs import intify_attrs
2020-04-28 11:37:37 +00:00
from .errors import Errors, Warnings
OOV_RANK = 0xffffffffffffffff # UINT64_MAX
memset(&EMPTY_LEXEME, 0, sizeof(LexemeC))
EMPTY_LEXEME.id = OOV_RANK
cdef class Lexeme:
"""An entry in the vocabulary. A `Lexeme` has no string context it's a
2015-01-24 09:48:34 +00:00
word-type, as opposed to a word token. It therefore has no part-of-speech
2017-10-27 19:07:50 +00:00
tag, dependency parse, or lemma (lemmatization depends on the
part-of-speech tag).
DOCS: https://spacy.io/api/lexeme
2015-01-24 09:48:34 +00:00
"""
def __init__(self, Vocab vocab, attr_t orth):
"""Create a Lexeme object.
2016-11-01 11:25:36 +00:00
vocab (Vocab): The parent vocabulary
orth (uint64): The orth id of the lexeme.
2016-11-01 11:25:36 +00:00
Returns (Lexeme): The newly constructd object.
"""
2015-08-22 20:04:34 +00:00
self.vocab = vocab
self.orth = orth
self.c = <LexemeC*><void*>vocab.get_by_orth(vocab.mem, orth)
if self.c.orth != orth:
raise ValueError(Errors.E071.format(orth=orth, vocab_orth=self.c.orth))
2015-08-22 20:04:34 +00:00
def __richcmp__(self, other, int op):
if other is None:
if op == 0 or op == 1 or op == 2:
return False
else:
return True
if isinstance(other, Lexeme):
a = self.orth
b = other.orth
elif isinstance(other, long):
a = self.orth
b = other
elif isinstance(other, str):
a = self.orth_
b = other
else:
a = 0
b = 1
2017-10-27 19:07:50 +00:00
if op == 2: # ==
return a == b
2017-10-27 19:07:50 +00:00
elif op == 3: # !=
return a != b
2017-10-27 19:07:50 +00:00
elif op == 0: # <
return a < b
2017-10-27 19:07:50 +00:00
elif op == 1: # <=
return a <= b
2017-10-27 19:07:50 +00:00
elif op == 4: # >
return a > b
2017-10-27 19:07:50 +00:00
elif op == 5: # >=
return a >= b
else:
raise NotImplementedError(op)
def __hash__(self):
return self.c.orth
2017-10-30 10:49:11 +00:00
def set_attrs(self, **attrs):
cdef attr_id_t attr
attrs = intify_attrs(attrs)
for attr, value in attrs.items():
Reduce stored lexemes data, move feats to lookups (#5238) * Reduce stored lexemes data, move feats to lookups * Move non-derivable lexemes features (`norm / cluster / prob`) to `spacy-lookups-data` as lookups * Get/set `norm` in both lookups and `LexemeC`, serialize in lookups * Remove `cluster` and `prob` from `LexemesC`, get/set/serialize in lookups only * Remove serialization of lexemes data as `vocab/lexemes.bin` * Remove `SerializedLexemeC` * Remove `Lexeme.to_bytes/from_bytes` * Modify normalization exception loading: * Always create `Vocab.lookups` table `lexeme_norm` for normalization exceptions * Load base exceptions from `lang.norm_exceptions`, but load language-specific exceptions from lookups * Set `lex_attr_getter[NORM]` including new lookups table in `BaseDefaults.create_vocab()` and when deserializing `Vocab` * Remove all cached lexemes when deserializing vocab to override existing normalizations with the new normalizations (as a replacement for the previous step that replaced all lexemes data with the deserialized data) * Skip English normalization test Skip English normalization test because the data is now in `spacy-lookups-data`. * Remove norm exceptions Moved to spacy-lookups-data. * Move norm exceptions test to spacy-lookups-data * Load extra lookups from spacy-lookups-data lazily Load extra lookups (currently for cluster and prob) lazily from the entry point `lg_extra` as `Vocab.lookups_extra`. * Skip creating lexeme cache on load To improve model loading times, do not create the full lexeme cache when loading. The lexemes will be created on demand when processing. * Identify numeric values in Lexeme.set_attrs() With the removal of a special case for `PROB`, also identify `float` to avoid trying to convert it with the `StringStore`. * Skip lexeme cache init in from_bytes * Unskip and update lookups tests for python3.6+ * Update vocab pickle to include lookups_extra * Update vocab serialization tests Check strings rather than lexemes since lexemes aren't initialized automatically, account for addition of "_SP". * Re-skip lookups test because of python3.5 * Skip PROB/float values in Lexeme.set_attrs * Convert is_oov from lexeme flag to lex in vectors Instead of storing `is_oov` as a lexeme flag, `is_oov` reports whether the lexeme has a vector. Co-authored-by: Matthew Honnibal <honnibal+gh@gmail.com>
2020-05-19 13:59:14 +00:00
# skip PROB, e.g. from lexemes.jsonl
if isinstance(value, float):
continue
elif isinstance(value, (int, long)):
Lexeme.set_struct_attr(self.c, attr, value)
2017-10-30 10:49:11 +00:00
else:
Lexeme.set_struct_attr(self.c, attr, self.vocab.strings.add(value))
def set_flag(self, attr_id_t flag_id, bint value):
"""Change the value of a boolean flag.
2016-11-01 11:25:36 +00:00
flag_id (int): The attribute ID of the flag to set.
value (bool): The new value of the flag.
2016-11-01 11:25:36 +00:00
"""
Lexeme.c_set_flag(self.c, flag_id, value)
2017-04-01 08:19:01 +00:00
def check_flag(self, attr_id_t flag_id):
"""Check the value of a boolean flag.
2016-11-01 11:25:36 +00:00
flag_id (int): The attribute ID of the flag to query.
RETURNS (bool): The value of the flag.
2016-11-01 11:25:36 +00:00
"""
return True if Lexeme.c_check_flag(self.c, flag_id) else False
def similarity(self, other):
"""Compute a semantic similarity estimate. Defaults to cosine over
vectors.
other (object): The object to compare with. By default, accepts `Doc`,
`Span`, `Token` and `Lexeme` objects.
RETURNS (float): A scalar similarity score. Higher is more similar.
"""
# Return 1.0 similarity for matches
if hasattr(other, "orth"):
if self.c.orth == other.orth:
return 1.0
elif (
hasattr(other, "__len__") and len(other) == 1
and hasattr(other[0], "orth")
and self.c.orth == other[0].orth
):
return 1.0
2015-09-22 00:10:01 +00:00
if self.vector_norm == 0 or other.vector_norm == 0:
2020-04-28 11:37:37 +00:00
warnings.warn(Warnings.W008.format(obj="Lexeme"))
2015-09-22 00:10:01 +00:00
return 0.0
vector = self.vector
xp = get_array_module(vector)
result = xp.dot(vector, other.vector) / (self.vector_norm * other.vector_norm)
# ensure we get a scalar back (numpy does this automatically but cupy doesn't)
return result.item()
@property
def has_vector(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether a word vector is associated with the object.
"""
return self.vocab.has_vector(self.c.orth)
@property
def vector_norm(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (float): The L2 norm of the vector representation."""
vector = self.vector
return numpy.sqrt((vector**2).sum())
@property
def vector(self):
"""A real-valued meaning representation.
RETURNS (numpy.ndarray[ndim=1, dtype='float32']): A 1D numpy array
representing the lexeme's semantics.
"""
cdef int length = self.vocab.vectors_length
if length == 0:
raise ValueError(Errors.E010)
return self.vocab.get_vector(self.c.orth)
@vector.setter
def vector(self, vector):
if len(vector) != self.vocab.vectors_length:
raise ValueError(Errors.E073.format(new_length=len(vector),
length=self.vocab.vectors_length))
self.vocab.set_vector(self.c.orth, vector)
@property
def rank(self):
2021-06-15 08:57:08 +00:00
"""RETURNS (str): Sequential ID of the lexeme's lexical type, used
2017-10-27 19:07:50 +00:00
to index into tables, e.g. for word vectors."""
return self.c.id
2017-10-27 19:07:50 +00:00
@rank.setter
def rank(self, value):
self.c.id = value
@property
def sentiment(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (float): A scalar value indicating the positivity or
negativity of the lexeme."""
sentiment_table = self.vocab.lookups.get_table("lexeme_sentiment", {})
return sentiment_table.get(self.c.orth, 0.0)
2017-10-27 19:07:50 +00:00
@sentiment.setter
def sentiment(self, float x):
if "lexeme_sentiment" not in self.vocab.lookups:
self.vocab.lookups.add_table("lexeme_sentiment")
sentiment_table = self.vocab.lookups.get_table("lexeme_sentiment")
sentiment_table[self.c.orth] = x
2017-04-01 08:19:01 +00:00
@property
def orth_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): The original verbatim text of the lexeme
2017-10-27 19:07:50 +00:00
(identical to `Lexeme.text`). Exists mostly for consistency with
the other attributes."""
return self.vocab.strings[self.c.orth]
2015-08-22 20:04:34 +00:00
@property
def text(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): The original verbatim text of the lexeme."""
return self.orth_
@property
def lower(self):
2023-03-07 12:29:08 +00:00
"""RETURNS (uint64): Lowercase form of the lexeme."""
return self.c.lower
2017-10-27 19:07:50 +00:00
@lower.setter
def lower(self, attr_t x):
self.c.lower = x
2017-04-01 08:19:01 +00:00
@property
def norm(self):
2021-06-15 08:57:08 +00:00
"""RETURNS (uint64): The lexeme's norm, i.e. a normalised form of the
2017-10-27 19:07:50 +00:00
lexeme text.
"""
return self.c.norm
2017-10-27 19:07:50 +00:00
@norm.setter
def norm(self, attr_t x):
if "lexeme_norm" not in self.vocab.lookups:
self.vocab.lookups.add_table("lexeme_norm")
norm_table = self.vocab.lookups.get_table("lexeme_norm")
norm_table[self.c.orth] = self.vocab.strings[x]
self.c.norm = x
2015-08-22 20:04:34 +00:00
@property
def shape(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (uint64): Transform of the word's string, to show
orthographic features.
"""
return self.c.shape
2017-10-27 19:07:50 +00:00
@shape.setter
def shape(self, attr_t x):
self.c.shape = x
2015-08-22 20:04:34 +00:00
@property
def prefix(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (uint64): Length-N substring from the start of the word.
Defaults to `N=1`.
"""
return self.c.prefix
2017-10-27 19:07:50 +00:00
@prefix.setter
def prefix(self, attr_t x):
self.c.prefix = x
2015-08-22 20:04:34 +00:00
@property
def suffix(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (uint64): Length-N substring from the end of the word.
Defaults to `N=3`.
"""
return self.c.suffix
2017-10-27 19:07:50 +00:00
@suffix.setter
def suffix(self, attr_t x):
self.c.suffix = x
2017-04-01 08:19:01 +00:00
@property
def cluster(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (int): Brown cluster ID."""
cluster_table = self.vocab.lookups.get_table("lexeme_cluster", {})
return cluster_table.get(self.c.orth, 0)
2017-10-27 19:07:50 +00:00
@cluster.setter
def cluster(self, int x):
cluster_table = self.vocab.lookups.get_table("lexeme_cluster", {})
cluster_table[self.c.orth] = x
2017-04-01 08:19:01 +00:00
@property
def lang(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (uint64): Language of the parent vocabulary."""
return self.c.lang
2017-10-27 19:07:50 +00:00
@lang.setter
def lang(self, attr_t x):
self.c.lang = x
@property
def prob(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (float): Smoothed log probability estimate of the lexeme's
type."""
prob_table = self.vocab.lookups.get_table("lexeme_prob", {})
settings_table = self.vocab.lookups.get_table("lexeme_settings", {})
default_oov_prob = settings_table.get("oov_prob", -20.0)
return prob_table.get(self.c.orth, default_oov_prob)
2017-10-27 19:07:50 +00:00
@prob.setter
def prob(self, float x):
prob_table = self.vocab.lookups.get_table("lexeme_prob", {})
prob_table[self.c.orth] = x
2015-08-22 20:04:34 +00:00
@property
def lower_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): Lowercase form of the word."""
return self.vocab.strings[self.c.lower]
2017-10-27 19:07:50 +00:00
@lower_.setter
def lower_(self, str x):
self.c.lower = self.vocab.strings.add(x)
2017-04-01 08:19:01 +00:00
@property
def norm_(self):
2021-06-15 08:57:08 +00:00
"""RETURNS (str): The lexeme's norm, i.e. a normalised form of the
2017-10-27 19:07:50 +00:00
lexeme text.
"""
return self.vocab.strings[self.c.norm]
2017-10-27 19:07:50 +00:00
@norm_.setter
def norm_(self, str x):
self.norm = self.vocab.strings.add(x)
2017-04-01 08:19:01 +00:00
@property
def shape_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): Transform of the word's string, to show
2017-10-27 19:07:50 +00:00
orthographic features.
"""
return self.vocab.strings[self.c.shape]
2017-10-27 19:07:50 +00:00
@shape_.setter
def shape_(self, str x):
self.c.shape = self.vocab.strings.add(x)
@property
def prefix_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): Length-N substring from the start of the word.
2017-10-27 19:07:50 +00:00
Defaults to `N=1`.
"""
return self.vocab.strings[self.c.prefix]
2017-10-27 19:07:50 +00:00
@prefix_.setter
def prefix_(self, str x):
self.c.prefix = self.vocab.strings.add(x)
@property
def suffix_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): Length-N substring from the end of the word.
2017-10-27 19:07:50 +00:00
Defaults to `N=3`.
"""
return self.vocab.strings[self.c.suffix]
2017-10-27 19:07:50 +00:00
@suffix_.setter
def suffix_(self, str x):
self.c.suffix = self.vocab.strings.add(x)
@property
def lang_(self):
2020-05-24 15:20:58 +00:00
"""RETURNS (str): Language of the parent vocabulary."""
return self.vocab.strings[self.c.lang]
2017-10-27 19:07:50 +00:00
@lang_.setter
def lang_(self, str x):
self.c.lang = self.vocab.strings.add(x)
@property
def flags(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (uint64): Container of the lexeme's binary flags."""
return self.c.flags
2017-10-27 19:07:50 +00:00
@flags.setter
def flags(self, flags_t x):
self.c.flags = x
Reduce stored lexemes data, move feats to lookups (#5238) * Reduce stored lexemes data, move feats to lookups * Move non-derivable lexemes features (`norm / cluster / prob`) to `spacy-lookups-data` as lookups * Get/set `norm` in both lookups and `LexemeC`, serialize in lookups * Remove `cluster` and `prob` from `LexemesC`, get/set/serialize in lookups only * Remove serialization of lexemes data as `vocab/lexemes.bin` * Remove `SerializedLexemeC` * Remove `Lexeme.to_bytes/from_bytes` * Modify normalization exception loading: * Always create `Vocab.lookups` table `lexeme_norm` for normalization exceptions * Load base exceptions from `lang.norm_exceptions`, but load language-specific exceptions from lookups * Set `lex_attr_getter[NORM]` including new lookups table in `BaseDefaults.create_vocab()` and when deserializing `Vocab` * Remove all cached lexemes when deserializing vocab to override existing normalizations with the new normalizations (as a replacement for the previous step that replaced all lexemes data with the deserialized data) * Skip English normalization test Skip English normalization test because the data is now in `spacy-lookups-data`. * Remove norm exceptions Moved to spacy-lookups-data. * Move norm exceptions test to spacy-lookups-data * Load extra lookups from spacy-lookups-data lazily Load extra lookups (currently for cluster and prob) lazily from the entry point `lg_extra` as `Vocab.lookups_extra`. * Skip creating lexeme cache on load To improve model loading times, do not create the full lexeme cache when loading. The lexemes will be created on demand when processing. * Identify numeric values in Lexeme.set_attrs() With the removal of a special case for `PROB`, also identify `float` to avoid trying to convert it with the `StringStore`. * Skip lexeme cache init in from_bytes * Unskip and update lookups tests for python3.6+ * Update vocab pickle to include lookups_extra * Update vocab serialization tests Check strings rather than lexemes since lexemes aren't initialized automatically, account for addition of "_SP". * Re-skip lookups test because of python3.5 * Skip PROB/float values in Lexeme.set_attrs * Convert is_oov from lexeme flag to lex in vectors Instead of storing `is_oov` as a lexeme flag, `is_oov` reports whether the lexeme has a vector. Co-authored-by: Matthew Honnibal <honnibal+gh@gmail.com>
2020-05-19 13:59:14 +00:00
@property
def is_oov(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is out-of-vocabulary."""
return self.orth not in self.vocab.vectors
@property
def is_stop(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is a stop word."""
return Lexeme.c_check_flag(self.c, IS_STOP)
2017-10-27 19:07:50 +00:00
@is_stop.setter
def is_stop(self, bint x):
Lexeme.c_set_flag(self.c, IS_STOP, x)
2015-09-14 08:25:40 +00:00
@property
def is_alpha(self):
"""RETURNS (bool): Whether the lexeme consists of alphabetic
2017-10-27 19:07:50 +00:00
characters. Equivalent to `lexeme.text.isalpha()`.
"""
return Lexeme.c_check_flag(self.c, IS_ALPHA)
2017-10-27 19:07:50 +00:00
@is_alpha.setter
def is_alpha(self, bint x):
Lexeme.c_set_flag(self.c, IS_ALPHA, x)
2017-04-01 08:19:01 +00:00
@property
def is_ascii(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme consists of ASCII characters.
Equivalent to `[any(ord(c) >= 128 for c in lexeme.text)]`.
"""
return Lexeme.c_check_flag(self.c, IS_ASCII)
2017-10-27 19:07:50 +00:00
@is_ascii.setter
def is_ascii(self, bint x):
Lexeme.c_set_flag(self.c, IS_ASCII, x)
@property
def is_digit(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme consists of digits. Equivalent
to `lexeme.text.isdigit()`.
"""
return Lexeme.c_check_flag(self.c, IS_DIGIT)
2017-10-27 19:07:50 +00:00
@is_digit.setter
def is_digit(self, bint x):
Lexeme.c_set_flag(self.c, IS_DIGIT, x)
@property
def is_lower(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is in lowercase. Equivalent to
`lexeme.text.islower()`.
"""
return Lexeme.c_check_flag(self.c, IS_LOWER)
2017-10-27 19:07:50 +00:00
@is_lower.setter
def is_lower(self, bint x):
Lexeme.c_set_flag(self.c, IS_LOWER, x)
2017-10-27 19:07:50 +00:00
@property
def is_upper(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is in uppercase. Equivalent to
`lexeme.text.isupper()`.
"""
return Lexeme.c_check_flag(self.c, IS_UPPER)
2017-10-27 19:07:50 +00:00
@is_upper.setter
def is_upper(self, bint x):
Lexeme.c_set_flag(self.c, IS_UPPER, x)
@property
def is_title(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is in titlecase. Equivalent to
`lexeme.text.istitle()`.
"""
return Lexeme.c_check_flag(self.c, IS_TITLE)
2017-10-27 19:07:50 +00:00
@is_title.setter
def is_title(self, bint x):
Lexeme.c_set_flag(self.c, IS_TITLE, x)
@property
def is_punct(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is punctuation."""
return Lexeme.c_check_flag(self.c, IS_PUNCT)
2017-10-27 19:07:50 +00:00
@is_punct.setter
def is_punct(self, bint x):
Lexeme.c_set_flag(self.c, IS_PUNCT, x)
@property
def is_space(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme consist of whitespace characters.
Equivalent to `lexeme.text.isspace()`.
"""
return Lexeme.c_check_flag(self.c, IS_SPACE)
2017-10-27 19:07:50 +00:00
@is_space.setter
def is_space(self, bint x):
Lexeme.c_set_flag(self.c, IS_SPACE, x)
@property
def is_bracket(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is a bracket."""
return Lexeme.c_check_flag(self.c, IS_BRACKET)
2017-10-27 19:07:50 +00:00
@is_bracket.setter
def is_bracket(self, bint x):
Lexeme.c_set_flag(self.c, IS_BRACKET, x)
@property
def is_quote(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is a quotation mark."""
return Lexeme.c_check_flag(self.c, IS_QUOTE)
2017-10-27 19:07:50 +00:00
@is_quote.setter
def is_quote(self, bint x):
Lexeme.c_set_flag(self.c, IS_QUOTE, x)
@property
def is_left_punct(self):
"""RETURNS (bool): Whether the lexeme is left punctuation, e.g. (."""
return Lexeme.c_check_flag(self.c, IS_LEFT_PUNCT)
2017-10-27 19:07:50 +00:00
@is_left_punct.setter
def is_left_punct(self, bint x):
Lexeme.c_set_flag(self.c, IS_LEFT_PUNCT, x)
@property
def is_right_punct(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme is right punctuation, e.g. )."""
return Lexeme.c_check_flag(self.c, IS_RIGHT_PUNCT)
2017-10-27 19:07:50 +00:00
@is_right_punct.setter
def is_right_punct(self, bint x):
Lexeme.c_set_flag(self.c, IS_RIGHT_PUNCT, x)
@property
def is_currency(self):
2018-02-11 17:51:48 +00:00
"""RETURNS (bool): Whether the lexeme is a currency symbol, e.g. $, €."""
return Lexeme.c_check_flag(self.c, IS_CURRENCY)
2018-02-11 17:51:48 +00:00
@is_currency.setter
def is_currency(self, bint x):
Lexeme.c_set_flag(self.c, IS_CURRENCY, x)
2018-02-11 17:51:48 +00:00
@property
def like_url(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme resembles a URL."""
return Lexeme.c_check_flag(self.c, LIKE_URL)
2017-10-27 19:07:50 +00:00
@like_url.setter
def like_url(self, bint x):
Lexeme.c_set_flag(self.c, LIKE_URL, x)
2017-04-01 08:19:01 +00:00
@property
def like_num(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme represents a number, e.g. "10.9",
"10", "ten", etc.
"""
return Lexeme.c_check_flag(self.c, LIKE_NUM)
2017-10-27 19:07:50 +00:00
@like_num.setter
def like_num(self, bint x):
Lexeme.c_set_flag(self.c, LIKE_NUM, x)
@property
def like_email(self):
2017-10-27 19:07:50 +00:00
"""RETURNS (bool): Whether the lexeme resembles an email address."""
return Lexeme.c_check_flag(self.c, LIKE_EMAIL)
2017-10-27 19:07:50 +00:00
@like_email.setter
def like_email(self, bint x):
Lexeme.c_set_flag(self.c, LIKE_EMAIL, x)