in opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStream.java [139:188]
private void processNode(Node node, List<String> sentence, List<String> tags,
List<String> target, String inheritedTag) {
String phraseTag = getChunkTag(node);
boolean inherited = false;
if (phraseTag.equals(OTHER) && inheritedTag != null) {
phraseTag = inheritedTag;
inherited = true;
}
TreeElement[] elements = node.getElements();
for (int i = 0; i < elements.length; i++) {
if (elements[i].isLeaf()) {
boolean isIntermediate = false;
String tag = phraseTag;
Leaf leaf = (Leaf) elements[i];
String localChunk = getChunkTag(leaf);
if (localChunk != null && !tag.equals(localChunk)) {
tag = localChunk;
}
if (isIntermediate(tags, target, tag) && (inherited || i > 0)) {
isIntermediate = true;
}
if (!isIncludePunctuations() && leaf.getFunctionalTag() == null &&
(
!( i + 1 < elements.length && elements[i + 1].isLeaf() ) ||
!( i > 0 && elements[i - 1].isLeaf() )
)
) {
isIntermediate = false;
tag = OTHER;
}
processLeaf(leaf, isIntermediate, tag, sentence,
tags, target);
} else {
int before = target.size();
processNode((Node) elements[i], sentence, tags, target, phraseTag);
// if the child node was of a different type we should break the chunk sequence
for (int j = target.size() - 1; j >= before; j--) {
if (!target.get(j).endsWith("-" + phraseTag)) {
phraseTag = OTHER;
break;
}
}
}
}
}