2 * Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include <lttoolbox/Ltstr.H>
27 #include <libxml/xmlreader.h>
31 typedef list<pair<string, string> > EntList;
34 * A compiler of dictionaries to letter transducers
40 * The libxml2's XML reader
42 xmlTextReaderPtr reader;
45 * The paradigm being compiled
47 string current_paradigm;
50 * The direction of the compilation, 'lr' (left-to-right) or 'rl'
58 map<string, EntList, Ltstr> paradigm;
60 map<string, EntList, Ltstr> paradigm_lr;
62 map<string, EntList, Ltstr> paradigm_rl;
65 * Method to parse an XML Node
67 void procNode(FILE *output);
70 * Parse the <pardef> element
75 * Parse the <e> element
77 void procEntry(FILE *output);
80 * Parse the <re> element
81 * @return the string representing the regular expression
86 * Gets an attribute value with their name and the current context
87 * @param name the name of the attribute
88 * @return the value of the attribute
90 string attrib(string const &name);
93 * Parse the <p< element
94 * @return a pair of string, left part and right part of a transduction
96 pair<string, string> procTransduction();
99 * Parse the <i< element
100 * @return a string from the dictionary's entry
102 string procIdentity();
105 * Parse the <par> element
106 * @return the name of the paradigm
111 * Skip all document #text nodes before "elem"
112 * @param name the name of the node
113 * @param elem the name of the expected node
115 void skip(string &name, string const &elem);
118 * Skip all blank #text nodes before "name"
119 * @param name the name of the node
121 void skipBlanks(string &name);
124 void readString(string &result, string const &name);
127 * Force an element to be empty, and check for it
128 * @param name the element
130 void requireEmptyError(string const &name);
133 * Force an attribute to be specified, amd check for it
134 * @param value the value of the attribute
135 * @param attrname the name of the attribute
136 * @param elemname the parent of the attribute
138 void requireAttribute(string const &value, string const &attrname,
139 string const &elemname);
142 * True if all the elements in the current node are blanks
143 * @return true if all are blanks
148 * Append a list of endings to a list of current transductions.
149 * @param result the current partial transductions, and after calling
150 * this method, the result of concatenations.
151 * @param endings the endings to be appended.
153 static void append(list<pair<string, string> > &result,
154 list<pair<string, string> > const &endings);
157 * Append a list of endings to a list of current transductions.
158 * @param result the current partial transductions, and after calling
159 * this method, the result of concatenations.
160 * @param endings the endings to be appended.
162 static void append(list<pair<string, string> > &result,
163 string const &endings);
166 * Append a list of endings to a list of current transductions.
167 * @param result the current partial transductions, and after calling
168 * this method, the result of concatenations.
169 * @param endings the endings to be appended.
171 static void append(list<pair<string, string> > &result,
172 pair<string, string> const &endings);
186 * Compile dictionary to letter transducers
188 void expand(string const &fichero, FILE *output);