commit 4cbae607fe62c428d43c799fd66926dcbe6c1a2a Author: Hèctor Alòs i Font Date: Thu Apr 25 21:06:23 2019 +0300 ús de metalrx per a la selecció lèxica diff --git a/apertium-por-cat.cat-por.lrx b/apertium-por-cat.cat-por.lrx deleted file mode 100644 index 8b55e17..0000000 --- a/apertium-por-cat.cat-por.lrx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/apertium-por-cat.por-cat.lrx b/apertium-por-cat.por-cat.lrx deleted file mode 100644 index 8b55e17..0000000 --- a/apertium-por-cat.por-cat.lrx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metalrx-to-lrx.xslt b/metalrx-to-lrx.xslt new file mode 100644 index 0000000..950afed --- /dev/null +++ b/metalrx-to-lrx.xslt @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Several repeats per rule not supported yet + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/metalrx.py b/metalrx.py new file mode 100644 index 0000000..5fdc46c --- /dev/null +++ b/metalrx.py @@ -0,0 +1,56 @@ +#!/usr/bin/python3 +# +# Copyright (C) 2018 Xavi Ivars +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# + +import sys +import xml.etree.ElementTree as ET + +source = sys.argv[1] +target = sys.argv[2] + +tree = ET.ElementTree() +tree.parse(source) + +rules = tree.find('rules') + +macros = [] + +for macro in tree.iter(tag='macro'): + + defmacro = tree.find('.//def-macro[@name="' + macro.attrib['name'] + '"]') + + macrostr = ET.tostring(defmacro, encoding="unicode") + for k,v in macro.attrib.items(): + if k.startswith('p'): + kstr = '{{' + k + '}}' + macrostr = macrostr.replace(kstr, v) + + newtree = ET.fromstring('' + macrostr + '') + + for r in newtree.iter(tag='rule'): + rules.append(r) + + macros.append(macro) + +allmacrodefs = tree.getroot().find('def-macros') +if allmacrodefs is not None: + tree.getroot().remove(allmacrodefs) + +for macro in macros: + rules.remove(macro) + +tree.write(target)