Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Direction getDefaultDirection(org.maltparser.core.syntaxgraph.node.NonTerminalNode nt) throws org.maltparser.core.exception.MaltChainedException
        public virtual Direction getDefaultDirection(NonTerminalNode nt)
        {
            HeadRule rule = null;

            if (nt.hasLabel(nonTerminalSymbolTable))
            {
                rule = this[nonTerminalSymbolTable.Name + ":" + nt.getLabelSymbol(nonTerminalSymbolTable)];
            }
            if (rule == null && nt.hasParentEdgeLabel(edgelabelSymbolTable))
            {
                rule = this[edgelabelSymbolTable.Name + ":" + nt.getParentEdgeLabelSymbol(edgelabelSymbolTable)];
            }

            if (rule != null)
            {
                return(rule.DefaultDirection);
            }
            return(Direction.LEFT);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.node.PhraseStructureNode getHeadChild(org.maltparser.core.syntaxgraph.node.NonTerminalNode nt) throws org.maltparser.core.exception.MaltChainedException
        public virtual PhraseStructureNode getHeadChild(NonTerminalNode nt)
        {
            HeadRule rule = null;

            if (nt.hasLabel(nonTerminalSymbolTable))
            {
                rule = this[nonTerminalSymbolTable.Name + ":" + nt.getLabelSymbol(nonTerminalSymbolTable)];
            }
            if (rule == null && nt.hasParentEdgeLabel(edgelabelSymbolTable))
            {
                rule = this[edgelabelSymbolTable.Name + ":" + nt.getParentEdgeLabelSymbol(edgelabelSymbolTable)];
            }

            if (rule != null)
            {
                return(rule.getHeadChild(nt));
            }
            return(null);
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeElement(org.maltparser.core.symbol.SymbolTableHandler symbolTables, org.maltparser.core.syntaxgraph.node.PhraseStructureNode element, int depth) throws org.maltparser.core.exception.MaltChainedException
        private void writeElement(SymbolTableHandler symbolTables, PhraseStructureNode element, int depth)
        {
            try
            {
                if (element is TokenNode)
                {
                    PhraseStructureNode t     = (PhraseStructureNode)element;
                    SymbolTable         table = null;
                    writer.Write("\n" + getIndentation(depth) + STARTING_BRACKET);
                    int i = 0;
                    foreach (string inputColumn in inputColumns.Keys)
                    {
                        if (i != 0)
                        {
                            writer.BaseStream.WriteByte(INPUT_SEPARATOR);
                        }
                        table = symbolTables.getSymbolTable(inputColumns[inputColumn].Name);
                        if (t.hasLabel(table))
                        {
                            writer.Write(encodeString(t.getLabelSymbol(table)));
                        }
                        if (i == 0)
                        {
                            foreach (string edgeLabelColumn in edgeLabelColumns.Keys)
                            {
                                table = symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelColumn].Name);
                                if (t.hasParentEdgeLabel(table) && !t.Parent.Root && !t.getParentEdgeLabelSymbol(table).Equals(EMPTY_EDGELABEL))
                                {
                                    writer.BaseStream.WriteByte(EDGELABEL_SEPARATOR);
                                    writer.Write(t.getParentEdgeLabelSymbol(table));
                                }
                            }
                        }
                        i++;
                    }
                    writer.BaseStream.WriteByte(CLOSING_BRACKET);
                }
                else
                {
                    NonTerminalNode nt = (NonTerminalNode)element;
                    writer.Write("\n" + getIndentation(depth) + STARTING_BRACKET);
                    SymbolTable table = null;
                    int         i     = 0;
                    foreach (string phraseLabelColumn in phraseLabelColumns.Keys)
                    {
                        if (i != 0)
                        {
                            writer.BaseStream.WriteByte(INPUT_SEPARATOR);
                        }
                        table = symbolTables.getSymbolTable(phraseLabelColumns[phraseLabelColumn].Name);
                        if (nt.hasLabel(table))
                        {
                            writer.BaseStream.WriteByte(nt.getLabelSymbol(table));
                        }
                        if (i == 0)
                        {
                            foreach (string edgeLabelColumn in edgeLabelColumns.Keys)
                            {
                                table = symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelColumn].Name);
                                if (nt.hasParentEdgeLabel(table) && !nt.Parent.Root && !nt.getParentEdgeLabelSymbol(table).Equals(EMPTY_EDGELABEL))
                                {
                                    writer.BaseStream.WriteByte(EDGELABEL_SEPARATOR);
                                    writer.Write(nt.getParentEdgeLabelSymbol(table));
                                }
                            }
                        }
                        i++;
                    }
                    foreach (PhraseStructureNode node in ((NonTerminalNode)element).Children)
                    {
                        writeElement(symbolTables, node, depth + 1);
                    }
                    writer.Write("\n" + getIndentation(depth) + CLOSING_BRACKET);
                }
            }
            catch (IOException e)
            {
                throw new DataFormatException("Could not write to the output file. ", e);
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeNonTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void writeNonTerminals(PhraseStructure phraseStructure)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.symbol.SymbolTableHandler symbolTables = phraseStructure.getSymbolTables();
            SymbolTableHandler symbolTables = phraseStructure.SymbolTables;

            foreach (int index in nonTerminalIndexMap.Keys)
            {
                //		for (int index : phraseStructure.getNonTerminalIndices()) {
                NonTerminalNode nonTerminal = (NonTerminalNode)phraseStructure.getNonTerminalNode(index);

                if (nonTerminal == null || nonTerminal.Root)
                {
                    return;
                }
                try
                {
                    writer.BaseStream.WriteByte('#');
                    //				writer.write(Integer.toString(index+START_ID_OF_NONTERMINALS-1));
                    writer.Write(Convert.ToString(nonTerminalIndexMap.get(index)));
                    writer.Write("\t\t\t--\t\t\t");
                    if (nonTerminal.hasLabel(symbolTables.getSymbolTable("CAT")))
                    {
                        writer.BaseStream.WriteByte(nonTerminal.getLabelSymbol(symbolTables.getSymbolTable("CAT")));
                    }
                    else
                    {
                        writer.Write("--");
                    }
                    writer.Write("\t--\t\t");
                    if (nonTerminal.hasParentEdgeLabel(symbolTables.getSymbolTable("LABEL")))
                    {
                        writer.Write(nonTerminal.getParentEdgeLabelSymbol(symbolTables.getSymbolTable("LABEL")));
                    }
                    else
                    {
                        writer.Write("--");
                    }
                    writer.BaseStream.WriteByte('\t');
                    if (nonTerminal.Parent == null || nonTerminal.Parent.Root)
                    {
                        writer.BaseStream.WriteByte('0');
                    }
                    else
                    {
                        //					writer.write(Integer.toString(nonTerminal.getParent().getIndex()+START_ID_OF_NONTERMINALS-1));
                        writer.Write(Convert.ToString(nonTerminalIndexMap.get(nonTerminal.Parent.Index)));
                    }
                    foreach (Edge.Edge e in nonTerminal.IncomingSecondaryEdges)
                    {
                        if (e.hasLabel(symbolTables.getSymbolTable("SECEDGELABEL")))
                        {
                            writer.BaseStream.WriteByte('\t');
                            writer.Write(e.getLabelSymbol(symbolTables.getSymbolTable("SECEDGELABEL")));
                            writer.BaseStream.WriteByte('\t');
                            if (e.Source is NonTerminalNode)
                            {
                                //							writer.write(Integer.toString(e.getSource().getIndex()+START_ID_OF_NONTERMINALS-1));
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(e.Source.Index)));
                            }
                            else
                            {
                                writer.Write(Convert.ToString(e.Source.Index));
                            }
                        }
                    }
                    writer.Write("\n");
                }
                catch (IOException e)
                {
                    throw new DataFormatException("The Negra writer is not able to write the non-terminals. ", e);
                }
            }
        }