mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	* Fix type declarations for attr_t. Remove unused id_t.
This commit is contained in:
		
							parent
							
								
									ced59ab9ea
								
							
						
					
					
						commit
						4dddc8a69b
					
				| 
						 | 
					@ -9,7 +9,7 @@ from thinc.api cimport ExampleC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from preshed.maps cimport PreshMapArray
 | 
					from preshed.maps cimport PreshMapArray
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .typedefs cimport hash_t, id_t
 | 
					from .typedefs cimport hash_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cdef int arg_max(const weight_t* scores, const int n_classes) nogil
 | 
					cdef int arg_max(const weight_t* scores, const int n_classes) nogil
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,13 +12,13 @@ from ..parts_of_speech cimport univ_pos_t
 | 
				
			||||||
from ..parts_of_speech cimport NO_TAG, ADJ, ADV, ADP, CONJ, DET, NOUN, NUM, PRON
 | 
					from ..parts_of_speech cimport NO_TAG, ADJ, ADV, ADP, CONJ, DET, NOUN, NUM, PRON
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ..parts_of_speech cimport PRT, VERB, X, PUNCT, EOL, SPACE
 | 
					from ..parts_of_speech cimport PRT, VERB, X, PUNCT, EOL, SPACE
 | 
				
			||||||
from ..typedefs cimport id_t
 | 
					 | 
				
			||||||
from ..structs cimport TokenC, Morphology, LexemeC
 | 
					from ..structs cimport TokenC, Morphology, LexemeC
 | 
				
			||||||
from ..tokens.doc cimport Doc
 | 
					from ..tokens.doc cimport Doc
 | 
				
			||||||
from ..morphology cimport set_morph_from_dict
 | 
					from ..morphology cimport set_morph_from_dict
 | 
				
			||||||
from .._ml cimport arg_max
 | 
					from .._ml cimport arg_max
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .attrs cimport IS_ALPHA, IS_PUNCT, LIKE_NUM, LIKE_URL
 | 
					from .attrs cimport IS_ALPHA, IS_PUNCT, LIKE_NUM, LIKE_URL
 | 
				
			||||||
 | 
					from ..typedefs cimport attr_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .lemmatizer import Lemmatizer
 | 
					from .lemmatizer import Lemmatizer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -342,7 +342,7 @@ cdef class EnPosTagger:
 | 
				
			||||||
        cdef dict entries
 | 
					        cdef dict entries
 | 
				
			||||||
        cdef dict props
 | 
					        cdef dict props
 | 
				
			||||||
        cdef int lemma
 | 
					        cdef int lemma
 | 
				
			||||||
        cdef id_t orth
 | 
					        cdef attr_t orth
 | 
				
			||||||
        cdef int pos
 | 
					        cdef int pos
 | 
				
			||||||
        for pos_str, entries in exc.items():
 | 
					        for pos_str, entries in exc.items():
 | 
				
			||||||
            pos = self.tag_names.index(pos_str)
 | 
					            pos = self.tag_names.index(pos_str)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
from .typedefs cimport attr_t, hash_t, flags_t, id_t, len_t, tag_t
 | 
					from .typedefs cimport attr_t, hash_t, flags_t, len_t, tag_t
 | 
				
			||||||
from .attrs cimport attr_id_t
 | 
					from .attrs cimport attr_id_t
 | 
				
			||||||
from .attrs cimport ID, ORTH, LOWER, NORM, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER
 | 
					from .attrs cimport ID, ORTH, LOWER, NORM, SHAPE, PREFIX, SUFFIX, LENGTH, CLUSTER
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,9 @@
 | 
				
			||||||
from cymem.cymem cimport Pool
 | 
					from cymem.cymem cimport Pool
 | 
				
			||||||
from preshed.maps cimport PreshMap
 | 
					from preshed.maps cimport PreshMap
 | 
				
			||||||
from murmurhash.mrmr cimport hash64
 | 
					from murmurhash.mrmr cimport hash64
 | 
				
			||||||
 | 
					from .typedefs cimport attr_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from libc.stdint cimport int64_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .structs cimport Utf8Str, UniStr
 | 
					from .structs cimport Utf8Str, UniStr
 | 
				
			||||||
from .typedefs cimport hash_t
 | 
					from .typedefs cimport hash_t
 | 
				
			||||||
| 
						 | 
					@ -17,9 +20,9 @@ cdef inline void slice_unicode(UniStr* s, Py_UNICODE* chars, int start, int end)
 | 
				
			||||||
cdef class StringStore:
 | 
					cdef class StringStore:
 | 
				
			||||||
    cdef Pool mem
 | 
					    cdef Pool mem
 | 
				
			||||||
    cdef Utf8Str* strings
 | 
					    cdef Utf8Str* strings
 | 
				
			||||||
    cdef size_t size
 | 
					    cdef int64_t size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cdef PreshMap _map
 | 
					    cdef PreshMap _map
 | 
				
			||||||
    cdef size_t _resize_at
 | 
					    cdef size_t _resize_at
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cdef const Utf8Str* intern(self, char* chars, int length, int* id_) except NULL
 | 
					    cdef const Utf8Str* intern(self, char* chars, int length, attr_t* id_) except NULL
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,8 +3,10 @@ import codecs
 | 
				
			||||||
from libc.string cimport memcpy
 | 
					from libc.string cimport memcpy
 | 
				
			||||||
from murmurhash.mrmr cimport hash64
 | 
					from murmurhash.mrmr cimport hash64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from libc.stdint cimport int64_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .typedefs cimport hash_t
 | 
					
 | 
				
			||||||
 | 
					from .typedefs cimport hash_t, attr_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SEPARATOR = '\n|-SEP-|\n'
 | 
					SEPARATOR = '\n|-SEP-|\n'
 | 
				
			||||||
| 
						 | 
					@ -34,7 +36,7 @@ cdef class StringStore:
 | 
				
			||||||
    def __getitem__(self, object string_or_id):
 | 
					    def __getitem__(self, object string_or_id):
 | 
				
			||||||
        cdef bytes byte_string
 | 
					        cdef bytes byte_string
 | 
				
			||||||
        cdef const Utf8Str* utf8str
 | 
					        cdef const Utf8Str* utf8str
 | 
				
			||||||
        cdef int id_
 | 
					        cdef attr_t id_
 | 
				
			||||||
        if isinstance(string_or_id, int) or isinstance(string_or_id, long):
 | 
					        if isinstance(string_or_id, int) or isinstance(string_or_id, long):
 | 
				
			||||||
            if string_or_id == 0:
 | 
					            if string_or_id == 0:
 | 
				
			||||||
                return u''
 | 
					                return u''
 | 
				
			||||||
| 
						 | 
					@ -52,26 +54,26 @@ cdef class StringStore:
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            raise TypeError(type(string_or_id))
 | 
					            raise TypeError(type(string_or_id))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cdef const Utf8Str* intern(self, char* chars, int length, int* id_) except NULL:
 | 
					    cdef const Utf8Str* intern(self, char* chars, int length, attr_t* id_) except NULL:
 | 
				
			||||||
        # 0 means missing, but we don't bother offsetting the index. We waste
 | 
					        # 0 means missing, but we don't bother offsetting the index. We waste
 | 
				
			||||||
        # slot 0 to simplify the code, because it doesn't matter.
 | 
					        # slot 0 to simplify the code, because it doesn't matter.
 | 
				
			||||||
        assert length != 0
 | 
					        assert length != 0
 | 
				
			||||||
        cdef hash_t key = hash64(chars, length * sizeof(char), 0)
 | 
					        cdef hash_t key = hash64(chars, length * sizeof(char), 0)
 | 
				
			||||||
        cdef void* value = self._map.get(key)
 | 
					        cdef void* value = self._map.get(key)
 | 
				
			||||||
        cdef size_t i
 | 
					        cdef int64_t i
 | 
				
			||||||
        if value == NULL:
 | 
					        if value == NULL:
 | 
				
			||||||
            if self.size == self._resize_at:
 | 
					            if self.size == self._resize_at:
 | 
				
			||||||
                self._resize_at *= 2
 | 
					                self._resize_at *= 2
 | 
				
			||||||
                self.strings = <Utf8Str*>self.mem.realloc(
 | 
					                self.strings = <Utf8Str*>self.mem.realloc(
 | 
				
			||||||
                    self.strings, self._resize_at * sizeof(Utf8Str))
 | 
					                    self.strings, self._resize_at * sizeof(Utf8Str))
 | 
				
			||||||
            i = self.size
 | 
					            i = <int64_t>self.size
 | 
				
			||||||
            self.strings[i].chars = <unsigned char*>self.mem.alloc(length, sizeof(char))
 | 
					            self.strings[i].chars = <unsigned char*>self.mem.alloc(length, sizeof(char))
 | 
				
			||||||
            memcpy(self.strings[i].chars, chars, length)
 | 
					            memcpy(self.strings[i].chars, chars, length)
 | 
				
			||||||
            self.strings[i].length = length
 | 
					            self.strings[i].length = length
 | 
				
			||||||
            self._map.set(key, <void*>self.size)
 | 
					            self._map.set(key, <void*>self.size)
 | 
				
			||||||
            self.size += 1
 | 
					            self.size += 1
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            i = <size_t>value
 | 
					            i = <int64_t>value
 | 
				
			||||||
        id_[0] = i
 | 
					        id_[0] = i
 | 
				
			||||||
        return &self.strings[i]
 | 
					        return &self.strings[i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,7 +94,7 @@ cdef class StringStore:
 | 
				
			||||||
            strings = file_.read().split(SEPARATOR)
 | 
					            strings = file_.read().split(SEPARATOR)
 | 
				
			||||||
        cdef unicode string
 | 
					        cdef unicode string
 | 
				
			||||||
        cdef bytes byte_string
 | 
					        cdef bytes byte_string
 | 
				
			||||||
        cdef int id_
 | 
					        cdef attr_t id_
 | 
				
			||||||
        for string in strings[1:]:
 | 
					        for string in strings[1:]:
 | 
				
			||||||
            byte_string = string.encode('utf8')
 | 
					            byte_string = string.encode('utf8')
 | 
				
			||||||
            self.intern(byte_string, len(byte_string), &id_)
 | 
					            self.intern(byte_string, len(byte_string), &id_)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
from libc.stdint cimport uint8_t, uint32_t, int32_t
 | 
					from libc.stdint cimport uint8_t, uint32_t, int32_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .typedefs cimport flags_t, attr_t, id_t, hash_t
 | 
					from .typedefs cimport flags_t, attr_t, hash_t
 | 
				
			||||||
from .parts_of_speech cimport univ_pos_t
 | 
					from .parts_of_speech cimport univ_pos_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,5 @@ ctypedef uint64_t hash_t
 | 
				
			||||||
ctypedef char* utf8_t
 | 
					ctypedef char* utf8_t
 | 
				
			||||||
ctypedef int32_t attr_t
 | 
					ctypedef int32_t attr_t
 | 
				
			||||||
ctypedef uint64_t flags_t
 | 
					ctypedef uint64_t flags_t
 | 
				
			||||||
ctypedef uint32_t id_t
 | 
					 | 
				
			||||||
ctypedef uint16_t len_t
 | 
					ctypedef uint16_t len_t
 | 
				
			||||||
ctypedef uint16_t tag_t
 | 
					ctypedef uint16_t tag_t
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ from cymem.cymem cimport Pool
 | 
				
			||||||
from murmurhash.mrmr cimport hash64
 | 
					from murmurhash.mrmr cimport hash64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .structs cimport LexemeC, TokenC, UniStr
 | 
					from .structs cimport LexemeC, TokenC, UniStr
 | 
				
			||||||
from .typedefs cimport utf8_t, id_t, hash_t
 | 
					from .typedefs cimport utf8_t, hash_t
 | 
				
			||||||
from .strings cimport StringStore
 | 
					from .strings cimport StringStore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +0,0 @@
 | 
				
			||||||
import pytest
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def test_range_iter(en_vocab):
 | 
					 | 
				
			||||||
    for i in range(len(en_vocab)):
 | 
					 | 
				
			||||||
        lex = en_vocab[i]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def test_iter(en_vocab):
 | 
					 | 
				
			||||||
    i = 0
 | 
					 | 
				
			||||||
    for lex in en_vocab:
 | 
					 | 
				
			||||||
        i += 1
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user