comments, some memoization, some other minor code changes
[nltk_ontology_framework.git] / src / mjacob / ontologybuilder / simple_subterms.py
blob67faffbe296d6e093a210b73d5dcb74b4a03d0c5
1 # This Python file uses the following encoding: utf-8
2 '''
3 Created on May 7, 2011
5 @author: mjacob
6 '''
8 class SimpleSubterms(object):
9 """
10 returns a collection of subterm strings from a collection of tokens
11 this version just assumes all possible substrings are possible, up to
12 an optionally specified "minimal length"
13 """
14 def __init__(self, minlength=1):
15 self.__minlength = minlength
17 def __call__(self, term):
18 for i in xrange(len(term)):
19 for j in xrange(i+self.__minlength, len(term)+1):
20 subterm = " ".join(term[i:j])
21 yield subterm.lower()