// System.out.println("Error in loading XML lexicon: Word with no base");
// return null;
// }
// create word
WordElement word = new WordElement();
List<Inflection> inflections = new ArrayList<Inflection>();
// now copy features
NodeList nodes = wordNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node featureNode = nodes.item(i);
if (featureNode.getNodeType() == Node.ELEMENT_NODE) {
String feature = featureNode.getNodeName().trim();
String value = featureNode.getTextContent();
if (value != null)
value = value.trim();
if (feature == null) {
System.out.println("Error in XML lexicon node for "
+ word.toString());
break;
}
if (feature.equalsIgnoreCase(XML_BASE)) {
word.setBaseForm(value);
} else if (feature.equalsIgnoreCase(XML_CATEGORY))
word.setCategory(LexicalCategory.valueOf(value
.toUpperCase()));
else if (feature.equalsIgnoreCase(XML_ID))
word.setId(value);
else if (value == null || value.equals("")) {
// if this is an infl code, add it to inflections
Inflection infl = Inflection.getInflCode(feature);
if (infl != null) {
inflections.add(infl);
} else {
// otherwise assume it's a boolean feature
word.setFeature(feature, true);
}
} else
word.setFeature(feature, value);
}
}
// if no infl specified, assume regular
if (inflections.isEmpty()) {
inflections.add(Inflection.REGULAR);
}
// default inflection code is "reg" if we have it, else random pick form
// infl codes available
Inflection defaultInfl = inflections.contains(Inflection.REGULAR) ? Inflection.REGULAR
: inflections.get(0);
word.setFeature(LexicalFeature.DEFAULT_INFL, defaultInfl);
word.setDefaultInflectionalVariant(defaultInfl);
for(Inflection infl: inflections) {
word.addInflectionalVariant(infl);
}
// done, return word
return word;
}