if (insideSentenceElement) {
if (WORD_ELEMENT_NAME.equals(qName)) {
String token = tokenBuffer.toString().trim();
if (token.length() > 0) {
cons.add(new Constituent(AbstractBottomUpParser.TOK_NODE,
new Span(offset, offset + token.length())));
text.append(token).append(" ");
offset += token.length() + 1;
}
else {
isCreateConstituent = false;
}
}
Constituent unfinishedCon = stack.pop();
if (isCreateConstituent) {
int start = unfinishedCon.getSpan().getStart();
if (start < offset) {
cons.add(new Constituent(unfinishedCon.getLabel(), new Span(start, offset - 1)));
}
}
if (SENT_ELEMENT_NAME.equals(qName)) {
// Finished parsing sentence, now put everything together and create
// a Parse object
String txt = text.toString();
int tokenIndex = -1;
Parse p = new Parse(txt, new Span(0, txt.length()), AbstractBottomUpParser.TOP_NODE, 1,0);
for (int ci=0;ci < cons.size();ci++) {
Constituent con = cons.get(ci);
String type = con.getLabel();
if (!type.equals(AbstractBottomUpParser.TOP_NODE)) {
if (type == AbstractBottomUpParser.TOK_NODE) {
tokenIndex++;
}
Parse c = new Parse(txt, con.getSpan(), type, 1,tokenIndex);
p.insert(c);
}
}
parses.add(p);