47 static EST_Regex simpleIDRegex(
".*#id(w\\([0-9]+\\))");
48 static EST_Regex rangeIDRegex(
".*#id(w\\([0-9]+\\)).*id(w\\([0-9]+\\))");
62 Parse_State() : contents(100) {
108 const char *instruction);
118 for(them.
begin(attributes); them ; them++)
120 (
const char *)them->k,
121 (
const char *)them->v);
130 (void)print_attributes;
131 Sole_Parser_Class pclass;
138 XML_Parser *parser = pclass.make_parser(file, name, &state);
151 static void ensure_relation(Parse_State *state)
153 if (state->rel==
NULL)
155 state->rel = state->utt->create_relation(state->relName);
165 state->contents.add_item(
id, c);
178 val = attributes.
val(
"id");
181 else if (attributes.
present(
"href"))
183 val = attributes.
val(
"href");
187 if (val.
matches(simpleIDRegex, 0, starts, ends))
193 else if (val.
matches(rangeIDRegex, 0, starts, ends))
195 int n1 = atoi(val.
at(starts[1], ends[1]-starts[1]));
196 int n2 = atoi(val.
at(starts[2], ends[2]-starts[2]));
198 for(
int i=n1; i<=n2; i++)
201 sprintf(buf,
"w%d", i);
208 EST_warning(
"element with bad ID or HREF '%s'", (
const char *)val);
213 sprintf(buf,
"n%d", ++count);
230 Parse_State *state = (Parse_State *)data;
242 (void)c; (void)p; (void)data;
252 (void)c; (void)p; (void)attributes;
253 Parse_State *state = (Parse_State *)data;
257 if (strcmp(name,
"solexml")==0)
259 state->relName=attributes.
val(
"relation");
260 printf(
"start solexml relation=%s\n", (
const char *)state->relName);
263 else if (strcmp(name,
"text-elem")==0)
269 ensure_relation(state);
271 if (strcmp(name,
"anaphora-elem")==0
272 || strcmp(name,
"wordlist")==0
273 || strcmp(name,
"w")==0)
276 extract_ids(attributes, ids);
280 for(; idp!=
NULL; idp = idp->
next())
290 state->current = state->parent;
291 state->parent=state->parent->up();
300 for(them.
begin(attributes); them ; them++)
309 if (state->current ==
NULL)
310 if (state->parent ==
NULL)
311 item = state->rel->append();
313 item = state->parent->insert_below();
315 item = state->current->insert_after();
324 EST_warning(
"SOLE XML Parser: unknown element %s", name);
334 (void)c; (void)p; (void)attributes;
335 Parse_State *state = (Parse_State *)data;
337 if (strcmp(name,
"language")==0)
339 state->utt->f.set(
"language", attributes.
val(
"name"));
343 element_open(c, p, data, name, attributes);
344 element_close(c, p, data, name);
353 (void)c; (void)p; (void)name;
354 Parse_State *state = (Parse_State *)data;
356 if (strcmp(name,
"anaphora-elem")==0
357 || strcmp(name,
"wordlist")==0
358 || strcmp(name,
"w")==0)
361 state->current = state->parent;
362 state->parent=state->parent->up();;
374 Parse_State *state = (Parse_State *)data;
377 state->parent->set(
EST_String(
"word"), chars);
388 (void)c; (void)p; (void)data; (void)chars;
398 const char *instruction)
401 Parse_State *state = (Parse_State *)data;
403 printf(
"SOLE XML Parser [proc[%s]] %d\n", instruction, state->depth);
411 (void)c; (void)p; (void)data;
414 EST_error(
"SOLE XML Parser %s", get_error(p));
EST_read_status solexml_read(FILE *file, const EST_String &name, EST_Utterance &u, int &max_id)
void set_contents(EST_Item_Content *li)
#define END_CATCH_ERRORS()
void clear()
remove everything in utterance
The file was read in successfully.
A Regular expression class to go with the CSTR EST_String class.
#define EST_Regex_max_subexpressions
void set(const EST_String &name, int ival)
A specialised hash table for when the key is an EST_String.
EST_Track error(EST_Track &ref, EST_Track &test, int relax=0)
EST_Features f
General features for this item.
#define est_error_throw()
V & val(const K &key, int &found) const
int present(const K &key) const
Does the key have an entry?
void track_context(bool flag)
The file exists but is not in the format specified.
void set_name(const EST_String &s)
set name
int matches(const char *e, ssize_t pos=0) const
Exactly match this string?
EST_String context(int n)
void append(const T &item)
add item onto end of list
void begin(const Container &over)
Set the iterator ready to run over this container.
virtual void error(XML_Parser_Class &c, XML_Parser &p, void *data)
EST_String at(int from, int len=0) const
Return part at position.
EST_Item * parent(const EST_Item *n)
return parent of n
static const EST_String Empty
Constant empty string.