Index: cli.py ================================================================== --- cli.py +++ cli.py @@ -19,10 +19,12 @@ _HELP = """ /help /h show this text ?word1 [word2] ... words analysis !word suggestion + >word draw path of word in the word graph + =filter show all entries whose morphology fits to filter /lopt /lo list options /+ option1 [option2] ... activate grammar checking options /- option1 [option2] ... deactivate grammar checking options /lrules [pattern] /lr list rules /--rule1 [rule2] ... deactivate grammar checking rule @@ -208,10 +210,13 @@ for sWord in sText[1:].strip().split(): if sWord: echo(" | ".join(oDict.suggest(sWord))) elif sText.startswith(">"): oDict.drawPath(sText[1:].strip()) + elif sText.startswith("="): + for sRes in oDict.select(sText[1:].strip()): + echo(sRes) elif sText.startswith("/+ "): gce.setOptions({ opt:True for opt in sText[3:].strip().split() if opt in gce.getOptions() }) echo("done") elif sText.startswith("/- "): gce.setOptions({ opt:False for opt in sText[3:].strip().split() if opt in gce.getOptions() }) Index: gc_core/py/ibdawg.py ================================================================== --- gc_core/py/ibdawg.py +++ gc_core/py/ibdawg.py @@ -281,15 +281,32 @@ return if iPos >= 0: print("\n "+ " " * iPos + "|") self.drawPath(sWord[1:], iNextNodeAddr) + def select (self, sFilter=""): + "generator: returns all entries which morphology fits " + print("Filter: " + sFilter) + yield from self._select1(sFilter, 0, "") + # def morph (self, sWord): # is defined in __init__ # VERSION 1 + def _select1 (self, sFilter, iAddr, sWord): + # recursive generator + for nVal, jAddr in self._getArcs1(iAddr): + if nVal < self.nChar: + # simple character + yield from self._select1(sFilter, jAddr, sWord + self.lArcVal[nVal]) + else: + sEntry = sWord + "\t" + self.funcStemming(sWord, self.lArcVal[nVal]) + for nMorphVal, _ in self._getArcs1(jAddr): + if not sFilter or sFilter in self.lArcVal[nMorphVal]: + yield sEntry + "\t" + self.lArcVal[nMorphVal] + def _morph1 (self, sWord): "returns morphologies of sWord" iAddr = 0 for c in sWord: if c not in self.dChar: