Ejemplo n.º 1
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, Direction direction) throws org.maltparser.core.exception.MaltChainedException
        public virtual PhraseStructureNode getHeadChild(NonTerminalNode nt, Direction direction)
        {
            bool match = false;

            if (direction == Direction.LEFT)
            {
                foreach (PhraseStructureNode child in nt.Children)
                {
                    for (int j = 0; j < Count; j++)
                    {
                        match = matchHeadChild(child, this[j]);
                        if (match == true)
                        {
                            if (j + 1 >= Count)
                            {
                                return(child);
                            }
                            else if (this[j].RelationToPrevMember != RelationToPrevMember.CONJUNCTION)
                            {
                                return(child);
                            }
                        }
                    }
                }
            }
            else if (direction == Direction.RIGHT)
            {
                for (int i = nt.nChildren() - 1; i >= 0; i--)
                {
                    PhraseStructureNode child = nt.getChild(i);
                    for (int j = 0; j < Count; j++)
                    {
                        match = matchHeadChild(child, this[j]);
                        if (match == true)
                        {
                            if (j + 1 >= Count)
                            {
                                return(child);
                            }
                            else if (this[j].RelationToPrevMember != RelationToPrevMember.CONJUNCTION)
                            {
                                return(child);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeNonTerminal(org.maltparser.core.symbol.SymbolTableHandler symbolTables, org.maltparser.core.syntaxgraph.node.NonTerminalNode nt, String id) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeNonTerminal(SymbolTableHandler symbolTables, NonTerminalNode nt, string id)
        {
            try
            {
                writer.Write("          <nt");
                writer.Write(" id=\"");
                writer.Write(id);
                writer.Write("\" ");
                foreach (ColumnDescription column in dataFormatInstance.PhraseStructureNodeLabelColumnDescriptionSet)
                {
                    if (nt.hasLabel(symbolTables.getSymbolTable(column.Name)))
                    {
                        writer.Write(column.Name.ToLower());
                        writer.Write("=");
                        writer.Write("\"");
                        writer.Write(Util.xmlEscape(nt.getLabelSymbol(symbolTables.getSymbolTable(column.Name))));
                        writer.Write("\" ");
                    }
                }
                writer.Write(">\n");

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

                    foreach (ColumnDescription column in dataFormatInstance.PhraseStructureEdgeLabelColumnDescriptionSet)
                    {
                        if (child.hasParentEdgeLabel(symbolTables.getSymbolTable(column.Name)))
                        {
                            writer.Write(column.Name.ToLower());
                            writer.Write("=\"");
                            writer.Write(Util.xmlEscape(child.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name))));
                            writer.Write("\" ");
                        }
                    }
                    if (child is TokenNode)
                    {
                        if (!labeledTerminalID)
                        {
                            tmpID.Length = 0;
                            tmpID.Append(sentenceID);
                            tmpID.Append('_');
                            tmpID.Append(Convert.ToString(child.Index));
                            writer.Write(" idref=\"");
                            writer.Write(tmpID.ToString());
                            writer.Write("\"");
                        }
                        else
                        {
                            writer.Write(" idref=\"");
                            writer.Write(child.getLabelSymbol(symbolTables.getSymbolTable("ID")));
                            writer.Write("\"");
                        }
                    }
                    else
                    {
                        tmpID.Length = 0;
                        tmpID.Append(sentenceID);
                        tmpID.Append('_');
                        tmpID.Append(Convert.ToString(child.Index + START_ID_OF_NONTERMINALS - 1));
                        writer.Write(" idref=\"");
                        writer.Write(tmpID.ToString());
                        writer.Write("\"");
                    }
                    writer.Write(" />\n");
                }
                writer.Write("          </nt>\n");
            }
            catch (IOException e)
            {
                throw new DataFormatException("The TigerXML writer is not able to write. ", e);
            }
        }