2015-01-14 16:33:16 +03:00
|
|
|
# cython: embedsignature=True
|
2014-09-15 05:22:40 +04:00
|
|
|
from cpython.ref cimport Py_INCREF
|
2014-09-18 01:09:24 +04:00
|
|
|
from cymem.cymem cimport Pool
|
2014-10-29 15:19:38 +03:00
|
|
|
from murmurhash.mrmr cimport hash64
|
2014-09-15 05:22:40 +04:00
|
|
|
|
2014-10-22 18:57:59 +04:00
|
|
|
from libc.string cimport memset
|
|
|
|
|
2015-01-05 10:49:19 +03:00
|
|
|
from .orth cimport word_shape
|
2015-07-01 19:50:37 +03:00
|
|
|
from .typedefs cimport attr_t, flags_t
|
2015-01-17 08:21:17 +03:00
|
|
|
import numpy
|
2014-09-10 22:41:37 +04:00
|
|
|
|
2014-10-09 12:53:30 +04:00
|
|
|
|
2015-01-12 02:26:22 +03:00
|
|
|
memset(&EMPTY_LEXEME, 0, sizeof(LexemeC))
|
2014-10-09 12:53:30 +04:00
|
|
|
|
|
|
|
|
2015-01-17 08:21:17 +03:00
|
|
|
cdef int set_lex_struct_props(LexemeC* lex, dict props, StringStore string_store,
|
|
|
|
const float* empty_vec) except -1:
|
2015-01-13 16:03:48 +03:00
|
|
|
lex.length = props['length']
|
2015-01-22 18:08:25 +03:00
|
|
|
lex.orth = string_store[props['orth']]
|
2015-04-19 11:31:31 +03:00
|
|
|
lex.lower = string_store[props['lower']]
|
|
|
|
lex.norm = string_store[props['norm']]
|
|
|
|
lex.shape = string_store[props['shape']]
|
2015-01-13 16:03:48 +03:00
|
|
|
lex.prefix = string_store[props['prefix']]
|
|
|
|
lex.suffix = string_store[props['suffix']]
|
2015-04-19 11:31:31 +03:00
|
|
|
|
2015-01-13 16:03:48 +03:00
|
|
|
lex.cluster = props['cluster']
|
|
|
|
lex.prob = props['prob']
|
|
|
|
lex.sentiment = props['sentiment']
|
|
|
|
|
|
|
|
lex.flags = props['flags']
|
2015-07-01 19:50:37 +03:00
|
|
|
cdef flags_t sense_id
|
2015-07-03 06:03:16 +03:00
|
|
|
lex.senses = 0
|
2015-07-01 19:50:37 +03:00
|
|
|
for sense_id in props.get('senses', []):
|
|
|
|
lex.senses |= 1 << sense_id
|
2015-01-21 18:03:54 +03:00
|
|
|
lex.repvec = empty_vec
|
2015-01-12 02:26:22 +03:00
|
|
|
|
|
|
|
|
2015-01-12 03:23:44 +03:00
|
|
|
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-01-17 08:21:17 +03:00
|
|
|
def __cinit__(self, int vec_size):
|
2015-01-22 18:08:25 +03:00
|
|
|
self.repvec = numpy.ndarray(shape=(vec_size,), dtype=numpy.float32)
|
2015-02-07 16:42:44 +03:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_repvec(self):
|
|
|
|
return self.l2_norm != 0
|
|
|
|
|
|
|
|
cpdef bint check(self, attr_id_t flag_id) except -1:
|
|
|
|
return self.flags & (1 << flag_id)
|
2015-07-01 19:50:37 +03:00
|
|
|
|
|
|
|
cpdef bint has_sense(self, flags_t flag_id) except -1:
|
|
|
|
return self.senses & (1 << flag_id)
|