summaryrefslogtreecommitdiff
path: root/python/src/sa/bilex.pxi
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
commit6f29f345dc06c1a1033475eac1d1340781d1d603 (patch)
tree6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /python/src/sa/bilex.pxi
parentb510da2e562c695c90d565eb295c749569c59be8 (diff)
parentc615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff)
merge upstream/master
Diffstat (limited to 'python/src/sa/bilex.pxi')
-rw-r--r--python/src/sa/bilex.pxi23
1 files changed, 9 insertions, 14 deletions
diff --git a/python/src/sa/bilex.pxi b/python/src/sa/bilex.pxi
index 27d1be49..44bc0ce6 100644
--- a/python/src/sa/bilex.pxi
+++ b/python/src/sa/bilex.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 struct _node:
_node* smaller
@@ -74,7 +74,6 @@ cdef class BiLex:
cdef int *fsent, *esent, *alignment, *links, *ealigned, *faligned
cdef _node** dict
cdef int *fmargin, *emargin, *count
- cdef bytes word
cdef int null_word
null_word = 0
@@ -215,32 +214,28 @@ cdef class BiLex:
cdef write_wordlist(self, wordlist, FILE* f):
cdef int word_len
cdef int num_words
- cdef char* c_word
num_words = len(wordlist)
fwrite(&(num_words), sizeof(int), 1, f)
for word in wordlist:
- 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)
cdef read_wordlist(self, word2id, id2word, FILE* f):
cdef int num_words
cdef int word_len
- cdef char* c_word
- cdef bytes py_word
+ cdef char* word
fread(&(num_words), sizeof(int), 1, f)
for i from 0 <= i < 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)
- word2id[py_word] = len(id2word)
- id2word.append(py_word)
+ word = <char*> malloc (word_len * sizeof(char))
+ fread(word, sizeof(char), word_len, f)
+ word2id[word] = len(id2word)
+ id2word.append(word)
+ free(word)
def read_binary(self, char* filename):
cdef FILE* f