Package org.maltparserx.core.io.dataformat

Examples of org.maltparserx.core.io.dataformat.ColumnDescription


    }
    Iterator<ColumnDescription> columns = dataFormatInstance.iterator();
   
    for (int i : syntaxGraph.getTokenIndices()) {
      try {
        ColumnDescription column = null;
        while (columns.hasNext()) {
          column = columns.next();

          if (column.getCategory() == ColumnDescription.INPUT) { // && column.getType() != ColumnDescription.IGNORE) {
            TokenNode node = syntaxGraph.getTokenNode(i);
            if (!column.getName().equals("ID")) {
              if (node.hasLabel(column.getSymbolTable())) {
                output.append(node.getLabelSymbol(column.getSymbolTable()));
                if (output.length() != 0) {
                  writer.write(output.toString());
                } else {
                  writer.write('_');
                }
              } else {
                writer.write('_');
              }
            } else {
              writer.write(Integer.toString(i));
            }
          } else if (column.getCategory() == ColumnDescription.HEAD /* && column.getType() != ColumnDescription.IGNORE */&& syntaxGraph instanceof DependencyStructure) {
            if (((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHead()) {
              writer.write(Integer.toString(((DependencyStructure)syntaxGraph).getDependencyNode(i).getHead().getIndex()));
            } else {
              writer.write(Integer.toString(0));
            }
           
          } else if (column.getCategory() == ColumnDescription.DEPENDENCY_EDGE_LABEL /* && column.getType() != ColumnDescription.IGNORE */ && syntaxGraph instanceof DependencyStructure) {
            if (((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHead() && ((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHeadEdgeLabel(column.getSymbolTable())) {
              output.append(((DependencyStructure)syntaxGraph).getDependencyNode(i).getHeadEdgeLabelSymbol(column.getSymbolTable()));
            } else {
              output.append(((DependencyStructure)syntaxGraph).getDefaultRootEdgeLabelSymbol(column.getSymbolTable()));
            }
           
            if (output.length() != 0) {
              writer.write(output.toString());
            }
          } else {
            writer.write(column.getDefaultOutput());
          }
          if (columns.hasNext()) {
            writer.write(TAB);
          }
          output.setLength(0);
View Full Code Here


    if (!(arguments[1] instanceof String)) {
      throw new FeatureException("Could not initialize SplitFeature: the second argument is not a string. ");
    }
    setParentFeature((FeatureFunction)arguments[0]);
    setSeparators((String)arguments[1]);
    ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.getSymbolTable().getName());
    if (parentColumn.getType() != ColumnDescription.STRING) {
      throw new FeatureException("Could not initialize SplitFeature: the first argument must be a string. ");
    }
    setColumn(dataFormatInstance.addInternalColumnDescription("SPLIT_"+parentFeature.getSymbolTable().getName(), parentColumn));
    setSymbolTable(column.getSymbolTable());
//    setSymbolTable(tableHandler.addSymbolTable("SPLIT_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
View Full Code Here

    if (!(arguments[1] instanceof Integer)) {
      throw new FeatureException("Could not initialize SuffixFeature: the second argument is not a string. ");
    }
    setParentFeature((FeatureFunction)arguments[0]);
    setSuffixLength(((Integer)arguments[1]).intValue());
    ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.getSymbolTable().getName());
    if (parentColumn.getType() != ColumnDescription.STRING) {
      throw new FeatureException("Could not initialize SuffixFeature: the first argument must be a string. ");
    }
    setColumn(dataFormatInstance.addInternalColumnDescription("SUFFIX_"+suffixLength+"_"+parentFeature.getSymbolTable().getName(), parentColumn));
    setSymbolTable(column.getSymbolTable());
//    setSymbolTable(tableHandler.addSymbolTable("SUFFIX_"+suffixLength+"_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
View Full Code Here

    if (!(arguments[1] instanceof FeatureFunction)) {
      throw new FeatureException("Could not initialize MergeFeature: the second argument is not a feature. ");
    }
    setFirstFeature((FeatureFunction)arguments[0]);
    setSecondFeature((FeatureFunction)arguments[1]);
    ColumnDescription firstColumn = (firstFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(firstFeature.getSymbolTable().getName()):null;
    ColumnDescription secondColumn = (secondFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(secondFeature.getSymbolTable().getName()):null;
//    if (firstColumn.getType() != secondColumn.getType()) {
//      throw new FeatureException("Could not initialize MergeFeature: the first and the second arguments are not of the same type.");
//    }
//    setColumn(dataFormatInstance.addInternalColumnDescription("MERGE2_"+firstFeature.getSymbolTable().getName()+"_"+secondFeature.getSymbolTable().getName(), firstColumn));
View Full Code Here

          }
          sentenceCount++;
        } else if (currentHeaderTable == NegraTables.SENTENCE) {
          if (line.length() >= 2 && line.charAt(0) == '#' && Character.isDigit(line.charAt(1))) { // Non-terminal
            Iterator<ColumnDescription> columns = dataFormatInstance.iterator();
            ColumnDescription column = null;
            currentNonTerminalSize++;
            char[] lineChars = line.toCharArray();
            int start = 0;
            int secedgecounter = 0;
            for (int i = 0, n = lineChars.length; i < n; i++) {
              if (lineChars[i] == '\t' && start == i) {
                start++;
              } else if (lineChars[i] == '\t' || i == n - 1) {
                if (columns.hasNext()) {
                  column = columns.next();
                }
                if (column.getPosition() == 0) {
                  int index = Integer.parseInt((i == n - 1)?line.substring(start+1):line.substring(start+1, i));
                  child = nonterminals.get(index);
                  if (child == null) {
                    if (index != 0) {
                      child = ((PhraseStructure)syntaxGraph).addNonTerminalNode(index-START_ID_OF_NONTERMINALS+1);
                    }
                    nonterminals.put(index,child);
                  }
                } else if (column.getPosition() == 2 && child != null) {
                  syntaxGraph.addLabel(child, "CAT", (i == n - 1)?line.substring(start):line.substring(start, i));
                } else if (column.getCategory() == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL) {
                  edgelabelSymbol.setLength(0);
                  edgelabelSymbol.append((i == n - 1)?line.substring(start):line.substring(start, i));
                  edgelabelTableName.setLength(0);
                  edgelabelTableName.append(column.getName());
                } else if (column.getCategory() == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null) {
                  int index = Integer.parseInt((i == n - 1)?line.substring(start):line.substring(start, i));
                  parent = nonterminals.get(index);
                  if (parent == null) {
                    if (index == 0) {
                      parent = phraseStructure.getPhraseStructureRoot()
                    } else {
                      parent = phraseStructure.addNonTerminalNode(index-START_ID_OF_NONTERMINALS+1);
                    }
                    nonterminals.put(index,parent);
                  }
                  Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                  syntaxGraph.addLabel(e, edgelabelTableName.toString(), edgelabelSymbol.toString());
                } else if (column.getCategory() == ColumnDescription.SECONDARY_EDGE_LABEL && child != null) {
                  if (secedgecounter % 2 == 0) {
                    edgelabelSymbol.setLength(0);
                    edgelabelSymbol.append((i == n - 1)?line.substring(start):line.substring(start, i));
                    secedgecounter++;
                  } else {
                    int index = Integer.parseInt((i == n - 1)?line.substring(start):line.substring(start, i));
                    if (index == 0) {
                      parent = phraseStructure.getPhraseStructureRoot();
                    } else if (index < START_ID_OF_NONTERMINALS) {
                      parent = phraseStructure.getTokenNode(index);
                    } else {
                      parent = nonterminals.get(index);
                      if (parent == null) {
                        parent = phraseStructure.addNonTerminalNode(index-START_ID_OF_NONTERMINALS+1);
                        nonterminals.put(index,parent);
                      }
                    }
                    Edge e = phraseStructure.addSecondaryEdge(parent, child);
                    e.addLabel(column.getSymbolTable(), edgelabelSymbol.toString());
                    secedgecounter++;
                  }
                }
                start = i + 1;
              }
            }
          } else { // Terminal
            Iterator<ColumnDescription> columns = dataFormatInstance.iterator();
            ColumnDescription column = null;
           
            currentTerminalSize++;
            child = syntaxGraph.addTokenNode(currentTerminalSize);
            char[] lineChars = line.toCharArray();
            int start = 0;
            int secedgecounter = 0;
            for (int i = 0, n = lineChars.length; i < n; i++) {
              if (lineChars[i] == '\t' && start == i) {
                start++;
              } else if (lineChars[i] == '\t' || i == n - 1) {
                if (columns.hasNext()) {
                  column = columns.next();
                }
                if (column.getCategory() == ColumnDescription.INPUT && child != null) {
                  syntaxGraph.addLabel(child, column.getName(), (i == n - 1)?line.substring(start):line.substring(start, i));
                } else if (column.getCategory() == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL && child != null) { // && column.getName().equals("EDGELABEL")) {
                  edgelabelSymbol.setLength(0);
                  edgelabelSymbol.append((i == n - 1)?line.substring(start):line.substring(start, i));
                  edgelabelTableName.setLength(0);
                  edgelabelTableName.append(column.getName());
                } else if (column.getCategory() == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null) {
                  int index = Integer.parseInt((i == n - 1)?line.substring(start):line.substring(start, i));
                  parent = nonterminals.get(index);
                  if (parent == null) {
                    if (index == 0) {
                      parent = phraseStructure.getPhraseStructureRoot()
                    } else {
                      parent = phraseStructure.addNonTerminalNode(index-START_ID_OF_NONTERMINALS+1);
                    }
                    nonterminals.put(index,parent);
                  }

                  Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                  syntaxGraph.addLabel(e, edgelabelTableName.toString(), edgelabelSymbol.toString());
                } else if (column.getCategory() == ColumnDescription.SECONDARY_EDGE_LABEL && child != null) {
                  if (secedgecounter % 2 == 0) {
                    edgelabelSymbol.setLength(0);
                    edgelabelSymbol.append((i == n - 1)?line.substring(start):line.substring(start, i));
                    secedgecounter++;
                  } else {
                    int index = Integer.parseInt((i == n - 1)?line.substring(start):line.substring(start, i));
                    if (index == 0) {
                      parent = phraseStructure.getPhraseStructureRoot();
                    } else if (index < START_ID_OF_NONTERMINALS) {
                      parent = phraseStructure.getTokenNode(index);
                    } else {
                      parent = nonterminals.get(index);
                      if (parent == null) {
                        parent = phraseStructure.addNonTerminalNode(index-START_ID_OF_NONTERMINALS+1);
                        nonterminals.put(index,parent);
                      }
                    }
                    Edge e = phraseStructure.addSecondaryEdge(parent, child);
                    e.addLabel(column.getSymbolTable(), edgelabelSymbol.toString());
                    secedgecounter++;
                  }
                }
                start = i + 1;
              }
View Full Code Here

      throw new SyntaxGraphException("Could not initialize InputColumnFeature: the first argument is not a string. ");
    }
    if (!(arguments[1] instanceof AddressFunction)) {
      throw new SyntaxGraphException("Could not initialize InputColumnFeature: the second argument is not an address function. ");
    }
    ColumnDescription column = dataFormatInstance.getColumnDescriptionByName((String)arguments[0]);
    if (column == null) {
      throw new SyntaxGraphException("Could not initialize InputColumnFeature: the input column type '"+(String)arguments[0]+"' could not be found in the data format specification. ' ");
    }
    setColumn(column);
    setAddressFunction((AddressFunction)arguments[1]);
View Full Code Here

          if (i == 0) {
            terminalCounter++;
            node = syntaxGraph.addTokenNode(terminalCounter);
          }
          if (columns.hasNext()) {
            ColumnDescription column = columns.next();
            if (column.getCategory() == ColumnDescription.INPUT && node != null) {
              syntaxGraph.addLabel(node, column.getName(), input.toString());
            } else if (column.getCategory() == ColumnDescription.HEAD) {
              if (syntaxGraph instanceof DependencyStructure) {
                if (column.getCategory() != ColumnDescription.IGNORE && !input.toString().equals(IGNORE_COLUMN_SIGN)) {
//                if (column.getType() != ColumnDescription.IGNORE && !input.toString().equals(IGNORE_COLUMN_SIGN)) { // bugfix
                //if (!input.toString().equals(IGNORE_COLUMN_SIGN)) {
                  edge = ((DependencyStructure)syntaxGraph).addDependencyEdge(Integer.parseInt(input.toString()), terminalCounter);
                }
              }
              else {
                close();
                throw new DataFormatException("The input graph is not a dependency graph and therefore it is not possible to add dependncy edges. ");
              }
            } else if (column.getCategory() == ColumnDescription.DEPENDENCY_EDGE_LABEL && edge != null) {
              //if (column.getType() != ColumnDescription.IGNORE && !input.toString().equals(IGNORE_COLUMN_SIGN)) { // bugfix not working for everybody
                syntaxGraph.addLabel(edge, column.getName(), input.toString());
              //} // bugfix
            }
          }
          input.setLength(0);
          nNewLines = 0;
View Full Code Here

      throw new FeatureException("Could not initialize Merge3Feature: the third argument is not a feature. ");
    }
    setFirstFeature((FeatureFunction)arguments[0]);
    setSecondFeature((FeatureFunction)arguments[1]);
    setThirdFeature((FeatureFunction)arguments[2]);
    ColumnDescription firstColumn = (firstFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(firstFeature.getSymbolTable().getName()):null;
    ColumnDescription secondColumn = (secondFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(secondFeature.getSymbolTable().getName()):null;
    ColumnDescription thirdColumn =  (thirdFeature.getSymbolTable() != null)?dataFormatInstance.getColumnDescriptionByName(thirdFeature.getSymbolTable().getName()):null;
    if (firstFeature.getType() != secondFeature.getType() || firstFeature.getType() != thirdFeature.getType()) {
      throw new FeatureException("Could not initialize MergeFeature: the arguments are not of the same type.");
    }
    if (firstColumn != null || secondColumn != null || thirdColumn != null) {
      setColumn(dataFormatInstance.addInternalColumnDescription("MERGE3_"+firstFeature.getMapIdentifier()+"_"+secondFeature.getMapIdentifier()+"_"+thirdFeature.getMapIdentifier(),
View Full Code Here

    if (!(arguments[1] instanceof Integer)) {
      throw new FeatureException("Could not initialize PrefixFeature: the second argument is not a string. ");
    }
    setParentFeature((FeatureFunction)arguments[0]);
    setPrefixLength(((Integer)arguments[1]).intValue());
    ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.getSymbolTable().getName());
    if (parentColumn.getType() != ColumnDescription.STRING) {
      throw new FeatureException("Could not initialize PrefixFeature: the first argument must be a string. ");
    }
    setColumn(dataFormatInstance.addInternalColumnDescription("PREFIX_"+prefixLength+"_"+parentFeature.getSymbolTable().getName(), parentColumn));
    setSymbolTable(column.getSymbolTable());
//    setSymbolTable(tableHandler.addSymbolTable("PREFIX_"+prefixLength+"_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
View Full Code Here

      throw new SyntaxGraphException("Could not initialize OutputColumnFeature: the first argument is not a string. ");
    }
    if (!(arguments[1] instanceof AddressFunction)) {
      throw new SyntaxGraphException("Could not initialize OutputColumnFeature: the second argument is not an address function. ");
    }
    ColumnDescription column = dataFormatInstance.getColumnDescriptionByName((String)arguments[0]);
    if (column == null) {
      throw new SyntaxGraphException("Could not initialize OutputColumnFeature: the output column type '"+(String)arguments[0]+"' could not be found in the data format specification. ' ");
    }
    setColumn(column);
    setAddressFunction((AddressFunction)arguments[1]);
View Full Code Here

TOP

Related Classes of org.maltparserx.core.io.dataformat.ColumnDescription

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.