[Hejes-devel] [887] addoutput added
hejes-devel at nytud.hu
hejes-devel at nytud.hu
Fri Aug 2 14:16:25 CEST 2013
Revision: 887
Author: mittelholcz
Date: 2013-08-02 14:16:25 +0200 (Fri, 02 Aug 2013)
Log Message:
-----------
addoutput added
Added Paths:
-----------
trunk/misc/log/add_output.py
Added: trunk/misc/log/add_output.py
===================================================================
--- trunk/misc/log/add_output.py (rev 0)
+++ trunk/misc/log/add_output.py 2013-08-02 12:16:25 UTC (rev 887)
@@ -0,0 +1,57 @@
+#!/usr/bin/python
+# coding=utf-8
+
+import sys
+sys.path.append('../../web2py/applications/helyesiras_webdev/modules/')
+import spell
+import egybekulon2
+import Wordform
+from gluon import *
+from time import time
+
+MYDBCONN = DAL('mysql://dbdicter:dbdicter123@localhost/dbdict', migrate_enabled=False)
+#~ print('Connected to database "{0}"'.format(MYDBCONN._uri))
+
+def main():
+
+ for line in sys.stdin:
+ line = unicode(line, 'utf8', 'replace').encode('utf8')
+ line = line.rstrip().split('\t')
+ if len(line) != 2: continue
+ freq, module, query = line[0].lstrip().split(' ')[0], line[0].lstrip().split(' ')[1], line[1]
+ prefix = freq + '\t' + module + '\t' + query + '\t'
+ if not query: continue
+ if len(query.split(' ')) > 7: # skip too long queries
+ print prefix + 'skip'
+ continue
+
+ if module.endswith('kulegy'):
+ #~ based on default.py
+ start = time()
+ st, uni = egybekulon2.SegmentedInputUseCase.toUnicodeChecked(query)
+ if st != 1: print(prefix)
+ ek = egybekulon2.SegmentedInputUseCase(MYDBCONN)
+ if not ek.preprocess(uni): print(prefix)
+ if not ek.analyzeTokens(): print(prefix)
+ n = ek.getExplanations(plaintxt=True)
+ end = time()
+ if n == 0: print('')
+ else:
+ answer = []
+ s = ek.explain.encode('utf8')
+ s = s.split('----------------------------------------')
+ for i in s:
+ i = i.split('\n')[2].split('"')
+ if len(i) == 3: answer.append(i[1])
+ print(prefix + ', '.join(answer) + '\t' + str(end-start))
+
+ if module.endswith('suggest'):
+ query = unicode(query, 'utf8', 'replace')
+ start = time()
+ answer = spell.union_humor_hunspell(query.split(' '))
+ end = time()
+ for i in answer:
+ print(prefix + str(i[0]) + ': ' + ', '.join([ x.encode('utf8') if (type(x)==type(u'')) else str(x) for x in i[1] ]) + '\t' + str(end-start))
+
+if __name__ == '__main__':
+ main()
Property changes on: trunk/misc/log/add_output.py
___________________________________________________________________
Added: svn:executable
+ *
More information about the Hejes-devel
mailing list