summaryrefslogtreecommitdiff
path: root/python/src/sa/data_array.pxi
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/sa/data_array.pxi')
-rw-r--r--python/src/sa/data_array.pxi24
1 files changed, 11 insertions, 13 deletions
diff --git a/python/src/sa/data_array.pxi b/python/src/sa/data_array.pxi
index 7a102a7e..9f62dc0a 100644
--- a/python/src/sa/data_array.pxi
+++ b/python/src/sa/data_array.pxi
@@ -4,7 +4,7 @@
from libc.stdio cimport FILE, fopen, fread, fwrite, fclose
from libc.stdlib cimport malloc, realloc, free
-from libc.string cimport memset, strcpy, strlen
+from libc.string cimport memset, strcpy
cdef class DataArray:
cdef word2id
@@ -99,20 +99,19 @@ cdef class DataArray:
cdef void read_handle(self, FILE* f):
cdef int num_words, word_len
cdef unsigned i
- cdef char* c_word
- cdef bytes py_word
+ cdef char* word
+
self.data.read_handle(f)
self.sent_index.read_handle(f)
self.sent_id.read_handle(f)
fread(&(num_words), sizeof(int), 1, f)
for i in range(num_words):
fread(&(word_len), sizeof(int), 1, f)
- c_word = <char*> malloc (word_len * sizeof(char))
- fread(c_word, sizeof(char), word_len, f)
- py_word = c_word
- free(c_word)
- self.word2id[py_word] = len(self.id2word)
- self.id2word.append(py_word)
+ word = <char*> malloc (word_len * sizeof(char))
+ fread(word, sizeof(char), word_len, f)
+ self.word2id[word] = len(self.id2word)
+ self.id2word.append(word)
+ free(word)
if len(self.sent_id) == 0:
self.use_sent_id = False
else:
@@ -121,17 +120,16 @@ cdef class DataArray:
cdef void write_handle(self, FILE* f):
cdef int word_len
cdef int num_words
- cdef char* c_word
+
self.data.write_handle(f)
self.sent_index.write_handle(f)
self.sent_id.write_handle(f)
num_words = len(self.id2word) - 2
fwrite(&(num_words), sizeof(int), 1, f)
for word in self.id2word[2:]:
- c_word = word
- word_len = strlen(c_word) + 1
+ word_len = len(word) + 1
fwrite(&(word_len), sizeof(int), 1, f)
- fwrite(c_word, sizeof(char), word_len, f)
+ fwrite(<char *>word, sizeof(char), word_len, f)
def write_binary(self, char* filename):
cdef FILE* f