Grammalecte  Check-in [8ddc15536e]

Overview
Comment:[core][py] timer for testing
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: 8ddc15536ecf0bd80f1080a458df151cc0003dbdb5656ac8f2a5450dd69d6fd8
User & Date: olr on 2017-11-06 17:21:58
Other Links: manifest | tags
Context
2017-11-08
15:57
[fr] màj: écriture dystypographique check-in: 0bd6a29f03 user: olr tags: fr, trunk
2017-11-07
11:56
[core] ibdawg: another suggestion method check-in: 1edae62ad8 user: olr tags: core, spellsugg
2017-11-06
17:21
[core][py] timer for testing check-in: 8ddc15536e user: olr tags: core, trunk
14:21
[core][py] ibdawg: debugging check-in: cbe1422160 user: olr tags: core, trunk
Changes

Modified gc_core/py/ibdawg.py from [08bbb9ff98] to [a0b40e49a1].

     1      1   #!python3
     2      2   
     3      3   import os
     4      4   import traceback
     5      5   import pkgutil
     6      6   import re
     7      7   from itertools import chain
            8  +from functools import wraps
            9  +import time
     8     10   
     9     11   #import logging
    10     12   #logging.basicConfig(filename="suggestions.log", level=logging.DEBUG)
    11     13   
    12     14   from . import str_transform as st
    13     15   from . import char_player as cp
    14     16   from .echo import echo
    15     17   
           18  +
           19  +def timethis (func):
           20  +    "decorator for the execution time"
           21  +    @wraps(func)
           22  +    def wrapper (*args, **kwargs):
           23  +        fStart = time.time()
           24  +        result = func(*args, **kwargs)
           25  +        fEnd = time.time()
           26  +        print(func.__name__, fEnd - fStart)
           27  +        return result
           28  +    return wrapper
           29  +
    16     30   
    17     31   class IBDAWG:
    18     32       """INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH"""
    19     33   
    20     34       def __init__ (self, sDicName):
    21     35           self.by = pkgutil.get_data(__package__, "_dictionaries/" + sDicName)
    22     36           if not self.by:
................................................................................
   182    196           l = self.morph(sWord)
   183    197           if sWord[0:1].isupper():
   184    198               l.extend(self.morph(sWord.lower()))
   185    199               if sWord.isupper() and len(sWord) > 1:
   186    200                   l.extend(self.morph(sWord.capitalize()))
   187    201           return l
   188    202   
          203  +    @timethis
   189    204       def suggest (self, sWord, nMaxSugg=10):
   190    205           "returns a set of suggestions for <sWord>"
   191    206           sPfx, sWord, sSfx = cp.cut(sWord)
   192    207           nMaxDel = len(sWord) // 5
   193    208           nMaxHardRepl = max((len(sWord) - 5) // 4, 1)
   194    209           aSugg = self._suggest(sWord, nMaxDel=nMaxDel, nMaxHardRepl=nMaxHardRepl)
   195    210           if sWord.istitle():