Search in sources :

Example 66 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class ParseConfiguration method getHead.

/**
 * Get the head of a given pos-tagged token in the current set of
 * dependencies, or null if none exists.
 *
 * @param dependent
 *          the token whose governing arc we want
 * @param projective
 *          if true, consider projective set, if false consider non-projective
 *          set.
 */
public PosTaggedToken getHead(PosTaggedToken dependent, boolean projective) {
    DependencyArc arc = this.getGoverningDependency(dependent, projective);
    PosTaggedToken head = null;
    if (arc != null)
        head = arc.getHead();
    return head;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 67 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class ParseConfiguration method addDependency.

/**
 * @param arc
 * @throws CircularDependencyException
 *           if this would create a circular dependency.
 */
void addDependency(DependencyArc arc) throws CircularDependencyException {
    PosTaggedToken ancestor = arc.getHead();
    while (ancestor != null) {
        if (ancestor.equals(arc.getDependent())) {
            throw new CircularDependencyException(this, arc.getHead(), arc.getDependent());
        }
        ancestor = this.getHead(ancestor);
    }
    this.dependencies.add(arc);
    this.governingDependencyMap[arc.getDependent().getIndex()] = arc;
    this.governorMap[arc.getDependent().getIndex()] = arc.getHead().getIndex();
    this.labelMap[arc.getDependent().getIndex()] = arc.getLabel();
    if (LOG.isTraceEnabled()) {
        LOG.trace("Added arc: " + arc);
        LOG.trace("dependencies: " + this.dependencies);
        LOG.trace("governingDependencyMap: " + this.governingDependencyMap);
    }
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 68 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class ParseTreeNode method getEdgeCount.

/**
 * Non-projectivity: for each edge directly governed by this node, counts the
 * number of connected components contained inside the interval defined by the
 * edge, which are not themselves dominated by this node, i.e. not contained
 * in the node's yield. A connected component is a connected subtree. Returns
 * the maximum edge count.
 */
public int getEdgeCount() {
    List<DependencyArc> nonProjectiveEdges = new ArrayList<>();
    this.getMyNonProjectiveEdges(nonProjectiveEdges);
    List<DependencyArc> gapHeads = this.getGapHeads();
    int maxEdgeCount = 0;
    for (DependencyArc nonProjectiveEdge : nonProjectiveEdges) {
        int edgeCount = 0;
        PosTaggedToken child = nonProjectiveEdge.getDependent();
        int i = this.getIndex() < child.getIndex() ? this.getIndex() : child.getIndex();
        int j = this.getIndex() > child.getIndex() ? this.getIndex() : child.getIndex();
        for (DependencyArc gapHead : gapHeads) {
            if (gapHead.getDependent().getIndex() > i && gapHead.getDependent().getIndex() < j)
                edgeCount++;
        }
        if (edgeCount > maxEdgeCount)
            maxEdgeCount = edgeCount;
    }
    return maxEdgeCount;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 69 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class DependencyNode method isContiguous.

/**
 * Return true if this node is contiguous, false if it contains gaps.
 */
public boolean isContiguous() {
    Set<PosTaggedToken> yield = this.getYield();
    int currentIndex = -1;
    boolean contiguous = true;
    for (PosTaggedToken token : yield) {
        if (currentIndex < 0) {
            currentIndex = token.getIndex();
        } else if (token.getIndex() == currentIndex + 1) {
            currentIndex++;
        } else {
            contiguous = false;
            break;
        }
    }
    return contiguous;
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken)

Example 70 with PosTaggedToken

use of com.joliciel.talismane.posTagger.PosTaggedToken in project talismane by joliciel-informatique.

the class DependencyNode method autoPopulate.

/**
 * Populate this node's dependents directly from the parse configuration.
 */
public void autoPopulate() {
    for (PosTaggedToken dependent : parseConfiguration.getDependents(this.token)) {
        DependencyNode childNode;
        try {
            childNode = this.addDependent(dependent);
        } catch (TalismaneException e) {
            // should never happen
            LOG.error(e.getMessage(), e);
            throw new RuntimeException(e);
        }
        childNode.autoPopulate();
    }
}
Also used : PosTaggedToken(com.joliciel.talismane.posTagger.PosTaggedToken) TalismaneException(com.joliciel.talismane.TalismaneException)

Aggregations

PosTaggedToken (com.joliciel.talismane.posTagger.PosTaggedToken)77 ParseConfiguration (com.joliciel.talismane.parser.ParseConfiguration)24 PosTaggedTokenWrapper (com.joliciel.talismane.posTagger.features.PosTaggedTokenWrapper)20 PosTagSequence (com.joliciel.talismane.posTagger.PosTagSequence)14 Token (com.joliciel.talismane.tokeniser.Token)11 DependencyArc (com.joliciel.talismane.parser.DependencyArc)9 TalismaneException (com.joliciel.talismane.TalismaneException)8 Decision (com.joliciel.talismane.machineLearning.Decision)8 RuntimeEnvironment (com.joliciel.talismane.machineLearning.features.RuntimeEnvironment)8 Sentence (com.joliciel.talismane.rawText.Sentence)8 TokenSequence (com.joliciel.talismane.tokeniser.TokenSequence)8 HashMap (java.util.HashMap)7 List (java.util.List)7 TalismaneTest (com.joliciel.talismane.TalismaneTest)6 PosTaggerContext (com.joliciel.talismane.posTagger.PosTaggerContext)6 PosTaggerContextImpl (com.joliciel.talismane.posTagger.PosTaggerContextImpl)6 Config (com.typesafe.config.Config)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 StringLiteralFeature (com.joliciel.talismane.machineLearning.features.StringLiteralFeature)5