spaCy/spacy/lexeme.pyx

119 lines
4.2 KiB
Cython
Raw Normal View History

# cython: embedsignature=True
from cpython.ref cimport Py_INCREF
from cymem.cymem cimport Pool
2014-10-29 15:19:38 +03:00
from murmurhash.mrmr cimport hash64
from libc.string cimport memset
2015-01-05 10:49:19 +03:00
from .orth cimport word_shape
from .typedefs cimport attr_t, flags_t
import numpy
2014-09-10 22:41:37 +04:00
from .attrs cimport IS_ALPHA, IS_ASCII, IS_DIGIT, IS_LOWER, IS_PUNCT, IS_SPACE
from .attrs cimport IS_TITLE, IS_UPPER, LIKE_URL, LIKE_NUM, LIKE_EMAIL, IS_STOP
from .attrs cimport IS_OOV
memset(&EMPTY_LEXEME, 0, sizeof(LexemeC))
cdef class Lexeme:
2015-01-24 12:48:34 +03:00
"""An entry in the vocabulary. A Lexeme has no string context --- it's a
word-type, as opposed to a word token. It therefore has no part-of-speech
tag, dependency parse, or lemma (lemmatization depends on the part-of-speech
tag).
"""
2015-08-22 23:04:34 +03:00
def __init__(self, Vocab vocab, int orth):
self.vocab = vocab
self.orth = orth
self.c = <LexemeC*><void*>vocab.get_by_orth(vocab.mem, orth)
assert self.c.orth == orth
2015-08-22 23:04:34 +03:00
property lower:
def __get__(self): return self.c.lower
def __set__(self, int x): self.c.lower = x
property norm:
def __get__(self): return self.c.norm
def __set__(self, int x): self.c.norm = x
property shape:
def __get__(self): return self.c.shape
def __set__(self, int x): self.c.shape = x
property prefix:
def __get__(self): return self.c.prefix
def __set__(self, int x): self.c.prefix = x
property suffix:
def __get__(self): return self.c.suffix
def __set__(self, int x): self.c.suffix = x
property orth_:
def __get__(self):
return self.vocab.strings[self.c.orth]
property lower_:
def __get__(self): return self.vocab.strings[self.c.lower]
def __set__(self, unicode x): self.c.lower = self.vocab.strings[x]
property norm_:
def __get__(self): return self.c.norm
def __set__(self, unicode x): self.c.norm = self.vocab.strings[x]
property shape_:
def __get__(self): return self.vocab.strings[self.c.shape]
def __set__(self, unicode x): self.c.shape = self.vocab.strings[x]
2015-08-22 23:04:34 +03:00
property prefix_:
def __get__(self): return self.c.prefix
def __set__(self, unicode x): self.c.prefix = self.vocab.strings[x]
2015-08-22 23:04:34 +03:00
property suffix_:
def __get__(self): return self.c.suffix
def __set__(self, unicode x): self.c.suffix = self.vocab.strings[x]
property is_oov:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_OOV)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_OOV, x)
property is_alpha:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_ALPHA)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_ALPHA, x)
property is_ascii:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_ASCII)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_ASCII, x)
property is_digit:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_DIGIT)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_DIGIT, x)
property is_lower:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_LOWER)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_LOWER, x)
property is_title:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_TITLE)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_TITLE, x)
property is_punct:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_PUNCT)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_PUNCT, x)
property is_space:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, IS_SPACE)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, IS_SPACE, x)
property like_url:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, LIKE_URL)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, LIKE_URL, x)
property like_num:
def __get__(self): return Lexeme.check_flag(self.c, LIKE_NUM)
2015-08-22 23:04:34 +03:00
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, LIKE_NUM, x)
property like_email:
2015-08-22 23:04:34 +03:00
def __get__(self): return Lexeme.check_flag(self.c, LIKE_EMAIL)
def __set__(self, attr_id_t x): Lexeme.set_flag(self.c, LIKE_EMAIL, x)