2014-08-03 00:51:52 +04:00
|
|
|
from libc.stdint cimport uint32_t
|
2014-07-07 06:21:06 +04:00
|
|
|
from libc.stdint cimport uint64_t
|
2014-10-14 08:47:06 +04:00
|
|
|
from libcpp.vector cimport vector
|
|
|
|
from libc.stdint cimport uint64_t, int64_t
|
2014-09-10 20:11:13 +04:00
|
|
|
|
2014-10-14 08:47:06 +04:00
|
|
|
from preshed.maps cimport PreshMap
|
2014-09-18 01:09:24 +04:00
|
|
|
from cymem.cymem cimport Pool
|
2014-09-17 22:02:26 +04:00
|
|
|
|
2014-10-14 08:47:06 +04:00
|
|
|
from .word cimport Lexeme
|
|
|
|
from .tokens cimport Tokens
|
|
|
|
from .lexeme cimport LexemeC
|
2014-09-10 20:11:13 +04:00
|
|
|
|
|
|
|
|
2014-09-12 20:00:42 +04:00
|
|
|
cdef extern from "Python.h":
|
|
|
|
cdef bint Py_UNICODE_ISSPACE(Py_UNICODE ch)
|
|
|
|
cdef bint Py_UNICODE_ISALNUM(Py_UNICODE ch)
|
2014-10-14 08:47:06 +04:00
|
|
|
cdef bint Py_UNICODE_ISALPHA(Py_UNICODE ch)
|
|
|
|
cdef bint Py_UNICODE_ISUPPER(Py_UNICODE ch)
|
2014-09-12 20:00:42 +04:00
|
|
|
|
|
|
|
|
2014-09-13 01:50:37 +04:00
|
|
|
cdef struct String:
|
|
|
|
Py_UNICODE* chars
|
|
|
|
size_t n
|
|
|
|
uint64_t key
|
|
|
|
|
|
|
|
|
2014-08-27 19:15:39 +04:00
|
|
|
cdef class Lexicon:
|
2014-10-14 08:47:06 +04:00
|
|
|
cdef Pool mem
|
2014-09-10 20:11:13 +04:00
|
|
|
cpdef readonly size_t size
|
|
|
|
|
2014-10-09 06:50:05 +04:00
|
|
|
cdef vector[LexemeC*] lexemes
|
|
|
|
|
2014-08-27 19:15:39 +04:00
|
|
|
cpdef Lexeme lookup(self, unicode string)
|
2014-09-16 20:01:46 +04:00
|
|
|
cdef LexemeC* get(self, String* s) except NULL
|
2014-08-29 03:59:23 +04:00
|
|
|
|
2014-09-26 20:40:03 +04:00
|
|
|
cdef PreshMap _dict
|
2014-08-29 03:59:23 +04:00
|
|
|
|
|
|
|
cdef list _string_features
|
|
|
|
cdef list _flag_features
|
2014-08-27 19:15:39 +04:00
|
|
|
|
2014-07-07 14:47:21 +04:00
|
|
|
cdef class Language:
|
2014-09-17 22:02:26 +04:00
|
|
|
cdef Pool _mem
|
2014-08-29 03:59:23 +04:00
|
|
|
cdef unicode name
|
2014-09-26 20:40:03 +04:00
|
|
|
cdef PreshMap cache
|
|
|
|
cdef PreshMap specials
|
2014-08-27 19:15:39 +04:00
|
|
|
cpdef readonly Lexicon lexicon
|
2014-07-07 06:21:06 +04:00
|
|
|
|
2014-09-25 20:22:52 +04:00
|
|
|
cdef object prefix_re
|
|
|
|
cdef object suffix_re
|
2014-10-14 08:47:06 +04:00
|
|
|
cdef object infix_re
|
2014-09-25 20:22:52 +04:00
|
|
|
|
2014-09-11 23:37:32 +04:00
|
|
|
cpdef Tokens tokenize(self, unicode text)
|
2014-09-16 15:16:02 +04:00
|
|
|
|
2014-10-14 11:22:41 +04:00
|
|
|
cdef int _tokenize(self, Tokens tokens, String* span, int start, int end) except -1
|
2014-10-14 08:47:06 +04:00
|
|
|
cdef String* _split_affixes(self, String* string, vector[LexemeC*] *prefixes,
|
|
|
|
vector[LexemeC*] *suffixes) except NULL
|
|
|
|
cdef int _attach_tokens(self, Tokens tokens, int idx, String* string,
|
|
|
|
vector[LexemeC*] *prefixes, vector[LexemeC*] *suffixes) except -1
|
|
|
|
cdef int _find_prefix(self, Py_UNICODE* characters, size_t length) except -1
|
|
|
|
cdef int _find_suffix(self, Py_UNICODE* characters, size_t length) except -1
|
|
|
|
cdef int _find_infix(self, Py_UNICODE* characters, size_t length) except -1
|
2014-09-16 15:16:02 +04:00
|
|
|
cdef int _save_cached(self, vector[LexemeC*] *tokens, uint64_t key, size_t n) except -1
|
|
|
|
|