Grammalecte  Check-in [d99a910d73]

Overview
Comment:[core] ibdawg: draw path taken by word in dawg
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: d99a910d73b7e8555099926b4d0e55a619f3fe726f3c03478ec2ad180eebd4d0
User & Date: olr on 2017-06-28 19:40:53
Other Links: manifest | tags
Context
2017-06-29
04:16
[core] ibdawg: add next node when drawing path of a word check-in: 94f5da9f4a user: olr tags: core, trunk
2017-06-28
19:40
[core] ibdawg: draw path taken by word in dawg check-in: d99a910d73 user: olr tags: core, trunk
06:16
[fr] nr: confusion <la/l’a> check-in: f47e4bd4a5 user: olr tags: fr, trunk
Changes

Modified cli.py from [8ec24a7015] to [2ae9df701e].

   204    204                           echo("* " + sWord)
   205    205                           for sMorph in oDict.getMorph(sWord):
   206    206                               echo("  {:<32} {}".format(sMorph, oLexGraphe.formatTags(sMorph)))
   207    207               elif sText.startswith("!"):
   208    208                   for sWord in sText[1:].strip().split():
   209    209                       if sWord:
   210    210                           echo(" | ".join(oDict.suggest(sWord)))
          211  +            elif sText.startswith(">"):
          212  +                oDict.drawPath(sText[1:].strip())
   211    213               elif sText.startswith("/+ "):
   212    214                   gce.setOptions({ opt:True  for opt in sText[3:].strip().split()  if opt in gce.getOptions() })
   213    215                   echo("done")
   214    216               elif sText.startswith("/- "):
   215    217                   gce.setOptions({ opt:False  for opt in sText[3:].strip().split()  if opt in gce.getOptions() })
   216    218                   echo("done")
   217    219               elif sText.startswith("/-- "):

Modified gc_core/py/ibdawg.py from [303901f49a] to [b249dfb9bf].

    52     52           if self.cStemming == "S":
    53     53               self.funcStemming = st.changeWordWithSuffixCode
    54     54           elif self.cStemming == "A":
    55     55               self.funcStemming = st.changeWordWithAffixCode
    56     56           else:
    57     57               self.funcStemming = st.noStemming
    58     58           self.nTag = self.nArcVal - self.nChar - self.nAff
    59         -        # <dChar> to get the value of an arc, <dArcVal> to get the char of an arc with its value
           59  +        # <dChar> to get the value of an arc, <dCharVal> to get the char of an arc with its value
    60     60           self.dChar = {}
    61     61           for i in range(1, self.nChar):
    62     62               self.dChar[self.lArcVal[i]] = i
    63         -        self.dArcVal = { v: k  for k, v in self.dChar.items() }
           63  +        self.dCharVal = { v: k  for k, v in self.dChar.items() }
    64     64               
    65     65           self._arcMask = (2 ** ((self.nBytesArc * 8) - 3)) - 1
    66     66           self._finalNodeMask = 1 << ((self.nBytesArc * 8) - 1)
    67     67           self._lastArcMask = 1 << ((self.nBytesArc * 8) - 2)
    68     68           self._addrBitMask = 1 << ((self.nBytesArc * 8) - 3)  # version 2
    69     69   
    70     70           self.nBytesOffset = 1 # version 3
................................................................................
   170    170           for c in sWord:
   171    171               if c not in self.dChar:
   172    172                   return False
   173    173               iAddr = self._lookupArcNode(self.dChar[c], iAddr)
   174    174               if iAddr == None:
   175    175                   return False
   176    176           return bool(int.from_bytes(self.byDic[iAddr:iAddr+self.nBytesArc], byteorder='big') & self._finalNodeMask)
          177  +
          178  +    def getMorph (self, sWord):
          179  +        "retrieves morphologies list, different casing allowed"
          180  +        l = self.morph(sWord)
          181  +        if sWord[0:1].isupper():
          182  +            l.extend(self.morph(sWord.lower()))
          183  +            if sWord.isupper() and len(sWord) > 1:
          184  +                l.extend(self.morph(sWord.capitalize()))
          185  +        return l
   177    186   
   178    187       def suggest (self, sWord):
   179    188           "returns a set of similar words"
   180    189           # first, we check for similar words
   181    190           #return set(self._suggestWithCrushedUselessChars(cp.clearWord(sWord)))
   182    191           lSugg = self._suggest(sWord)
   183    192           if not lSugg:
................................................................................
   244    253               show(nDeep, cChar)
   245    254               lSugg.extend(self._suggestWithCrushedUselessChars(sWord[1:], nDeep+1, jAddr, sNewWord+cChar))
   246    255           return lSugg
   247    256   
   248    257       def _getSimilarArcsAndCrushedChars (self, cChar, iAddr):
   249    258           "generator: yield similar char of <cChar> and address of the following node"
   250    259           for nVal, jAddr in self._getArcs(iAddr):
   251         -            if self.dArcVal.get(nVal, "") in cp.aUselessChar:
   252         -                yield (self.dArcVal[nVal], jAddr)
          260  +            if self.dCharVal.get(nVal, None) in cp.aUselessChar:
          261  +                yield (self.dCharVal[nVal], jAddr)
   253    262           for c in cp.d1to1.get(cChar, [cChar]):
   254    263               if c in self.dChar:
   255    264                   jAddr = self._lookupArcNode(self.dChar[c], iAddr)
   256    265                   if jAddr:
   257    266                       yield (c, jAddr)
   258    267   
   259         -    def getMorph (self, sWord):
   260         -        "retrieves morphologies list, different casing allowed"
   261         -        l = self.morph(sWord)
   262         -        if sWord[0:1].isupper():
   263         -            l.extend(self.morph(sWord.lower()))
   264         -            if sWord.isupper() and len(sWord) > 1:
   265         -                l.extend(self.morph(sWord.capitalize()))
   266         -        return l
          268  +    def drawPath (self, sWord, iAddr=0):
          269  +        if not sWord:
          270  +            return
          271  +        iPos = -1
          272  +        n = 0
          273  +        print(sWord[0:1] + ": ", end="")
          274  +        for nVal, jAddr in self._getArcs(iAddr):
          275  +            if nVal in self.dCharVal:
          276  +                print(self.dCharVal[nVal], end="")
          277  +                if self.dCharVal[nVal] == sWord[0:1]:
          278  +                    iNextNodeAddr = jAddr
          279  +                    iPos = n
          280  +                n += 1
          281  +        if iPos >= 0:
          282  +            print("\n   "+ " " * iPos + "|")
          283  +            self.drawPath(sWord[1:], iNextNodeAddr)
          284  +
   267    285   
   268    286       # def morph (self, sWord):
   269    287       #     is defined in __init__
   270    288   
   271    289       # VERSION 1
   272    290       def _morph1 (self, sWord):
   273    291           "returns morphologies of sWord"