Package org.maltparserx.core.syntaxgraph.node

Examples of org.maltparserx.core.syntaxgraph.node.DependencyNode


      throw new SyntaxGraphException("Head node is not a root node or a terminal node.");
    }
  }
 
  public Edge moveDependencyEdge(int newHeadIndex, int dependentIndex) throws MaltChainedException {
    DependencyNode newHead = null;
    DependencyNode dependent = null;
    if (newHeadIndex == 0) {
      newHead = root;
    } else if (newHeadIndex > 0) {
      newHead = terminalNodes.get(newHeadIndex);
    }
View Full Code Here


    }
    DependencyStructure outputGraph = new DependencyGraph(symbolTables);
   
    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();
View Full Code Here

    String[] outputTokens = new String[tokens.length];
    SymbolTable deprelTable = outputGraph.getSymbolTables().getSymbolTable("DEPREL");
    for (Integer index : outputGraph.getTokenIndices()) {
      sb.setLength(0);
      if (index <= tokens.length) {
        DependencyNode node = outputGraph.getDependencyNode(index);
        sb.append(tokens[index -1]);
        sb.append('\t');
        sb.append(node.getHead().getIndex());
        sb.append('\t');
        if (node.getHeadEdge().hasLabel(deprelTable)) {
          sb.append(node.getHeadEdge().getLabelSymbol(deprelTable));
        } else {
          sb.append(outputGraph.getDefaultRootEdgeLabelSymbol(deprelTable));
        }
        outputTokens[index-1] = sb.toString();
      }
View Full Code Here

 
  private void updateDependencyEdges(MappablePhraseStructureGraph graph, PhraseStructureNode top) throws MaltChainedException {
    if (top == null) {
      return;
    }
    DependencyNode head = null;
    DependencyNode dependent = null;
    if (top instanceof NonTerminalNode) {
      for (PhraseStructureNode node : ((NonTerminalNode)top).getChildren()) {
        if (node instanceof NonTerminalNode) {
          updateDependencyEdges(graph,node);
        } else {
          head = ((NonTerminalNode)top).getLexicalHead(headRules);
          dependent = (DependencyNode)node;
          if (head != null && dependent != null && head != dependent) {
            lockUpdate = true;
            if (!dependent.hasHead()) {
              graph.addDependencyEdge(head, dependent);
            }
            else if (head != dependent.getHead()) {
              graph.moveDependencyEdge(head, dependent);
            }
            lockUpdate = false;
          }
        }
      }
    }
   
    head = null;
    if (top.getParent() != null) {
      head = ((NonTerminalNode)top.getParent()).getLexicalHead(headRules);
    } else if (top.isRoot()) {
      head = (DependencyNode)top; 
    }
   
    if (top instanceof NonTerminalNode) {
      dependent = ((NonTerminalNode)top).getLexicalHead(headRules);
    } else if (!top.isRoot()) {
      dependent = (DependencyNode)top;
    }
    if (head != null && dependent != null && head != dependent) {
      lockUpdate = true;
      if (!dependent.hasHead()) {
        graph.addDependencyEdge(head, dependent);
      }
      else if (head != dependent.getHead()) {
        graph.moveDependencyEdge(head, dependent);
      }
      lockUpdate = false;
    }
  }
View Full Code Here

          es = j = j + 1;
        }
      }

      // Recursively attach the dependent spines to target node.
      DependencyNode target = (DependencyNode)depEdge.getTarget();
      for (int i = 0; i < target.getLeftDependentCount(); i++) {
        updatePhraseStructureGraph(graph, target.getLeftDependent(i).getHeadEdge(), attachHeadSpineToRoot);
      }
      for (int i = target.getRightDependentCount()-1; i >= 0 ; i--) {
        updatePhraseStructureGraph(graph, target.getRightDependent(i).getHeadEdge(), attachHeadSpineToRoot);
      }
    } else {
      // If dependent spine already exist, then set dependentSpine to the highest nonterminal
      // of the dependent spine.
      while (dependentSpine.getParent() != null && !dependentSpine.getParent().isRoot()) {
        dependentSpine = dependentSpine.getParent();
      }
    }

   
    PhraseStructureNode headSpine = null;
    if (((PhraseStructureNode)depEdge.getSource()).getParent() != null) {
      // If head spine exist, then attach dependent spine to the head spine at the attachment level a.
      int a = 0;
      headSpine = ((PhraseStructureNode)depEdge.getSource()).getParent();
      if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(ATTACH))) {
        try {
        a = Integer.parseInt((depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(ATTACH))));
        } catch (NumberFormatException e) {
          throw new MaltChainedException(e.getMessage());
        }
      }
      for (int i = 0; i < a && headSpine != null; i++) {
        headSpine = headSpine.getParent();
      }
     
      if ((headSpine == null || headSpine == dependentSpine) && attachHeadSpineToRoot) {
        headSpine = graph.getPhraseStructureRoot();
      }
      if (headSpine != null) {
        lockUpdate = true;
        Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
        if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)).equals(EMPTY_LABEL) & e != null) {
          e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
        }
        lockUpdate = false;
      }
    }
    else if (depEdge.getSource().isRoot() && !depEdge.isLabeled()) {
        headSpine = graph.getPhraseStructureRoot();
        lockUpdate = true;
        Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
        if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)).equals(EMPTY_LABEL) & e != null) {
          e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
        } else {
          e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), graph.getDefaultRootEdgeLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
        }
        lockUpdate = false;
        // Recursively attach the dependent spines to target node.
        DependencyNode target = (DependencyNode)depEdge.getTarget();
        for (int i = 0; i < target.getLeftDependentCount(); i++) {
          updatePhraseStructureGraph(graph, target.getLeftDependent(i).getHeadEdge(), attachHeadSpineToRoot);
        }
        for (int i = target.getRightDependentCount()-1; i >= 0 ; i--) {
          updatePhraseStructureGraph(graph, target.getRightDependent(i).getHeadEdge(), attachHeadSpineToRoot);
        }
    }
  }
View Full Code Here

    super.clear();
  }
 
  public String toStringTerminalNode(TokenNode node) {
    final StringBuilder sb = new StringBuilder();
    final DependencyNode depnode = node;

    sb.append(node.toString().trim());
    if (depnode.hasHead()) {
      sb.append('\t');
      try {
        sb.append(depnode.getHead().getIndex());
        sb.append('\t');
        sb.append(depnode.getHeadEdge().toString());
      } catch (MaltChainedException e) {
        System.err.println(e);
      }
    }
    sb.append('\n');
View Full Code Here

   * @throws MaltChainedException
   */
  public void propagate(Edge e) throws MaltChainedException {
    if (e != null && e.hasLabel(deprelTable) && !e.getSource().isRoot()) {
      if (overSet.size() == 0 || overSet.contains(e.getLabelSymbol(deprelTable))) {
        DependencyNode to = (DependencyNode)e.getSource();
        DependencyNode from = (DependencyNode)e.getTarget();
        String fromSymbol = null;
        if (e.hasLabel(fromTable)) {
          fromSymbol = e.getLabelSymbol(fromTable);
        } else if (from.hasLabel(fromTable)) {
          fromSymbol = from.getLabelSymbol(fromTable);
        }
       
        String propSymbol = null;
        if (to.hasLabel(toTable)) {
          propSymbol = union(fromSymbol, to.getLabelSymbol(toTable));
View Full Code Here

  }
 
  public void copyTerminalStructure(TokenStructure sourceGraph, TokenStructure targetGraph) throws MaltChainedException {
    targetGraph.clear();
    for (int index : sourceGraph.getTokenIndices()) {
      DependencyNode gnode = sourceGraph.getTokenNode(index);
      DependencyNode pnode = targetGraph.addTokenNode(gnode.getIndex());
      for (SymbolTable table : gnode.getLabelTypes()) {
        pnode.addLabel(table, gnode.getLabelSymbol(table));
      }
    }
  }
View Full Code Here

    if (partHead == null || partDeprel == null) {
      return;
    }
    SymbolTable deprel = cachedTarget.getSymbolTables().getSymbolTable("DEPREL");
    for (int index : sourceGraph.getTokenIndices()) {
      DependencyNode snode = sourceGraph.getTokenNode(index);
      DependencyNode tnode = targetGraph.getTokenNode(index);
      if (snode != null && tnode != null) {
        int spartheadindex = Integer.parseInt(snode.getLabelSymbol(partHead));
        String spartdeprel = snode.getLabelSymbol(partDeprel);
        if (spartheadindex > 0) {
          Edge tedge = targetGraph.addDependencyEdge(spartheadindex, snode.getIndex());
View Full Code Here

TOP

Related Classes of org.maltparserx.core.syntaxgraph.node.DependencyNode

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.