def put(self, word, location, feature): ''' 真を返す場合は単語を返します @param word: str: 対象の単語 @param location: int: 対象の単語の位置情報 @param feature: str: 対象の品詞情報 @return: bool ''' condition = self.get_condition(guess_decode(feature)) if condition == self.IGNORE: return len(self.words) > 0 return self._put(word, location, condition)
def parse(self, text): ''' 指定したテキストから単語とその位置情報を抽出します @param text: str or unicode @return: str, int ''' _text = encoder(text) # 文書の先頭からの位置 cur = 0 node = self.tagger.parseToNode(_text) while node: u_word = guess_decode(node.surface) # 半角スペースの数を算出 cur += node.rlength - node.length if self.fm.put(node.surface, cur, node.feature): yield self.fm.get() cur += len(u_word) node = node.next