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-17 05:21:17 +00:00
|
|
|
cdef int set_lex_struct_props(LexemeC* lex, dict props, StringStore string_store,
|
|
|
|
const float* empty_vec) except -1:
|
2015-01-13 13:03:48 +00:00
|
|
|
lex.length = props['length']
|
2015-01-22 15:08:25 +00:00
|
|
|
lex.orth = string_store[props['orth']]
|
2015-04-19 08:31:31 +00:00
|
|
|
lex.lower = string_store[props['lower']]
|
|
|
|
lex.norm = string_store[props['norm']]
|
|
|
|
lex.shape = string_store[props['shape']]
|
2015-01-13 13:03:48 +00:00
|
|
|
lex.prefix = string_store[props['prefix']]
|
|
|
|
lex.suffix = string_store[props['suffix']]
|
2015-04-19 08:31:31 +00:00
|
|
|
|
2015-01-13 13:03:48 +00:00
|
|
|
lex.cluster = props['cluster']
|
|
|
|
lex.prob = props['prob']
|
|
|
|
lex.sentiment = props['sentiment']
|
|
|
|
|
|
|
|
lex.flags = props['flags']
|
2015-01-21 15:03:54 +00:00
|
|
|
lex.repvec = empty_vec
|
2015-01-11 23:26:22 +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-01-17 05:21:17 +00:00
|
|
|
def __cinit__(self, int vec_size):
|
2015-01-22 15:08:25 +00:00
|
|
|
self.repvec = numpy.ndarray(shape=(vec_size,), dtype=numpy.float32)
|
2015-02-07 13:42:44 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_repvec(self):
|
|
|
|
return self.l2_norm != 0
|
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
cpdef bint check_flag(self, attr_id_t flag_id) except -1:
|
|
|
|
cdef flags_t one = 1
|
|
|
|
return self.flags & (one << flag_id)
|
|
|
|
|
2015-07-26 23:50:06 +00:00
|
|
|
property is_oov:
|
|
|
|
def __get__(self): return self.check_flag(IS_OOV)
|
|
|
|
|
2015-07-26 14:37:16 +00:00
|
|
|
property is_alpha:
|
|
|
|
def __get__(self): return self.check_flag(IS_ALPHA)
|
|
|
|
|
|
|
|
property is_ascii:
|
|
|
|
def __get__(self): return self.check_flag(IS_ASCII)
|
|
|
|
|
|
|
|
property is_digit:
|
|
|
|
def __get__(self): return self.check_flag(IS_DIGIT)
|
|
|
|
|
|
|
|
property is_lower:
|
|
|
|
def __get__(self): return self.check_flag(IS_LOWER)
|
|
|
|
|
|
|
|
property is_title:
|
|
|
|
def __get__(self): return self.check_flag(IS_TITLE)
|
|
|
|
|
|
|
|
property is_punct:
|
|
|
|
def __get__(self): return self.check_flag(IS_PUNCT)
|
|
|
|
|
|
|
|
property is_space:
|
|
|
|
def __get__(self): return self.check_flag(IS_SPACE)
|
|
|
|
|
|
|
|
property like_url:
|
|
|
|
def __get__(self): return self.check_flag(LIKE_URL)
|
|
|
|
|
|
|
|
property like_num:
|
|
|
|
def __get__(self): return self.check_flag(LIKE_NUM)
|
|
|
|
|
|
|
|
property like_email:
|
|
|
|
def __get__(self): return self.check_flag(LIKE_EMAIL)
|