summaryrefslogtreecommitdiff
path: root/python/src/sa/data_array.pxi
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-09-06 16:44:53 +0100
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-09-06 16:44:53 +0100
commitc1b77250f656c4cff9f0e532d6b6644cb0dc993c (patch)
tree93711d64a442124ca441e61d64b75b861c517120 /python/src/sa/data_array.pxi
parentfe9577d0ec51b7a5136d23885742780ca7f9ba8c (diff)
[cdec.sa] Fix API to make everyone happy
Diffstat (limited to 'python/src/sa/data_array.pxi')
-rw-r--r--python/src/sa/data_array.pxi17
1 files changed, 9 insertions, 8 deletions
diff --git a/python/src/sa/data_array.pxi b/python/src/sa/data_array.pxi
index 371708c5..2a8ea921 100644
--- a/python/src/sa/data_array.pxi
+++ b/python/src/sa/data_array.pxi
@@ -7,11 +7,11 @@ from libc.stdlib cimport malloc, realloc, free
from libc.string cimport memset, strcpy
cdef class DataArray:
- cdef word2id
- cdef id2word
+ cdef public word2id
+ cdef public id2word
cdef public IntList data
cdef public IntList sent_id
- cdef IntList sent_index
+ cdef public IntList sent_index
cdef bint use_sent_id
def __cinit__(self, from_binary=None, from_text=None, side=None, bint use_sent_id=False):
@@ -44,17 +44,18 @@ cdef class DataArray:
sent.append(self.id2word[self.data.arr[i]])
return sent
- def get_sentence_position(self, loc):
- return loc - self.sent_index.arr[self.sent_id.arr[loc]]
-
def get_id(self, word):
if not word in self.word2id:
self.word2id[word] = len(self.id2word)
self.id2word.append(word)
return self.word2id[word]
- def get_word(self, id):
- return self.id2word[id]
+ def __getitem__(self, loc):
+ return self.id2word[self.data.arr[loc]]
+
+ def get_sentence_bounds(self, loc):
+ cdef int sid = self.sent_id.arr[loc]
+ return (self.sent_index.arr[sid], self.sent_index.arr[sid+1])
def write_text(self, char* filename):
with open(filename, "w") as f: