Package org.maltparserx.core.syntaxgraph.node

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


    if (syntaxGraph == null || !(syntaxGraph instanceof PhraseStructure)) {
      return false;
    }
    syntaxGraph.clear();
    final PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;
    PhraseStructureNode parent = null;
    PhraseStructureNode child = null;
    currentHeaderTable = NegraTables.UNDEF;
    String line = null;
    syntaxGraph.clear();
    nonterminals.clear();
    try {
View Full Code Here


            start = i + 1;
          }
        }
      }
    } else {
      PhraseStructureNode nt;
      Edge e = null;
      if (parent == null) {
        nt = phraseStructure.getPhraseStructureRoot();
      } else {
        nt = phraseStructure.addNonTerminalNode(nonTerminalCounter);
        if (nt == null) {
          close();
          throw new MaltChainedException("Bracket Reader error: could not create a nonterminal node. ");
        }
        nonTerminalCounter++;

        e = phraseStructure.addPhraseStructureEdge(parent, nt);
      }
      Iterator<String> phraseLabelColumnsIterator = phraseLabelColumns.keySet().iterator();
      Iterator<String> edgeLabelsColumnsIterator = edgeLabelColumns.keySet().iterator();
      int newbegin = begin;
      int start = begin;
     
      for (int i = begin; i < index; i++) {
        if (input.charAt(i) == EDGELABEL_SEPARATOR || i == index - 1) {
          if (start == newbegin) {
            if (phraseLabelColumnsIterator.hasNext()) {
              nt.addLabel(phraseLabelColumns.get(phraseLabelColumnsIterator.next()).getSymbolTable(), (i == index - 1)?input.substring(start,index):input.substring(start, i));
            }
            start = i + 1;
          } else if (e != null) {
            if (edgeLabelsColumnsIterator.hasNext()) {
              e.addLabel(edgeLabelColumns.get(edgeLabelsColumnsIterator.next()).getSymbolTable(), (i == index - 1)?input.substring(start,index):input.substring(start, i));
View Full Code Here

    if (syntaxGraph == null || !(syntaxGraph instanceof PhraseStructure)) {
      return false;
    }
    syntaxGraph.clear();
    final PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;
    PhraseStructureNode parent = null;
    PhraseStructureNode child = null;
//    if (header == null) {
//      header = new TigerXMLHeader(syntaxGraph.getSymbolTables());
//    }

    try {
      while (true) {
        int event = reader.next();
        if (event == XMLStreamConstants.START_ELEMENT) {
          if (reader.getLocalName().length() == 0) {
            continue;
          }
          if (reader.getLocalName().charAt(0) == 'e') {
            // e -> edge, edgelabel
            if (reader.getLocalName().length() == 4) { //edge
              int childid = -1;
              int indexSep = reader.getAttributeValue(null, "idref").indexOf('_');
             
              try {
                if (indexSep != -1) {
                  childid = Integer.parseInt(reader.getAttributeValue(null, "idref").substring(indexSep+1));
                } else {
                  childid = Integer.parseInt(reader.getAttributeValue(null, "idref"));
                }
                if (childid == -1) {
                  throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '"+reader.getAttributeValue(null, "idref")+"' of the edge element. ");
                }
              } catch (NumberFormatException e) {
                throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '"+reader.getAttributeValue(null, "idref")+"' of the edge element. ");
              }

              if (childid < START_ID_OF_NONTERMINALS) {
                child = phraseStructure.getTokenNode(childid);
              } else {

                child = phraseStructure.getNonTerminalNode(childid-START_ID_OF_NONTERMINALS+1);
              }

              Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
              SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureEdgeLabelSymbolTables();
              for (String name : inputTables.keySet()) {
                e.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
              }
            } else if (reader.getLocalName().equals("edgelabel")) { // edgelabel
//              domain = Domain.EL;
            }
          } else if (reader.getLocalName().charAt(0) == 'n') {
            // n -> nt, nonterminals, name
            if (reader.getLocalName().length() == 2) { // nt
              final String id = reader.getAttributeValue(null, "id");
              if (graphRootID.length() == id.length() && graphRootID.toString().equals(id)) {
                parent = phraseStructure.getPhraseStructureRoot();
              } else {
                int index = id.indexOf('_');
                if (index != -1) {
                  parent = phraseStructure.addNonTerminalNode(Integer.parseInt(id.substring(index+1))-START_ID_OF_NONTERMINALS+1);
                }
              }
              SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureNodeLabelSymbolTables();
              for (String name : inputTables.keySet()) {
                parent.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
              }
            } else if (reader.getLocalName().equals("name")) { // name
//              elementContent.setLength(0);
//              collectChar = true;
            }
          } else if (reader.getLocalName().charAt(0) == 't') {
            // t -> t, terminals
            if (reader.getLocalName().length() == 1) { // t
              SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getInputSymbolTables();
              child = syntaxGraph.addTokenNode();
              for (String name : inputTables.keySet()) {
                child.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
              }
            }
          } else if (reader.getLocalName().charAt(0) == 's') {
            // s -> subcorpus, secedge, s, secedgelabel
            if (reader.getLocalName().length() == 1) { // s
View Full Code Here

  }
 
  private void writeElement(PhraseStructureNode element) throws MaltChainedException {
    try {
      if (element instanceof TokenNode) {
        PhraseStructureNode t = (PhraseStructureNode)element;
        SymbolTable table = null;
        writer.write(STARTING_BRACKET);
        int i = 0;
        for (String inputColumn : inputColumns.keySet()) {
          if (i != 0) {
            writer.write(INPUT_SEPARATOR);
          }
          table = inputColumns.get(inputColumn).getSymbolTable();
          if (t.hasLabel(table)) {
            writer.write(t.getLabelSymbol(table));
          }
          if (i == 0) {
            for (String edgeLabelColumn : edgeLabelColumns.keySet()) {
              table = edgeLabelColumns.get(edgeLabelColumn).getSymbolTable();
              if (t.hasParentEdgeLabel(table) && !t.getParent().isRoot() && !t.getParentEdgeLabelSymbol(table).equals(EMPTY_EDGELABEL)) {
                writer.write(EDGELABEL_SEPARATOR);
                writer.write(t.getParentEdgeLabelSymbol(table));
              }
            }
          }
          i++;
        }
View Full Code Here

  }
 
  private void writeElement(PhraseStructureNode element, int depth) throws MaltChainedException {
    try {
      if (element instanceof TokenNode) {
        PhraseStructureNode t = (PhraseStructureNode)element;
        SymbolTable table = null;
        writer.write("\n" + getIndentation(depth) + STARTING_BRACKET);
        int i = 0;
        for (String inputColumn : inputColumns.keySet()) {
          if (i != 0) {
            writer.write(INPUT_SEPARATOR);
          }
          table = inputColumns.get(inputColumn).getSymbolTable();
          if (t.hasLabel(table)) {
            writer.write(encodeString(t.getLabelSymbol(table)));
          }
          if (i == 0) {
            for (String edgeLabelColumn : edgeLabelColumns.keySet()) {
              table = edgeLabelColumns.get(edgeLabelColumn).getSymbolTable();
              if (t.hasParentEdgeLabel(table) && !t.getParent().isRoot() && !t.getParentEdgeLabelSymbol(table).equals(EMPTY_EDGELABEL)) {
                writer.write(EDGELABEL_SEPARATOR);
                writer.write(t.getParentEdgeLabelSymbol(table));
              }
            }
          }
          i++;
        }
View Full Code Here

      throw new HeadRuleException("The specification of the priority list is not correct '"+listSpec+"'. ");
    }
  }
 
  public PhraseStructureNode getHeadChild(NonTerminalNode nt) throws MaltChainedException {
    PhraseStructureNode headChild = null;
    for (int i = 0, n = size(); i < n; i++) {
      headChild = get(i).getHeadChild(nt, direction);
      if (headChild != null) {
        break;
      }
View Full Code Here

    }
  }
 
  private void setRootID(PhraseStructure phraseStructure) throws MaltChainedException {
    useVROOT = false;
    PhraseStructureNode root = phraseStructure.getPhraseStructureRoot();
    for (ColumnDescription column : dataFormatInstance.getPhraseStructureNodeLabelColumnDescriptionSet()) {
      if (root.hasLabel(column.getSymbolTable()) && root.getLabelSymbol(column.getSymbolTable()).equals(VROOT_SYMBOL)) {
        useVROOT = true;
        break;
      }
    }
    if (useVROOT) {
      rootID.setLength(0);
      rootID.append(sentenceID);
      rootID.append('_');
      rootID.append(VROOT_SYMBOL);
    } else if (phraseStructure.nTokenNode() == 1 && phraseStructure.nNonTerminals() == 0 && !root.isLabeled()) {
      rootID.setLength(0);
      rootID.append(sentenceID);
      rootID.append("_1");
    } else {
      rootID.setLength(0);
View Full Code Here

 
  private void writeTerminals(PhraseStructure phraseStructure) throws MaltChainedException {
    try {
      writer.write("        <terminals>\n");
      for (int index : phraseStructure.getTokenIndices()) {
        final PhraseStructureNode t = phraseStructure.getTokenNode(index);
        writer.write("          <t ");
        if (!labeledTerminalID) {
          tmpID.setLength(0);
          tmpID.append(sentenceID);
          tmpID.append('_');
          tmpID.append(Integer.toString(t.getIndex()));
          writer.write("id=\"");writer.write(tmpID.toString());writer.write("\" ");
        }
       
        for (ColumnDescription column : dataFormatInstance.getInputColumnDescriptionSet()) {
          writer.write(column.getName().toLowerCase());
          writer.write("=\"");
          writer.write(Util.xmlEscape(t.getLabelSymbol(column.getSymbolTable())));
          writer.write("\" ")
        }
        writer.write("/>\n");
      }
      writer.write("        </terminals>\n");
View Full Code Here

        }
      }
      writer.write(">\n");
     
      for (int i = 0, n = nt.nChildren(); i < n; i++) {
        PhraseStructureNode child = nt.getChild(i);
        writer.write("            <edge ");

        for (ColumnDescription column : dataFormatInstance.getPhraseStructureEdgeLabelColumnDescriptionSet()) {
          if (child.hasParentEdgeLabel(column.getSymbolTable())) {
            writer.write(column.getName().toLowerCase());
            writer.write("=\"");
            writer.write(Util.xmlEscape(child.getParentEdgeLabelSymbol(column.getSymbolTable())));
            writer.write("\" ");
          }
        }
        if (child instanceof TokenNode) {
          if (!labeledTerminalID) {
            tmpID.setLength(0);
            tmpID.append(sentenceID);
            tmpID.append('_');
            tmpID.append(Integer.toString(child.getIndex()));
            writer.write(" idref=\"");writer.write(tmpID.toString());writer.write("\"");
          } else {
            writer.write(" idref=\"");writer.write(child.getLabelSymbol(dataFormatInstance.getInputSymbolTables().get("ID")));writer.write("\"");
          }
         
        } else {
          tmpID.setLength(0);
          tmpID.append(sentenceID);
          tmpID.append('_');
          tmpID.append(Integer.toString(child.getIndex()+START_ID_OF_NONTERMINALS-1));
          writer.write(" idref=\"");writer.write(tmpID.toString());writer.write("\"");
        }
        writer.write(" />\n");
      }
      writer.write("          </nt>\n");
View Full Code Here

      }
    }
  }

  public PhraseStructureNode getHeadChild(NonTerminalNode nt) throws MaltChainedException {
    PhraseStructureNode headChild = null;
    for (int i = 0; i < size(); i++) {
      headChild = get(i).getHeadChild(nt);
      if (headChild != null) {
        break;
      }
View Full Code Here

TOP

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

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.