[Hejes-devel] [722] kulegy: help line in explanation now uses transliteration of number of steps
hejes-devel at nytud.hu
hejes-devel at nytud.hu
Thu May 9 23:13:55 CEST 2013
Revision: 722
Author: mihaltz
Date: 2013-05-09 23:13:55 +0200 (Thu, 09 May 2013)
Log Message:
-----------
kulegy: help line in explanation now uses transliteration of number of steps
Modified Paths:
--------------
trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2_output.py
trunk/web2py/applications/helyesiras_webdev/modules/szamok.py
trunk/web2py/applications/helyesiras_webdev/modules/util.py
Modified: trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2_output.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2_output.py 2013-05-09 19:56:26 UTC (rev 721)
+++ trunk/web2py/applications/helyesiras_webdev/modules/egybekulon2_output.py 2013-05-09 21:13:55 UTC (rev 722)
@@ -12,6 +12,7 @@
from xml.etree.ElementTree import Element, SubElement, tostring
import xml.sax
import xml.sax.handler
+from util import int2txt
from egybekulon2_def import DISPLAY_NONTERM_HEJESNODE_ATTRIBUTES, DISPLAY_NODE_ATTRIBUTES, GRM_MULTIVALUE_ATTRIBUTES
from egybekulon2_parser.parser import GRAMMAR
@@ -175,7 +176,7 @@
expl = explain_struct(hnode, toklst)
if len(expl) > 1: # if #steps>1, add line "x szabályt alkalmaztunk az alábbi sorrendben:"
help = SubElement(root, 'div', {'class':'expl_help'})
- help.text = u'{0} szabályt alkalmaztunk az alábbi sorrendben:'.format(len(expl))
+ help.text = u'{0} szabályt alkalmaztunk az alábbi sorrendben:'.format(int2txt(len(expl), True, True))
for i, exp in enumerate(expl):
step = SubElement(root, 'div', {'class':'expl_step'})
step.text = step.tail = '\n'
Modified: trunk/web2py/applications/helyesiras_webdev/modules/szamok.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/szamok.py 2013-05-09 19:56:26 UTC (rev 721)
+++ trunk/web2py/applications/helyesiras_webdev/modules/szamok.py 2013-05-09 21:13:55 UTC (rev 722)
@@ -326,7 +326,7 @@
def translit(self):
""" Transliterate the numeral represented by this class into an array of strings (Hungarian numeric expressions).
See module function parse() about how to create an object from this class.
- Returns triple [transliteration, reference, remarks].
+ Returns list of triples [transliteration, reference, remarks].
Returns [] (emtpy array) if class was not instantiated properly (e.g. parse() returned None).
"""
Modified: trunk/web2py/applications/helyesiras_webdev/modules/util.py
===================================================================
--- trunk/web2py/applications/helyesiras_webdev/modules/util.py 2013-05-09 19:56:26 UTC (rev 721)
+++ trunk/web2py/applications/helyesiras_webdev/modules/util.py 2013-05-09 21:13:55 UTC (rev 722)
@@ -7,7 +7,9 @@
"""
#from gluon import *
+import szamok
+
def safeint(s):
"""s: string representing an int (or not)
returns: None if s could not be converted to int, or an int representing s otherwise
@@ -18,3 +20,31 @@
return None
else:
return i
+
+
+def int2txt(i, ismodifier=False, titlecase=False):
+ """Return unicode string representing Hungarian transliteration of int i via szamok.py.
+ If ismodifier is True, ending 2 is "két": két alma, tizenkét alma etc. (otherwise "kettő").
+ If titlecase is True, first character is capitalized.
+ If anything fails, returns str(i).
+ """
+ try:
+ errs = []
+ s = str(i)
+ n = szamok.parse(s, errs)
+ if n == None:
+ return unicode(i, 'utf8', 'replace')
+ t = n.translit()
+ if len(t) == 0:
+ return str(i)
+ uret = unicode(t[0][0], 'utf8', 'replace')
+ if ismodifier and uret.endswith(u'kettő'): # this is a hack until szamok.py knows this
+ uret = uret[:-len(u'kettő')] + u'két'
+ if titlecase:
+ uret = uret.title()
+ return uret
+ except Exception as e:
+ return unicode(i, 'utf8', 'replace')
+
+
+
More information about the Hejes-devel
mailing list