Package org.maltparserx.core.syntaxgraph

Examples of org.maltparserx.core.syntaxgraph.DependencyStructure


    // Creates a dependency graph
    if (tokens == null || tokens.length == 0) {
      throw new MaltChainedException("Nothing to convert. ");
    }
    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();
          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


   * @param tokens an array of tokens to parse
   * @return an array of tokens with a head index and a dependency type at the end of string
   * @throws MaltChainedException
   */
  public String[] parseTokens(String[] tokens) throws MaltChainedException {
    DependencyStructure outputGraph = parse(tokens);
    StringBuilder sb = new StringBuilder();
    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();
      }
    }
    return outputTokens;
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.