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
|
|
|
|
|
2014-10-09 08:53:30 +00:00
|
|
|
import orth
|
2014-09-10 18:41:37 +00:00
|
|
|
|
2014-10-09 08:53:30 +00:00
|
|
|
|
2014-10-23 13:59:17 +00:00
|
|
|
memset(&EMPTY_LEXEME, 0, sizeof(Lexeme))
|
2014-10-09 08:53:30 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:43:00 +00:00
|
|
|
cpdef Lexeme init(id_t i, unicode string, hash_t hashed,
|
2014-12-03 00:04:00 +00:00
|
|
|
StringStore string_store, dict props) except *:
|
2014-10-29 12:19:38 +00:00
|
|
|
cdef Lexeme lex
|
2014-10-31 06:43:00 +00:00
|
|
|
lex.id = i
|
2014-10-29 12:19:38 +00:00
|
|
|
lex.length = len(string)
|
2014-12-03 00:04:00 +00:00
|
|
|
lex.sic = string_store[string]
|
2014-10-29 12:19:38 +00:00
|
|
|
|
|
|
|
lex.cluster = props.get('cluster', 0)
|
2014-12-03 00:04:00 +00:00
|
|
|
lex.pos_type = props.get('pos_type', 0)
|
|
|
|
lex.sense_type = props.get('sense_type', 0)
|
2014-10-29 12:19:38 +00:00
|
|
|
lex.prob = props.get('prob', 0)
|
|
|
|
|
2014-12-03 00:04:00 +00:00
|
|
|
lex.upper_pc = props.get('upper_pc', 0.0)
|
|
|
|
lex.title_pc = props.get('lower_pc', 0.0)
|
2014-10-29 12:19:38 +00:00
|
|
|
|
2014-12-03 00:04:00 +00:00
|
|
|
lex.prefix = string_store[string[:1]]
|
|
|
|
lex.suffix = string_store[string[-3:]]
|
|
|
|
lex.norm = lex.sic # TODO
|
|
|
|
lex.shape = string_store[orth.word_shape(string)]
|
|
|
|
lex.asciied = string_store[orth.asciied(string)]
|
|
|
|
|
|
|
|
lex.flags = props.get('flags', 0)
|
2014-10-29 12:19:38 +00:00
|
|
|
return lex
|
|
|
|
|
2014-10-31 06:43:00 +00:00
|
|
|
|
2014-12-03 04:44:25 +00:00
|
|
|
cdef attr_t get_attr(const Lexeme* lex, attr_id_t feat_name):
|
2014-12-03 00:04:00 +00:00
|
|
|
if feat_name < (sizeof(flags_t) * 8):
|
|
|
|
return check_flag(lex, feat_name)
|
|
|
|
elif feat_name == ID:
|
|
|
|
return lex.id
|
|
|
|
elif feat_name == SIC:
|
|
|
|
return lex.sic
|
|
|
|
elif feat_name == NORM:
|
|
|
|
return lex.norm
|
|
|
|
elif feat_name == SHAPE:
|
|
|
|
return lex.shape
|
|
|
|
elif feat_name == ASCIIED:
|
|
|
|
return lex.asciied
|
|
|
|
elif feat_name == PREFIX:
|
|
|
|
return lex.prefix
|
|
|
|
elif feat_name == SUFFIX:
|
|
|
|
return lex.suffix
|
|
|
|
elif feat_name == LENGTH:
|
|
|
|
return lex.length
|
|
|
|
elif feat_name == CLUSTER:
|
|
|
|
return lex.cluster
|
|
|
|
elif feat_name == POS_TYPE:
|
|
|
|
return lex.pos_type
|
|
|
|
elif feat_name == SENSE_TYPE:
|
|
|
|
return lex.sense_type
|
|
|
|
else:
|
|
|
|
raise StandardError('Feature ID: %d not found' % feat_name)
|