Example usage for opennlp.tools.parser Parse isPosTag

List of usage examples for opennlp.tools.parser Parse isPosTag

Introduction

In this page you can find the example usage for opennlp.tools.parser Parse isPosTag.

Prototype

public boolean isPosTag() 

Source Link

Document

Indicates whether this parse node is a pos-tag.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpParser.java

/**
 * Creates linked constituent annotations + POS annotations
 *
 * @param aNode//from  w w  w  . j a  v  a2  s .c  o  m
 *            the source tree
 * @param aParentFS
 * @param aCreatePos
 *            sets whether to create or not to create POS tags
 * @param aCreateLemmas
 *            sets whether to create or not to create Lemmas
 * @return the child-structure (needed for recursive call only)
 */
private Annotation createConstituentAnnotationFromTree(JCas aJCas, Parse aNode, Annotation aParentFS,
        List<Token> aTokens) {
    // If the node is a word-level constituent node (== POS):
    // create parent link on token and (if not turned off) create POS tag
    if (aNode.isPosTag()) {
        Token token = getToken(aTokens, aNode.getSpan().getStart(), aNode.getSpan().getEnd());

        // link token to its parent constituent
        if (aParentFS != null) {
            token.setParent(aParentFS);
        }

        // only add POS to index if we want POS-tagging
        if (createPosTags) {
            Type posTag = mappingProvider.getTagType(aNode.getType());
            POS posAnno = (POS) aJCas.getCas().createAnnotation(posTag, token.getBegin(), token.getEnd());
            posAnno.setPosValue(internTags ? aNode.getType().intern() : aNode.getType());
            posAnno.addToIndexes();
            token.setPos((POS) posAnno);
        }

        return token;
    }
    // Check if node is a constituent node on sentence or phrase-level
    else {
        String typeName = aNode.getType();
        if (AbstractBottomUpParser.TOP_NODE.equals(typeName)) {
            typeName = "ROOT"; // in DKPro the root is ROOT, not TOP
        }

        // create the necessary objects and methods
        String constituentTypeName = CONPACKAGE + typeName;

        Type type = aJCas.getTypeSystem().getType(constituentTypeName);

        //if type is unknown, map to X-type
        if (type == null) {
            type = aJCas.getTypeSystem().getType(CONPACKAGE + "X");
        }

        Constituent constAnno = (Constituent) aJCas.getCas().createAnnotation(type, aNode.getSpan().getStart(),
                aNode.getSpan().getEnd());
        constAnno.setConstituentType(typeName);

        // link to parent
        if (aParentFS != null) {
            constAnno.setParent(aParentFS);
        }

        // Do we have any children?
        List<Annotation> childAnnotations = new ArrayList<Annotation>();
        for (Parse child : aNode.getChildren()) {
            Annotation childAnnotation = createConstituentAnnotationFromTree(aJCas, child, constAnno, aTokens);
            if (childAnnotation != null) {
                childAnnotations.add(childAnnotation);
            }
        }

        // Now that we know how many children we have, link annotation of
        // current node with its children
        FSArray childArray = (FSArray) FSCollectionFactory.createFSArray(aJCas, childAnnotations);
        constAnno.setChildren(childArray);

        // write annotation for current node to index
        aJCas.addFsToIndexes(constAnno);

        return constAnno;
    }
}

From source file:es.ehu.si.ixa.pipe.convert.Convert.java

/**
 * It converts a penn treebank constituent tree into tokens oneline form.
 * /*from  w ww.java  2 s .  c o m*/
 * @param parse
 *          the parse tree
 * @param sb
 *          the stringbuilder to add the trees
 */
private void getTokens(Parse parse, StringBuilder sb) {
    if (parse.isPosTag()) {
        if (!parse.getType().equals("-NONE-")) {
            sb.append(parse.getCoveredText()).append(" ");
        }
    } else {
        Parse children[] = parse.getChildren();
        for (int i = 0; i < children.length; i++) {
            getTokens(children[i], sb);
        }
    }
}

From source file:es.ehu.si.ixa.pipe.convert.Convert.java

/**
 * It converts a penn treebank constituent tree into Word_POS form
 * /*  ww w .  j  a va 2 s.  c om*/
 * @param parse
 * @param sb
 */
private void getWordType(Parse parse, StringBuilder sb) {
    if (parse.isPosTag()) {
        if (!parse.getType().equals("-NONE-")) {
            sb.append(parse.getCoveredText()).append("_").append(parse.getType()).append(" ");
        }
    } else {
        Parse children[] = parse.getChildren();
        for (int i = 0; i < children.length; i++) {
            getWordType(children[i], sb);
        }
    }
}