Package org.maltparserx.core.syntaxgraph

Examples of org.maltparserx.core.syntaxgraph.DependencyStructure


      covingtonConfig.setLeft(covingtonConfig.getRight() - 1);
    } else {
      int leftstop = covingtonConfig.getLeftstop();
      int left = covingtonConfig.getLeft();
      if (trans == NOARC) {
        DependencyStructure dg = covingtonConfig.getDependencyStructure();
        DependencyNode leftNode = covingtonConfig.getInput().get(covingtonConfig.getLeft());
        if (dg.getTokenNode(leftNode.getIndex()) != null && dg.getTokenNode(leftNode.getIndex()).hasHead()) {
          left = dg.getTokenNode(leftNode.getIndex()).getHead().getIndex();
        } else {
          left = leftstop - 1;
        }
      } else {
        DependencyNode rightNode = covingtonConfig.getRightTarget();
View Full Code Here


 
  public boolean permissible(GuideUserAction currentAction, ParserConfiguration config) throws MaltChainedException {
    CovingtonConfig covingtonConfig = (CovingtonConfig)config;
    DependencyNode leftTarget = covingtonConfig.getLeftTarget();
    DependencyNode rightTarget = covingtonConfig.getRightTarget();
    DependencyStructure dg = covingtonConfig.getDependencyGraph();
    currentAction.getAction(actionContainers);
    int trans = transActionContainer.getActionCode();
   
    if (trans == SHIFT && covingtonConfig.isAllowShift() == false) {
      return false;
    }
    if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) {
      return false;
    }
    if (trans == LEFTARC && leftTarget.isRoot()) {
      return false;
    }
    if (trans == LEFTARC && dg.hasLabeledDependency(leftTarget.getIndex())) {
      return false;
    }
    if (trans == RIGHTARC && dg.hasLabeledDependency(rightTarget.getIndex())) {
      return false;
    }
    return true;
  }
View Full Code Here

 
  public boolean permissible(GuideUserAction currentAction, ParserConfiguration config) throws MaltChainedException {
    CovingtonConfig covingtonConfig = (CovingtonConfig)config;
    DependencyNode leftTarget = covingtonConfig.getLeftTarget();
    DependencyNode rightTarget = covingtonConfig.getRightTarget();
    DependencyStructure dg = covingtonConfig.getDependencyGraph();
    currentAction.getAction(actionContainers);
    int trans = transActionContainer.getActionCode();
   
    if (trans == SHIFT && covingtonConfig.isAllowShift() == false) {
      return false;
    }
    if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) {
      return false;
    }
    if (trans == LEFTARC && leftTarget.isRoot()) {
      return false;
    }
    if (trans == LEFTARC && dg.hasLabeledDependency(leftTarget.getIndex())) {
      return false;
    }
    if (trans == RIGHTARC && dg.hasLabeledDependency(rightTarget.getIndex())) {
      return false;
    }
    return true;
  }
View Full Code Here

    setGuideName("Planar");
  }
 
  public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException {
    PlanarConfig planarConfig = (PlanarConfig)config;
    DependencyStructure dg = planarConfig.getDependencyGraph();
    DependencyNode stackPeek = planarConfig.getStack().peek();
    int stackPeekIndex = stackPeek.getIndex();
    int inputPeekIndex = planarConfig.getInput().peek().getIndex();
   
    if (!stackPeek.isRoot() && gold.getTokenNode(stackPeekIndex).getHead().getIndex() == inputPeekIndex
View Full Code Here

    currentAction.getAction(actionContainers);
    int trans = transActionContainer.getActionCode();
    PlanarConfig planarConfig = (PlanarConfig)config;
    DependencyNode stackPeek = planarConfig.getStack().peek();
    DependencyNode inputPeek = planarConfig.getInput().peek();
    DependencyStructure dg = planarConfig.getDependencyGraph();
    //int rootHandling = planarConfig.getRootHandling();
    boolean singleHeadConstraint = planarConfig.requiresSingleHead();
    boolean noCoveredRootsConstraint = planarConfig.requiresNoCoveredRoots();
    boolean acyclicityConstraint = planarConfig.requiresAcyclicity();
    boolean connectednessConstraintOnReduce = planarConfig.requiresConnectednessCheckOnReduce();
    boolean connectednessConstraintOnShift = planarConfig.requiresConnectednessCheckOnShift();
    if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) {
      return false;
    }
    //if ((trans == LEFTARC || trans == REDUCE) && stackPeek.isRoot()) {
    //  return false;
    //}
    if (trans == LEFTARC) {
      //avoid making root child of something
      if ( stackPeek.isRoot() )
        return false;
      //enforce single-head constraint if present
      if ( stackPeek.hasHead() && singleHeadConstraint )
        return false;
      //avoid two links being created from and to the same node
      if ( stackPeek.hasHead() && dg.getTokenNode(stackPeek.getIndex()).getHead().getIndex() == inputPeek.getIndex() )
        return false;
      //enforce acyclicity constraint if present
      if ( acyclicityConstraint && stackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() )
        return false;
    }
    if (trans == RIGHTARC) {
      //enforce single-head constraint if present
      if ( inputPeek.hasHead() && singleHeadConstraint )
        return false;
      //avoid two links being created from and to the same node
      if ( inputPeek.hasHead() && dg.getTokenNode(inputPeek.getIndex()).getHead().getIndex() == stackPeek.getIndex() )
        return false;
      //enforce acyclicity constraint if present
      if ( acyclicityConstraint && stackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() )
        return false;
    }
View Full Code Here

  private static final int NO_PLANE = 3;
  private Map<Edge,Integer> linksToPlanes = new IdentityHashMap<Edge,Integer>();
 
  public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException {
    TwoPlanarConfig planarConfig = (TwoPlanarConfig)config;
    DependencyStructure dg = planarConfig.getDependencyGraph();
    DependencyNode activeStackPeek = planarConfig.getActiveStack().peek();
    DependencyNode inactiveStackPeek = planarConfig.getInactiveStack().peek();
    int activeStackPeekIndex = activeStackPeek.getIndex();
    int inactiveStackPeekIndex = inactiveStackPeek.getIndex();
    int inputPeekIndex = planarConfig.getInput().peek().getIndex();
View Full Code Here

    int trans = transActionContainer.getActionCode();
    TwoPlanarConfig planarConfig = (TwoPlanarConfig)config;
    DependencyNode activeStackPeek = planarConfig.getActiveStack().peek();
    DependencyNode inactiveStackPeek = planarConfig.getInactiveStack().peek();
    DependencyNode inputPeek = planarConfig.getInput().peek();
    DependencyStructure dg = planarConfig.getDependencyGraph();
    //int rootHandling = planarConfig.getRootHandling();
    boolean singleHeadConstraint = planarConfig.requiresSingleHead();
    boolean noCoveredRootsConstraint = planarConfig.requiresNoCoveredRoots();
    boolean acyclicityConstraint = planarConfig.requiresAcyclicity();
    //boolean connectednessConstraintOnReduce = planarConfig.requiresConnectednessCheckOnReduce();
    //boolean connectednessConstraintOnShift = planarConfig.requiresConnectednessCheckOnShift();
    if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) {
      return false;
    }
    //if ((trans == LEFTARC || trans == REDUCE) && stackPeek.isRoot()) {
    //  return false;
    //}
    if (trans == LEFTARC) {
      //avoid making root child of something
      if ( activeStackPeek.isRoot() )
        return false;
      //enforce single-head constraint if present
      if ( activeStackPeek.hasHead() && singleHeadConstraint )
        return false;
      //avoid two links being created from and to the same node
      if ( activeStackPeek.hasHead() && dg.getTokenNode(activeStackPeek.getIndex()).getHead().getIndex() == inputPeek.getIndex() )
        return false;
      //enforce acyclicity constraint if present
      if ( acyclicityConstraint && activeStackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() )
        return false;
    }
    if (trans == RIGHTARC) {
      //enforce single-head constraint if present
      if ( inputPeek.hasHead() && singleHeadConstraint )
        return false;
      //avoid two links being created from and to the same node
      if ( inputPeek.hasHead() && dg.getTokenNode(inputPeek.getIndex()).getHead().getIndex() == activeStackPeek.getIndex() )
        return false;
      //enforce acyclicity constraint if present
      if ( acyclicityConstraint && activeStackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() )
        return false;
    }
View Full Code Here

  public void process(Object[] arguments) throws MaltChainedException {
    if (mode == LEARN) {
      if (arguments.length < 2 || !(arguments[0] instanceof DependencyStructure) || !(arguments[1] instanceof DependencyStructure)) {
        throw new MaltChainedException("The single malt learn task must be supplied with at least two dependency structures. ");
      }
      DependencyStructure systemGraph = (DependencyStructure)arguments[0];
      DependencyStructure goldGraph = (DependencyStructure)arguments[1];
      if (systemGraph.hasTokens() && getGuide() != null) {
        getGuide().finalizeSentence(((Trainer)getAlgorithm()).parse(goldGraph, systemGraph));
      }
    } else if (mode == PARSE) {
      if (arguments.length < 1 || !(arguments[0] instanceof DependencyStructure)) {
        throw new MaltChainedException("The single malt parse task must be supplied with at least one input terminal structure and one output dependency structure. ");
      }
      DependencyStructure processGraph = (DependencyStructure)arguments[0];
      if (processGraph.hasTokens()) {
        parser.parse(processGraph);
//        ((Parser)getAlgorithm()).parse(processGraph);
      }
    }
  }
View Full Code Here

    }
    if (tokens == null || tokens.length == 0) {
      throw new MaltChainedException("Nothing to parse. ");
    }

    DependencyStructure outputGraph = new DependencyGraph(singleMalt.getSymbolTables());
   
    for (int i = 0; i < tokens.length; i++) {
      Iterator<ColumnDescription> columns = dataFormatInstance.iterator();
      DependencyNode node = outputGraph.addDependencyNode(i+1);
      String[] items = tokens[i].split("\t");
      for (int j = 0; j < items.length; j++) {
        if (columns.hasNext()) {
          ColumnDescription column = columns.next();
          if (column.getCategory() == ColumnDescription.INPUT && node != null) {
            outputGraph.addLabel(node, column.getName(), items[j]);
          }
        }
      }
    }
    outputGraph.setDefaultRootEdgeLabel(outputGraph.getSymbolTables().getSymbolTable("DEPREL"), "ROOT");
    // Invoke parse with the output graph
    singleMalt.parse(outputGraph);
    return outputGraph;
  }
View Full Code Here

      throw new MaltChainedException("No parser model has been initialized. Please use the method initializeParserModel() before invoking this method.");
    }
    if (tokens == null || tokens.length == 0) {
      throw new MaltChainedException("Nothing to convert. ");
    }
    DependencyStructure outputGraph = new DependencyGraph(singleMalt.getSymbolTables());
   
    for (int i = 0; i < tokens.length; i++) {
      Iterator<ColumnDescription> columns = dataFormatInstance.iterator();
      DependencyNode node = outputGraph.addDependencyNode(i+1);
      String[] items = tokens[i].split("\t");
      Edge edge = null;
      for (int j = 0; j < items.length; j++) {
        if (columns.hasNext()) {
          ColumnDescription column = columns.next();
          if (column.getCategory() == ColumnDescription.INPUT && node != null) {
            outputGraph.addLabel(node, column.getName(), items[j]);
          } else if (column.getCategory() == ColumnDescription.HEAD) {
            if (column.getCategory() != ColumnDescription.IGNORE && !items[j].equals("_")) {
              edge = ((DependencyStructure)outputGraph).addDependencyEdge(Integer.parseInt(items[j]), i+1);
            }
          } else if (column.getCategory() == ColumnDescription.DEPENDENCY_EDGE_LABEL && edge != null) {
            outputGraph.addLabel(edge, column.getName(), items[j]);
          }
        }
      }
    }
    outputGraph.setDefaultRootEdgeLabel(outputGraph.getSymbolTables().getSymbolTable("DEPREL"), "ROOT");
    return outputGraph;
  }
View Full Code Here

TOP

Related Classes of org.maltparserx.core.syntaxgraph.DependencyStructure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.