[Hejes-devel] [1413] spell.py: query paronyms with the stem, slangs with the surface form
hejes-devel at nytud.hu
hejes-devel at nytud.hu
Thu Jul 9 17:31:18 CEST 2015
Revision: 1413
Author: mihaltz
Date: 2015-07-09 17:31:17 +0200 (Thu, 09 Jul 2015)
Log Message:
-----------
spell.py: query paronyms with the stem, slangs with the surface form
Modified Paths:
--------------
trunk/web2py/applications/helyesiras_webdev/modules/spell.py
Modified: trunk/web2py/applications/helyesiras_webdev/modules/spell.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/spell.py 2015-07-09 14:01:00 UTC (rev 1412)
+++ trunk/web2py/applications/helyesiras_webdev/modules/spell.py 2015-07-09 15:31:17 UTC (rev 1413)
@@ -315,12 +315,12 @@
for ana in hanas:
if ana.stem != '':
stems.add(ana.stem)
+ # 1. query paronyms with the stem(s)
for stem in stems:
- # query stem in DB
sql = """SELECT * FROM sugg_types t
- LEFT JOIN sugg_types_paronyms p ON t.id=p.id
- LEFT JOIN sugg_types_slang s ON t.id=s.id
- WHERE t.actual={0};""".format(escape_string(stem))
+ JOIN sugg_types_paronyms p ON t.id=p.id
+ WHERE t.actual={0}
+ """.format(escape_string(stem))
try:
res = db.executesql(sql, as_dict=True)
except: # any exception: return as unknown
@@ -331,6 +331,20 @@
if v != None:
ret[safe_unic(k)] = safe_unic(v)
break # TODO: what if >1 stem matches
+ # 2. query slangs with the surface form only
+ sql = """SELECT * FROM sugg_types t
+ JOIN sugg_types_slang s ON t.id=s.id
+ WHERE t.actual={0}
+ """.format(escape_string(tok))
+ try:
+ res = db.executesql(sql, as_dict=True)
+ except: # any exception: return as unknown
+ return {}
+ # process
+ if len(res) > 0:
+ for k, v in res[0].items(): # TODO: what if len(res) > 1
+ if v != None:
+ ret[safe_unic(k)] = safe_unic(v)
return ret
More information about the Hejes-devel
mailing list