Index: gc_core/py/ibdawg.py ================================================================== --- gc_core/py/ibdawg.py +++ gc_core/py/ibdawg.py @@ -2,10 +2,11 @@ # -*- coding: UTF-8 -*- import os import traceback import pkgutil +import re from itertools import chain from . import str_transform as st from . import char_player as cp from .echo import echo @@ -281,30 +282,34 @@ 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 select (self, sPattern=""): + "generator: returns all entries which morphology fits " + zPattern = None + try: + zPattern = re.compile(sPattern) + except: + print("# Error in regex pattern") + traceback.print_exc() + yield from self._select1(zPattern, 0, "") # def morph (self, sWord): # is defined in __init__ # VERSION 1 - def _select1 (self, sFilter, iAddr, sWord): + def _select1 (self, zPattern, 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]) + yield from self._select1(zPattern, 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]: + if not zPattern or zPattern.search(self.lArcVal[nMorphVal]): yield sEntry + "\t" + self.lArcVal[nMorphVal] def _morph1 (self, sWord): "returns morphologies of sWord" iAddr = 0