NW: ColocationIds class implemented
This commit is contained in:
parent
5b75d6e4fa
commit
1298a45d0f
25
wani.py
25
wani.py
|
@ -782,6 +782,31 @@ def load_corpus(filename):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import time
|
import time
|
||||||
|
class ColocationIds:
|
||||||
|
def __init__(self):
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
|
def add_match(self, key):
|
||||||
|
if key in self.data:
|
||||||
|
self.data[key][1] += 1
|
||||||
|
else:
|
||||||
|
self.data[key] = [str(len(self.data) + 1), 1, False]
|
||||||
|
|
||||||
|
def get(self, key, n):
|
||||||
|
return self.data[key][n]
|
||||||
|
|
||||||
|
def is_written(self, key):
|
||||||
|
return self.get(key, 2)
|
||||||
|
|
||||||
|
def num(self, key):
|
||||||
|
return str(self.get(key, 1))
|
||||||
|
|
||||||
|
def to_id(self, key):
|
||||||
|
return self.get(key, 0)
|
||||||
|
|
||||||
|
def set_written(self, key):
|
||||||
|
self.data[key][2] = True
|
||||||
|
|
||||||
t = time.time()
|
t = time.time()
|
||||||
|
|
||||||
structures = build_structures(structures_file)
|
structures = build_structures(structures_file)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user