[Hejes-devel] [717] kulon vagy egybe: disallow parsing if ntoks>3 and not found in ohdict , show message; spell.py: don't dump exc.

hejes-devel at nytud.hu hejes-devel at nytud.hu
Wed May 8 17:44:01 CEST 2013


Revision: 717
Author:   mihaltz
Date:     2013-05-08 17:44:01 +0200 (Wed, 08 May 2013)
Log Message:
-----------
kulon vagy egybe: disallow parsing if ntoks>3 and not found in ohdict, show message; spell.py: don't dump exc. dict at startup

Modified Paths:
--------------
    trunk/web2py/applications/helyesiras_webdev/cache/cache.shelve
    trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2.py
    trunk/web2py/applications/helyesiras_webdev/modules/spell.py
    trunk/web2py/applications/helyesiras_webdev/views/default/kulegy.html

Modified: trunk/web2py/applications/helyesiras_webdev/cache/cache.shelve
===================================================================
(Binary files differ)

Modified: trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2.py	2013-05-08 14:43:26 UTC (rev 716)
+++ trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2.py	2013-05-08 15:44:01 UTC (rev 717)
@@ -173,6 +173,17 @@
     """
     if toklst == None:
       toklst = self.toklst
+    
+    # Do lookup in OHdict
+    found_oh = self.query_oh()
+
+    # If input is more than 3 tokens _and_ it's not found in ohdict then:
+    # Don't bother parsing. Return 0 with self.message set to a flag to indicate the message "please try to make into 3 or less tokens and try again"
+    # This is a hack to increase precision at the expense of recall because (for now) parsing is very buggy for n>=4 tokens.
+    if len(self.toklst.toks) > 3 and not found_oh:
+      self.message = '#TRY_AGAIN_WITH_LESS_TOKENS#'
+      return 0
+
     # convert TokenList to [[Node]]
     self.nlists = toklst.toNodeLists()
     # create & call parser
@@ -182,7 +193,7 @@
     parser = PhraseParser( self.nlists)
     self.parses, log = parser.parse()
 
-    # modifying rule-generated parses list based on lookup
+    # modifying rule-generated parses list based on dictionary lookup
     self.modify_parses()
 
     # 0 solutions:
@@ -236,11 +247,9 @@
     """
     if toklst == None:
       toklst = self.toklst
-    #norm_string = normalize_input( self.toklst )
     norm_strings = self.get_normalized_forms()
     self.oh_hits = []
     try:
-      # sql = 'SELECT actual FROM `ohdict` WHERE norm = {0};'.format(escape_string(norm_string))
       sql = 'SELECT actual FROM `ohdict` WHERE norm IN ({0});'.format(','.join([escape_string(x) for x in norm_strings]))
       result = self.dbconn.executesql(sql, as_dict=True) # e.g. [{actual='alma fa'}, {actual='almafa'}]
     except:
@@ -257,9 +266,10 @@
           but the rule-generated form is not present in the list;
         * adds a form if it is in the list but not generated by rules,
           uses special dummy rule (M_XXX) in this case.
+       NOTE: self.query_oh() must have been already called previously!
     """
-    # 'oh' list: lookup
-    exists_oh = self.query_oh()
+    # 'oh' list lookup: already done
+    # exists_oh = self.query_oh() # moved to getExplanations() for optimalization for new features (MM)
     oh_hits = self.oh_hits
 
     # if len(oh_hits) == 0 -> no modification is needed

Modified: trunk/web2py/applications/helyesiras_webdev/modules/spell.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/spell.py	2013-05-08 14:43:26 UTC (rev 716)
+++ trunk/web2py/applications/helyesiras_webdev/modules/spell.py	2013-05-08 15:44:01 UTC (rev 717)
@@ -57,8 +57,8 @@
 except Exception as e:
   sys.stderr.write('spell.py: exception while loading exceptions file:\n{0}\n'.format(str(e)))
   SPELL_EXC_DICT = {}
-print('Exception dictionary:')
-print(str(SPELL_EXC_DICT))
+#print('Exception dictionary:')
+#print(str(SPELL_EXC_DICT))
 
 
 @memcachememoize

Modified: trunk/web2py/applications/helyesiras_webdev/views/default/kulegy.html
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/views/default/kulegy.html	2013-05-08 14:43:26 UTC (rev 716)
+++ trunk/web2py/applications/helyesiras_webdev/views/default/kulegy.html	2013-05-08 15:44:01 UTC (rev 717)
@@ -95,9 +95,17 @@
 {{pass}}
 
 {{if status == 0:}}
-<div class="result result-noresult">
-  Az Ön által megadott "{{=result['usrinp']}}" bemenetre a rendelkezésre álló automatikus eszközök segítségével sajnos nem tudtunk tanáccsal szolgálni. Kérjük, keresse fel kérdésével {{=A('Közönségszolgálatunk', _href=URL(c='default', f='helpline'))}} munkatársait!
-</div>
+  <div class="result result-noresult">
+  {{if result.get('message') == '#TRY_AGAIN_WITH_LESS_TOKENS#':}}
+    Az Ön által megadott "{{=result['usrinp']}}" bemenetre a rendelkezésre álló automatikus eszközök segítségével sajnos nem tudtunk tanáccsal szolgálni. Kérjük,<br/>
+    <ul>
+      <li>vagy <b>próbálja újra 2 vagy 3 szóba írva</b>, szóközt csupán a kérdéses helyeken hagyva,</li>
+      <li>vagy keresse fel kérdésével {{=A('Közönségszolgálatunk', _href=URL(c='default', f='helpline'))}} munkatársait!</li>
+    </ul>
+  {{else:}}
+    Az Ön által megadott "{{=result['usrinp']}}" bemenetre a rendelkezésre álló automatikus eszközök segítségével sajnos nem tudtunk tanáccsal szolgálni. Kérjük, keresse fel kérdésével {{=A('Közönségszolgálatunk', _href=URL(c='default', f='helpline'))}} munkatársait!
+  {{pass}}
+  </div>
 {{pass}}
 
 {{if status > 0:}} 




More information about the Hejes-devel mailing list