summaryrefslogtreecommitdiff
path: root/python/src/sa/data_array.pxi
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-09-20 21:51:31 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-09-20 21:51:31 -0400
commitd2bc8694e5450a46c6f851d926c1ebfeb3424cbf (patch)
tree5619896999d43ca478acee0da2b1c60244aab5b1 /python/src/sa/data_array.pxi
parent78518f1f417616633b300a361cd5e0c1bcb1ff24 (diff)
parent5d159b948ad71850bcb03d0882ea7183a3a59b7e (diff)
Merge branch 'master' of https://github.com/redpony/cdec
Diffstat (limited to 'python/src/sa/data_array.pxi')
-rw-r--r--python/src/sa/data_array.pxi25
1 files changed, 13 insertions, 12 deletions
diff --git a/python/src/sa/data_array.pxi b/python/src/sa/data_array.pxi
index 9f62dc0a..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 IntList data
- cdef IntList sent_id
- cdef IntList sent_index
+ cdef public word2id
+ cdef public id2word
+ cdef public IntList data
+ cdef public IntList sent_id
+ 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):
@@ -32,10 +32,10 @@ cdef class DataArray:
def __len__(self):
return len(self.data)
- def getSentId(self, i):
+ def get_sentence_id(self, i):
return self.sent_id.arr[i]
- def getSent(self, i):
+ def get_sentence(self, i):
cdef int j, start, stop
sent = []
start = self.sent_index.arr[i]
@@ -44,17 +44,18 @@ cdef class DataArray:
sent.append(self.id2word[self.data.arr[i]])
return sent
- def getSentPos(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: