2015-01-14 13:33:16 +00:00
|
|
|
# cython: embedsignature=True
|
2014-09-15 01:22:40 +00:00
|
|
|
from cpython.ref cimport Py_INCREF
|
2014-09-17 21:09:24 +00:00
|
|
|
from cymem.cymem cimport Pool
|
2014-10-29 12:19:38 +00:00
|
|
|
from murmurhash.mrmr cimport hash64
|
2014-09-15 01:22:40 +00:00
|
|
|
|
2014-10-22 14:57:59 +00:00
|
|
|
from libc.string cimport memset
|
|
|
|
|
2015-01-05 07:49:19 +00:00
|
|
|
from .orth cimport word_shape
|
2015-07-01 16:50:37 +00:00
|
|
|
from .typedefs cimport attr_t, flags_t
|
2015-01-17 05:21:17 +00:00
|
|
|
import numpy
|
2014-09-10 18:41:37 +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
|
|
|
|
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
|
|
|
|
2014-10-09 08:53:30 +00:00
|
|
|
|
2015-01-11 23:26:22 +00:00
|
|
|
memset(&EMPTY_LEXEME, 0, sizeof(LexemeC))
|
2014-10-09 08:53:30 +00:00
|
|
|
|
|
|
|
|
2015-01-12 00:23:44 +00:00
|
|
|
cdef class Lexeme:
|
2015-01-24 09:48:34 +00: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 20:04:34 +00:00
|
|
|
def __init__(self, Vocab vocab, int orth):
|
|
|
|
self.vocab = vocab
|
|
|
|
self.orth = orth
|
2015-09-06 17:45:15 +00:00
|
|
|
self.c = <LexemeC*><void*>vocab.get_by_orth(vocab.mem, orth)
|
2015-08-23 18:49:18 +00:00
|
|
|
assert self.c.orth == orth
|
2015-08-22 20:04:34 +00:00
|
|
|
|
2015-09-06 15:52:51 +00:00
|
|
|
def py_set_flag(self, attr_id_t flag_id):
|
|
|
|
Lexeme.set_flag(self.c, flag_id, True)
|
|
|
|
|
|
|
|
def py_check_flag(self, attr_id_t flag_id):
|
|
|
|
return True if Lexeme.check_flag(self.c, flag_id) else False
|
|
|
|
|
2015-08-26 17:16:28 +00:00
|
|
|
property orth_:
|
|
|
|
def __get__(self):
|
|
|
|
return self.vocab.strings[self.c.orth]
|
2015-08-22 20:04:34 +00: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
|
|
|
|
|
2015-08-26 17:16:28 +00:00
|
|
|
property cluster:
|
|
|
|
def __get__(self): return self.c.suffix
|
|
|
|
def __set__(self, int x): self.c.suffix = x
|
|
|
|
|
|
|
|
property prob:
|
|
|
|
def __get__(self): return self.c.suffix
|
|
|
|
def __set__(self, int x): self.c.suffix = x
|
2015-08-22 20:04:34 +00:00
|
|
|
|
|
|
|
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-02-07 13:42:44 +00:00
|
|
|
|
2015-08-22 20:04:34 +00:00
|
|
|
property prefix_:
|
|
|
|
def __get__(self): return self.c.prefix
|
|
|
|
def __set__(self, unicode x): self.c.prefix = self.vocab.strings[x]
|
2015-02-07 13:42:44 +00:00
|
|
|
|
2015-08-22 20:04:34 +00:00
|
|
|
property suffix_:
|
|
|
|
def __get__(self): return self.c.suffix
|
|
|
|
def __set__(self, unicode x): self.c.suffix = self.vocab.strings[x]
|
2015-07-26 14:37:16 +00:00
|
|
|
|
2015-08-26 17:16:28 +00:00
|
|
|
property flags:
|
|
|
|
def __get__(self): return self.c.flags
|
|
|
|
def __set__(self, flags_t x): self.c.flags = x
|
|
|
|
|
2015-07-26 23:50:06 +00:00
|
|
|
property is_oov:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_OOV)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_OOV, x)
|
2015-07-26 23:50:06 +00:00
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
property is_alpha:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_ALPHA)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_ALPHA, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_ascii:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_ASCII)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_ASCII, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_digit:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_DIGIT)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_DIGIT, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_lower:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_LOWER)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_LOWER, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_title:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_TITLE)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_TITLE, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_punct:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_PUNCT)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_PUNCT, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property is_space:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, IS_SPACE)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, IS_SPACE, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property like_url:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, LIKE_URL)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, LIKE_URL, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property like_num:
|
2015-09-06 17:45:15 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, LIKE_NUM)
|
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, LIKE_NUM, x)
|
2015-07-26 14:37:16 +00:00
|
|
|
|
|
|
|
property like_email:
|
2015-08-22 20:04:34 +00:00
|
|
|
def __get__(self): return Lexeme.check_flag(self.c, LIKE_EMAIL)
|
2015-09-06 17:45:15 +00:00
|
|
|
def __set__(self, bint x): Lexeme.set_flag(self.c, LIKE_EMAIL, x)
|