Skip to content
Snippets Groups Projects
Commit 006c4af2 authored by Adam Radziszewski's avatar Adam Radziszewski
Browse files

update converter

parent 0f4ba9e7
No related branches found
No related tags found
No related merge requests found
...@@ -7,11 +7,14 @@ from StringIO import StringIO ...@@ -7,11 +7,14 @@ from StringIO import StringIO
descr = """%prog [options] IN OUT descr = """%prog [options] IN OUT
Attempts to convert JOSKIPI rules to WCCL rules. Attempts to convert JOSKIPI rules to WCCL rules.
NOTE: this is based on very naive heuristics. NOTE: this is based on very naive heuristics. Dirty regex manipulation is done
instead of real parsing.
Known issues:
1. Will not skip superfluous none in non-empty sets.
2. Complex agreement/hasnum/isbig predicates will not be handled properly.
""" """
# TODO agr bits
# TODO isbig -> regex
p_strset = re.compile(u'{(\\s*"[^"]*"(\\s*,\\s*"[^"]*")*\\s*)}', re.U) p_strset = re.compile(u'{(\\s*"[^"]*"(\\s*,\\s*"[^"]*")*\\s*)}', re.U)
p_negposref = re.compile(u'\$\-([0-9]+)([A-Z][A-Za-z0-9]*)') p_negposref = re.compile(u'\$\-([0-9]+)([A-Z][A-Za-z0-9]*)')
...@@ -58,11 +61,11 @@ class Rule: ...@@ -58,11 +61,11 @@ class Rule:
self.act = jos2ccl(act.strip()) self.act = jos2ccl(act.strip())
self.name = name.strip() self.name = name.strip()
def write(self, out, comma = False): def write(self, out, sep = False):
out.write('rule("%s",\n' % self.name) out.write('rule("%s",\n' % self.name)
out.write('%s,\n' % self.cond) out.write('%s,\n' % self.cond)
out.write('%s\n' % self.act) out.write('%s\n' % self.act)
out.write(')%s\n' % (',' if comma else '')) out.write(')%s\n' % (';' if sep else ''))
def rule_texts(infile): def rule_texts(infile):
buf = StringIO() buf = StringIO()
...@@ -97,7 +100,7 @@ def go(): ...@@ -97,7 +100,7 @@ def go():
w = IndentWriter(outf) w = IndentWriter(outf)
indent = 0 indent = 0
w.write('rules(\n') w.write('tag_rules(\n')
# quick and dirty: to get all but last # quick and dirty: to get all but last
allrules = [r for r in rules(inf)] allrules = [r for r in rules(inf)]
for rule in allrules[:-1]: for rule in allrules[:-1]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment