mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-10 19:57:17 +03:00
* Add function to predict number of bits needed to encode message
This commit is contained in:
parent
b89b489bb4
commit
5a042ee0d3
|
@ -1,6 +1,7 @@
|
|||
cimport cython
|
||||
from libcpp.queue cimport priority_queue
|
||||
from libcpp.pair cimport pair
|
||||
import numpy
|
||||
|
||||
from ..typedefs cimport attr_t
|
||||
|
||||
|
@ -59,6 +60,16 @@ cdef class HuffmanCodec:
|
|||
bits.extend(self.codes[i].bits, self.codes[i].length)
|
||||
return bits
|
||||
|
||||
def n_bits(self, msg, overhead=0):
|
||||
cdef int i
|
||||
length = 0
|
||||
for word in msg:
|
||||
if word not in self._map:
|
||||
return numpy.nan
|
||||
i = self._map[word]
|
||||
length += self.codes[i].length
|
||||
return length + overhead * len(msg)
|
||||
|
||||
def decode(self, bits, msg):
|
||||
node = self.root
|
||||
cdef int i = 0
|
||||
|
|
Loading…
Reference in New Issue
Block a user