Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void resetTokens(String[] inputTokens, String defaultRootLabel, boolean addEdges) throws org.maltparser.core.exception.MaltChainedException
        public void resetTokens(string[] inputTokens, string defaultRootLabel, bool addEdges)
        {
            nodes.Clear();
            comments.Clear();
            symbolTables.cleanUp();
            // Add nodes
            nodes.Add(new LWNode(this, 0));             // ROOT
            for (int i = 0; i < inputTokens.Length; i++)
            {
                nodes.Add(new LWNode(this, i + 1));
            }

            for (int i = 0; i < inputTokens.Length; i++)
            {
                nodes[i + 1].addColumnLabels(inputTokens[i].Split(TAB_SIGN, true), addEdges);
            }
            // Check graph
            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].HeadIndex >= nodes.Count)
                {
                    throw new LWGraphException("Not allowed to add a head node that doesn't exists");
                }
            }

            for (int i = 0; i < dataFormat.NumberOfColumns(); i++)
            {
                ColumnDescription column = dataFormat.GetColumnDescription(i);
                if (!column.Internal && column.Category == ColumnDescription.DependencyEdgeLabel)
                {
                    rootLabels.setDefaultRootLabel(symbolTables.getSymbolTable(column.Name), defaultRootLabel);
                }
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(Object[] arguments) throws org.maltparser.core.exception.MaltChainedException
        public void initialize(object[] arguments)
        {
            if (arguments.Length != 2)
            {
                throw new FeatureException("Could not initialize PrefixFeature: number of arguments are not correct. ");
            }
            if (!(arguments[0] is FeatureFunction))
            {
                throw new FeatureException("Could not initialize PrefixFeature: the first argument is not a feature. ");
            }
            if (!(arguments[1] is int?))
            {
                throw new FeatureException("Could not initialize PrefixFeature: the second argument is not a string. ");
            }
            ParentFeature = (FeatureFunction)arguments[0];
            PrefixLength  = ((int?)arguments[1]).Value;
            ColumnDescription parentColumn = dataFormatInstance.getColumnDescriptionByName(parentFeature.SymbolTable.Name);

            if (parentColumn.Type != ColumnDescription.STRING)
            {
                throw new FeatureException("Could not initialize PrefixFeature: the first argument must be a string. ");
            }
            Column      = dataFormatInstance.addInternalColumnDescription(tableHandler, "PREFIX_" + prefixLength + "_" + parentFeature.SymbolTable.Name, parentColumn);
            SymbolTable = tableHandler.getSymbolTable(column.Name);
            //		setSymbolTable(tableHandler.addSymbolTable("PREFIX_"+prefixLength+"_"+parentFeature.getSymbolTable().getName(), parentFeature.getSymbolTable()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a propagation object based on the propagation specification
        /// </summary>
        /// <param name="spec"> a propagation specification </param>
        /// <param name="dataFormatInstance"> a data format instance </param>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Propagation(org.maltparser.core.propagation.spec.PropagationSpec spec, org.maltparser.core.io.dataformat.DataFormatInstance dataFormatInstance, org.maltparser.core.symbol.SymbolTableHandler tableHandler) throws org.maltparser.core.exception.MaltChainedException
        public Propagation(PropagationSpec spec, DataFormatInstance dataFormatInstance, SymbolTableHandler tableHandler)
        {
            ColumnDescription fromColumn = dataFormatInstance.getColumnDescriptionByName(spec.From);

            if (fromColumn == null)
            {
                throw new PropagationException("The symbol table '" + spec.From + " does not exists.");
            }
            fromTable = tableHandler.getSymbolTable(spec.From);

            ColumnDescription toColumn = dataFormatInstance.getColumnDescriptionByName(spec.To);

            if (toColumn == null)
            {
                toColumn = dataFormatInstance.addInternalColumnDescription(tableHandler, spec.To, fromColumn);
                toTable  = tableHandler.getSymbolTable(spec.To);
            }


            forSet = new SortedSet <string>();
            if (!ReferenceEquals(spec.For, null) && spec.For.Length > 0)
            {
                string[] items = spec.For.Split("\\|", true);

                foreach (string item in items)
                {
                    forSet.Add(item);
                }
            }

            overSet = new SortedSet <string>();
            if (!ReferenceEquals(spec.Over, null) && spec.Over.Length > 0)
            {
                string[] items = spec.Over.Split("\\|", true);

                foreach (string item in items)
                {
                    overSet.Add(item);
                }
            }

            //		ColumnDescription deprelColumn = dataFormatInstance.getColumnDescriptionByName("DEPREL");
            deprelTable     = tableHandler.getSymbolTable("DEPREL");
            symbolSeparator = Pattern.compile("\\|");
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static String[] toStringArray(org.maltparser.core.syntaxgraph.DependencyGraph graph, org.maltparser.core.io.dataformat.DataFormatInstance dataFormatInstance, org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        public static string[] toStringArray(DependencyGraph graph, DataFormatInstance dataFormatInstance, SymbolTableHandler symbolTables)
        {
            string[]      tokens = new string[graph.NTokenNode()];
            StringBuilder sb     = new StringBuilder();
            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();

            foreach (int?index in graph.TokenIndices)
            {
                sb.Length = 0;
                if (index <= tokens.Length)
                {
                    ColumnDescription column = null;
                    TokenNode         node   = graph.GetTokenNode(index.Value);
                    while (columns.MoveNext())
                    {
                        column = columns.Current;
                        if (column.Category == ColumnDescription.INPUT)
                        {
                            if (!column.Name.Equals("ID"))
                            {
                                if (node.hasLabel(symbolTables.getSymbolTable(column.Name)) && node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)).Length > 0)
                                {
                                    sb.Append(node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                                }
                                else
                                {
                                    sb.Append('_');
                                }
                            }
                            else
                            {
                                sb.Append(index.ToString());
                            }
                            sb.Append('\t');
                        }
                    }
                    sb.Length         = sb.Length - 1;
                    tokens[index - 1] = sb.ToString();
                    columns           = dataFormatInstance.GetEnumerator();
                }
            }
            return(tokens);
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void createInputSymbolTables(org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void createInputSymbolTables(SymbolTableHandler symbolTables)
        {
            inputSymbolTables = new SortedDictionary <string, SymbolTable>();
            foreach (ColumnDescription column in columnDescriptions)
            {
                if (column.Category == ColumnDescription.INPUT)
                {
                    inputSymbolTables[column.Name] = symbolTables.getSymbolTable(column.Name);
                }
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void createPhraseStructureNodeLabelSymbolTables(org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void createPhraseStructureNodeLabelSymbolTables(SymbolTableHandler symbolTables)
        {
            phraseStructureNodeLabelSymbolTables = new SortedDictionary <string, SymbolTable>();
            foreach (ColumnDescription column in columnDescriptions)
            {
                if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL)
                {
                    phraseStructureNodeLabelSymbolTables[column.Name] = symbolTables.getSymbolTable(column.Name);
                }
            }
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void createSecondaryEdgeLabelSymbolTables(org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void createSecondaryEdgeLabelSymbolTables(SymbolTableHandler symbolTables)
        {
            secondaryEdgeLabelSymbolTables = new SortedDictionary <string, SymbolTable>();
            foreach (ColumnDescription column in columnDescriptions)
            {
                if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL)
                {
                    secondaryEdgeLabelSymbolTables[column.Name] = symbolTables.getSymbolTable(column.Name);
                }
            }
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void createDependencyEdgeLabelSymbolTables(org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void createDependencyEdgeLabelSymbolTables(SymbolTableHandler symbolTables)
        {
            dependencyEdgeLabelSymbolTables = new SortedDictionary <string, SymbolTable>();
            foreach (ColumnDescription column in columnDescriptions)
            {
                if (column.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL)
                {
                    dependencyEdgeLabelSymbolTables[column.Name] = symbolTables.getSymbolTable(column.Name);
                }
            }
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void update() throws org.maltparser.core.exception.MaltChainedException
        public void update()
        {
            // Retrieve the address value
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.feature.value.AddressValue arg1 = addressFunction1.getAddressValue();
            AddressValue arg1 = addressFunction1.AddressValue;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.feature.value.AddressValue arg2 = addressFunction2.getAddressValue();
            AddressValue arg2 = addressFunction2.AddressValue;

            if (arg1.Address != null && arg1.AddressClass == typeof(DependencyNode) && arg2.Address != null && arg2.AddressClass == typeof(DependencyNode))
            {
                DependencyNode node1 = (DependencyNode)arg1.Address;
                DependencyNode node2 = (DependencyNode)arg2.Address;
                try
                {
                    SymbolTable symbolTable = tableHandler.getSymbolTable(column.Name);
                    int         head1       = int.Parse(node1.getLabelSymbol(symbolTable));
                    int         head2       = int.Parse(node2.getLabelSymbol(symbolTable));
                    if (!node1.Root && head1 == node2.Index)
                    {
                        featureValue.IndexCode = table.getSymbolStringToCode("LEFT");
                        featureValue.Symbol    = "LEFT";
                        featureValue.NullValue = false;
                    }
                    else if (!node2.Root && head2 == node1.Index)
                    {
                        featureValue.IndexCode = table.getSymbolStringToCode("RIGHT");
                        featureValue.Symbol    = "RIGHT";
                        featureValue.NullValue = false;
                    }
                    else
                    {
                        featureValue.IndexCode = table.getNullValueCode(NullValueId.NO_NODE);
                        featureValue.Symbol    = table.getNullValueSymbol(NullValueId.NO_NODE);
                        featureValue.NullValue = true;
                    }
                }
                catch (FormatException e)
                {
                    throw new FeatureException("The index of the feature must be an integer value. ", e);
                }
            }
            else
            {
                featureValue.IndexCode = table.getNullValueCode(NullValueId.NO_NODE);
                featureValue.Symbol    = table.getNullValueSymbol(NullValueId.NO_NODE);
                featureValue.NullValue = true;
            }
            featureValue.Value = 1;
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void update() throws org.maltparser.core.exception.MaltChainedException
        public void update()
        {
            AddressValue a = addressFunction.AddressValue;

            if (a.Address != null && a.AddressClass == typeof(DependencyNode))
            {
                DependencyNode node = (DependencyNode)a.Address;
                try
                {
                    int index = int.Parse(node.getLabelSymbol(tableHandler.getSymbolTable(column.Name)));
                    if (node.Root)
                    {
                        featureValue.IndexCode = table.getNullValueCode(NullValueId.ROOT_NODE);
                        featureValue.Symbol    = table.getNullValueSymbol(NullValueId.ROOT_NODE);
                        featureValue.NullValue = true;
                    }
                    else if (index == 0)
                    {
                        featureValue.IndexCode = table.getSymbolStringToCode("ROOT");
                        featureValue.Symbol    = "ROOT";
                        featureValue.NullValue = false;
                    }
                    else if (index < node.Index)
                    {
                        featureValue.IndexCode = table.getSymbolStringToCode("LEFT");
                        featureValue.Symbol    = "LEFT";
                        featureValue.NullValue = false;
                    }
                    else if (index > node.Index)
                    {
                        featureValue.IndexCode = table.getSymbolStringToCode("RIGHT");
                        featureValue.Symbol    = "RIGHT";
                        featureValue.NullValue = false;
                    }
                }
                catch (FormatException e)
                {
                    throw new FeatureException("The index of the feature must be an integer value. ", e);
                }
            }
            else
            {
                featureValue.IndexCode = table.getNullValueCode(NullValueId.NO_NODE);
                featureValue.Symbol    = table.getNullValueSymbol(NullValueId.NO_NODE);
                featureValue.NullValue = true;
            }
            featureValue.Value = 1;
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(Object[] arguments) throws org.maltparser.core.exception.MaltChainedException
        public override void initialize(object[] arguments)
        {
            if (arguments.Length != 2)
            {
                throw new SyntaxGraphException("Could not initialize InputColumnFeature: number of arguments are not correct. ");
            }
            if (!(arguments[0] is string))
            {
                throw new SyntaxGraphException("Could not initialize InputColumnFeature: the first argument is not a string. ");
            }
            if (!(arguments[1] is 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. ' ");
            }
            Column          = column;
            SymbolTable     = tableHandler.getSymbolTable(column.Name);
            AddressFunction = (AddressFunction)arguments[1];
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void extract(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure, int begin, int end, org.maltparser.core.syntaxgraph.node.PhraseStructureNode parent) throws org.maltparser.core.exception.MaltChainedException
        private void extract(PhraseStructure phraseStructure, int begin, int end, PhraseStructureNode parent)
        {
            SymbolTableHandler symbolTables = phraseStructure.SymbolTables;
            int index = -1;

            for (int i = begin; i < end; i++)
            {
                if (input[i] == STARTING_BRACKET && (i == begin || input[i - 1] != '\\'))
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                TokenNode t = phraseStructure.AddTokenNode(terminalCounter);
                if (t == null)
                {
                    close();
                    throw new MaltChainedException("Bracket Reader error: could not create a terminal node. ");
                }

                terminalCounter++;
                Edge.Edge e = null;

                if (parent != null)
                {
                    e = phraseStructure.addPhraseStructureEdge(parent, (PhraseStructureNode)t);
                }
                else
                {
                    close();
                    throw new MaltChainedException("Bracket Reader error: could not find the parent node. ");
                }

                int start = begin;

                IEnumerator <string> inputColumnsIterator      = inputColumns.Keys.GetEnumerator();
                IEnumerator <string> edgeLabelsColumnsIterator = edgeLabelColumns.Keys.GetEnumerator();
                bool noneNode   = false;
                bool edgeLabels = false;
                for (int i = begin; i < end; i++)
                {
                    if (input[i] == EDGELABEL_SEPARATOR || (input[i] == INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\')) || i == end - 1)
                    {
                        if (i == begin && input[i] == EDGELABEL_SEPARATOR)
                        {
                            noneNode = true;
                        }
                        else if (start == begin)
                        {
                            if ((noneNode && input[i] != EDGELABEL_SEPARATOR) || !noneNode)
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                if (inputColumnsIterator.hasNext())
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    t.addLabel(symbolTables.getSymbolTable(inputColumns[inputColumnsIterator.next()].Name), decodeString((i == end - 1)?input.substring(start, end - start):input.substring(start, i - start)));
                                }
                                start = i + 1;
                                if (input[i] == EDGELABEL_SEPARATOR)
                                {
                                    edgeLabels = true;
                                }
                            }
                        }
                        else if (edgeLabels && e != null)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (edgeLabelsColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                e.addLabel(symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelsColumnsIterator.next()].Name), (i == end - 1)?input.substring(start, end - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                            if (input[i] == INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\'))
                            {
                                edgeLabels = false;
                            }
                        }
                        else if (input[i] == EDGELABEL_SEPARATOR && i != end - 1 && (input[i + 1] != INPUT_SEPARATOR && (i == begin || input[i - 1] != '\\')))
                        {
                        }
                        else
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (inputColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                t.addLabel(symbolTables.getSymbolTable(inputColumns[inputColumnsIterator.next()].Name), (i == end - 1)?input.substring(start, end - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                    }
                }
            }
            else
            {
                PhraseStructureNode nt;
                Edge.Edge           e = null;
                if (parent == null)
                {
                    nt = phraseStructure.PhraseStructureRoot;
                }
                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);
                }
                IEnumerator <string> phraseLabelColumnsIterator = phraseLabelColumns.Keys.GetEnumerator();
                IEnumerator <string> edgeLabelsColumnsIterator  = edgeLabelColumns.Keys.GetEnumerator();
                int newbegin = begin;
                int start    = begin;

                for (int i = begin; i < index; i++)
                {
                    if (input[i] == EDGELABEL_SEPARATOR || i == index - 1)
                    {
                        if (start == newbegin)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (phraseLabelColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                nt.addLabel(symbolTables.getSymbolTable(phraseLabelColumns[phraseLabelColumnsIterator.next()].Name), (i == index - 1)?input.substring(start, index - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                        else if (e != null)
                        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            if (edgeLabelsColumnsIterator.hasNext())
                            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                e.addLabel(symbolTables.getSymbolTable(edgeLabelColumns[edgeLabelsColumnsIterator.next()].Name), (i == index - 1)?input.substring(start, index - start):input.substring(start, i - start));
                            }
                            start = i + 1;
                        }
                    }
                    else if (input[i] == BLANK)
                    {
                        start++;
                        newbegin++;
                    }
                }

                bracketing(phraseStructure, index, end, nt);
            }
        }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
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);
                }
            }
        }
Ejemplo n.º 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeTerminals(org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure) throws org.maltparser.core.exception.MaltChainedException
        private void writeTerminals(PhraseStructure phraseStructure)
        {
            try
            {
//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 phraseStructure.TokenIndices)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.PhraseStructureNode terminal = phraseStructure.getTokenNode(index);
                    PhraseStructureNode terminal = phraseStructure.GetTokenNode(index);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Iterator<org.maltparser.core.io.dataformat.ColumnDescription> columns = dataFormatInstance.iterator();
                    IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                    ColumnDescription column = null;
                    int ti = 1;
                    while (columns.MoveNext())
                    {
                        column = columns.Current;
                        if (column.Category == ColumnDescription.INPUT)
                        {
                            SymbolTable table = symbolTables.getSymbolTable(column.Name);
                            writer.Write(terminal.getLabelSymbol(table));
                            int nTabs = 1;
                            if (ti == 1 || ti == 2)
                            {
                                nTabs = 3 - (terminal.getLabelSymbol(table).Length / 8);
                            }
                            else if (ti == 3)
                            {
                                nTabs = 1;
                            }
                            else if (ti == 4)
                            {
                                nTabs = 2 - (terminal.getLabelSymbol(table).Length / 8);
                            }
                            if (nTabs < 1)
                            {
                                nTabs = 1;
                            }
                            for (int j = 0; j < nTabs; j++)
                            {
                                writer.BaseStream.WriteByte('\t');
                            }
                            ti++;
                        }
                        else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL)
                        {
                            SymbolTable table = symbolTables.getSymbolTable(column.Name);
                            if (terminal.Parent != null && terminal.hasParentEdgeLabel(table))
                            {
                                writer.Write(terminal.getParentEdgeLabelSymbol(table));
                                writer.BaseStream.WriteByte('\t');
                            }
                            else
                            {
                                writer.Write("--\t");
                            }
                        }
                        else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL)
                        {
                            if (terminal.Parent == null || terminal.Parent == phraseStructure.PhraseStructureRoot)
                            {
                                writer.BaseStream.WriteByte('0');
                            }
                            else
                            {
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(terminal.Parent.Index)));
                                //							writer.write(Integer.toString(terminal.getParent().getIndex()+START_ID_OF_NONTERMINALS-1));
                            }
                        }
                    }
                    SymbolTable table = symbolTables.getSymbolTable(column.Name);
                    foreach (Edge.Edge e in terminal.IncomingSecondaryEdges)
                    {
                        if (e.hasLabel(table))
                        {
                            writer.BaseStream.WriteByte('\t');
                            writer.Write(e.getLabelSymbol(table));
                            writer.BaseStream.WriteByte('\t');
                            if (e.Source is NonTerminalNode)
                            {
                                writer.Write(Convert.ToString(nonTerminalIndexMap.get(e.Source.Index)));
                                //							writer.write(Integer.toString(e.getSource().getIndex()+START_ID_OF_NONTERMINALS-1));
                            }
                            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. ", e);
            }
        }
Ejemplo n.º 16
0
        //	private void updateDependenyLabels(MappablePhraseStructureGraph graph, PhraseStructureNode top) throws MaltChainedException {
        //		if (top == null) {
        //			return;
        //		}
        //		DependencyNode head = null;
        //		DependencyNode dependent = null;
        //		if (top instanceof NonTerminalNode) {
        //			for (PhraseStructureNode node : ((NonTerminalNode)top).getChildren()) {
        //				if (node instanceof NonTerminalNode) {
        //					updateDependenyLabels(graph, node);
        //				} else {
        //					head = ((NonTerminalNode)top).getLexicalHead(headRules);
        //					dependent = (DependencyNode)node;
        //					if (head != null && dependent != null && head != dependent) {
        //						lockUpdate = true;
        //						if (dependent.hasHead()) {
        //							Edge e = dependent.getHeadEdge();
        //							labelDependencyEdge(graph, e, node);
        //						}
        //						lockUpdate = false;
        //					}
        //				}
        //			}
        //		}
        //
        //		dependent = null;
        //		if (top instanceof NonTerminalNode) {
        //			dependent = ((NonTerminalNode)top).getLexicalHead(headRules);
        //		}
        //
        //		if (dependent != null) {
        //			lockUpdate = true;
        //			if (dependent.hasHead()) {
        //				Edge e = dependent.getHeadEdge();
        //				labelDependencyEdge(graph, e, top);
        //			}
        //			lockUpdate = false;
        //		}
        //	}

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void labelDependencyEdge(org.maltparser.core.syntaxgraph.MappablePhraseStructureGraph graph, org.maltparser.core.syntaxgraph.edge.Edge e, org.maltparser.core.syntaxgraph.node.PhraseStructureNode top) throws org.maltparser.core.exception.MaltChainedException
        private void labelDependencyEdge(MappablePhraseStructureGraph graph, Edge.Edge e, PhraseStructureNode top)
        {
            if (e == null)
            {
                return;
            }
            SymbolTableHandler symbolTables = graph.SymbolTables;

            deprel.Length  = 0;
            phrase.Length  = 0;
            headrel.Length = 0;

            e.removeLabel(symbolTables.getSymbolTable(DEPREL));
            e.removeLabel(symbolTables.getSymbolTable(HEADREL));
            e.removeLabel(symbolTables.getSymbolTable(PHRASE));
            e.removeLabel(symbolTables.getSymbolTable(ATTACH));

            int i = 0;
            SortedDictionary <string, SymbolTable> edgeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureEdgeLabelSymbolTables(symbolTableHandler);
            SortedDictionary <string, SymbolTable> nodeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureNodeLabelSymbolTables(symbolTableHandler);

            if (!top.Root)
            {
                foreach (string name in edgeLabelSymbolTables.Keys)
                {
                    if (top.hasParentEdgeLabel(symbolTables.getSymbolTable(name)))
                    {
                        deprel.Append(top.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        deprel.Append(EMPTY_LABEL);
                    }
                    i++;
                    if (i < edgeLabelSymbolTables.Count)
                    {
                        deprel.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                if (deprel.Length != 0)
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), deprel.ToString());
                }
            }
            else
            {
                string deprelDefaultRootLabel = graph.GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(DEPREL));
                if (!ReferenceEquals(deprelDefaultRootLabel, null))
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), deprelDefaultRootLabel);
                }
                else
                {
                    e.addLabel(symbolTables.getSymbolTable(DEPREL), EMPTY_LABEL);
                }
            }
            PhraseStructureNode tmp = (PhraseStructureNode)e.Target;

            while (tmp != top && tmp.Parent != null)
            {             // && !tmp.getParent().isRoot()) {
                i = 0;
                foreach (string name in edgeLabelSymbolTables.Keys)
                {
                    if (tmp.hasParentEdgeLabel(symbolTables.getSymbolTable(name)))
                    {
                        headrel.Append(tmp.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        headrel.Append(EMPTY_LABEL);
                    }
                    i++;
                    if (i < edgeLabelSymbolTables.Count)
                    {
                        headrel.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                i = 0;
                headrel.Append(SPINE_ELEMENT_SEPARATOR);
                foreach (string name in nodeLabelSymbolTables.Keys)
                {
                    if (tmp.Parent.hasLabel(symbolTables.getSymbolTable(name)))
                    {
                        phrase.Append(tmp.Parent.getLabelSymbol(symbolTables.getSymbolTable(name)));
                    }
                    else
                    {
                        if (tmp.Parent.Root)
                        {
                            string deprelDefaultRootLabel = graph.GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(PHRASE));
                            if (!ReferenceEquals(deprelDefaultRootLabel, null))
                            {
                                phrase.Append(deprelDefaultRootLabel);
                            }
                            else
                            {
                                phrase.Append(EMPTY_LABEL);
                            }
                        }
                        else
                        {
                            phrase.Append(EMPTY_LABEL);
                        }
                    }
                    i++;
                    if (i < nodeLabelSymbolTables.Count)
                    {
                        phrase.Append(LABEL_ELEMENT_SEPARATOR);
                    }
                }
                phrase.Append(SPINE_ELEMENT_SEPARATOR);
                tmp = tmp.Parent;
            }
            if (phrase.Length == 0)
            {
                headrel.Append(EMPTY_SPINE);
                phrase.Append(EMPTY_SPINE);
            }
            else
            {
                headrel.Length = headrel.Length - 1;
                phrase.Length  = phrase.Length - 1;
            }
            e.addLabel(symbolTables.getSymbolTable(HEADREL), headrel.ToString());
            e.addLabel(symbolTables.getSymbolTable(PHRASE), phrase.ToString());
            int a = 0;

            tmp = (PhraseStructureNode)e.Source;
            while (top.Parent != null && tmp.Parent != null && tmp.Parent != top.Parent)
            {
                a++;
                tmp = tmp.Parent;
            }
            e.addLabel(symbolTables.getSymbolTable(ATTACH), Convert.ToString(a));
        }
Ejemplo n.º 17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean readSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool readSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || !(syntaxGraph is PhraseStructure))
            {
                return(false);
            }
            syntaxGraph.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.PhraseStructure phraseStructure = (org.maltparser.core.syntaxgraph.PhraseStructure)syntaxGraph;
            PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;
//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;
            PhraseStructureNode parent       = null;
            PhraseStructureNode child        = null;

            currentHeaderTable = NegraTables.UNDEF;
            string line = null;

            syntaxGraph.Clear();
            nonterminals.Clear();
            try
            {
                while (true)
                {
                    line = reader.ReadLine();
                    if (ReferenceEquals(line, null))
                    {
                        if (syntaxGraph.HasTokens())
                        {
                            sentenceCount++;
                            if (syntaxGraph is MappablePhraseStructureGraph)
                            {
                                ((MappablePhraseStructureGraph)syntaxGraph).Mapping.updateDependenyGraph(((MappablePhraseStructureGraph)syntaxGraph), ((PhraseStructure)syntaxGraph).PhraseStructureRoot);
                            }
                        }
                        if (cIterations < nIterations)
                        {
                            cIterations++;
                            reopen();
                            return(true);
                        }
                        return(false);
                    }
                    else if (line.StartsWith("#EOS", StringComparison.Ordinal))
                    {
                        currentTerminalSize    = 0;
                        currentNonTerminalSize = 0;
                        currentHeaderTable     = NegraTables.UNDEF;
                        if (syntaxGraph is MappablePhraseStructureGraph)
                        {
                            ((MappablePhraseStructureGraph)syntaxGraph).Mapping.updateDependenyGraph(((MappablePhraseStructureGraph)syntaxGraph), ((PhraseStructure)syntaxGraph).PhraseStructureRoot);
                        }
                        return(true);
                    }
                    else if (line.StartsWith("#BOS", StringComparison.Ordinal))
                    {
                        currentHeaderTable = NegraTables.SENTENCE;
                        int s = -1, e = -1;
                        for (int i = 5, n = line.Length; i < n; i++)
                        {
                            if (char.IsDigit(line[i]) && s == -1)
                            {
                                s = i;
                            }
                            if (line[i] == ' ')
                            {
                                e = i;
                                break;
                            }
                        }
                        if (s != e && s != -1 && e != -1)
                        {
                            phraseStructure.SentenceID = int.Parse(line.Substring(s, e - s));
                        }
                        sentenceCount++;
                    }
                    else if (currentHeaderTable == NegraTables.SENTENCE)
                    {
                        if (line.Length >= 2 && line[0] == '#' && char.IsDigit(line[1]))
                        {                         // Non-terminal
                            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                            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)
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    if (columns.hasNext())
                                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                        column = columns.next();
                                    }
                                    if (column.Position == 0)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start + 1):line.Substring(start + 1, i - (start + 1)));
                                        child = nonterminals[index];
                                        if (child == null)
                                        {
                                            if (index != 0)
                                            {
                                                child = ((PhraseStructure)syntaxGraph).addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = child;
                                        }
                                    }
                                    else if (column.Position == 2 && child != null)
                                    {
                                        syntaxGraph.AddLabel(child, "CAT", (i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL)
                                    {
                                        edgelabelSymbol.Length = 0;
                                        edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        edgelabelTableName.Length = 0;
                                        edgelabelTableName.Append(column.Name);
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        parent = nonterminals[index];
                                        if (parent == null)
                                        {
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else
                                            {
                                                parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = parent;
                                        }
                                        Edge.Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                                        syntaxGraph.AddLabel(e, edgelabelTableName.ToString(), edgelabelSymbol.ToString());
                                    }
                                    else if (column.Category == ColumnDescription.SECONDARY_EDGE_LABEL && child != null)
                                    {
                                        if (secedgecounter % 2 == 0)
                                        {
                                            edgelabelSymbol.Length = 0;
                                            edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            secedgecounter++;
                                        }
                                        else
                                        {
                                            int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else if (index < START_ID_OF_NONTERMINALS)
                                            {
                                                parent = phraseStructure.GetTokenNode(index);
                                            }
                                            else
                                            {
                                                parent = nonterminals[index];
                                                if (parent == null)
                                                {
                                                    parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                                    nonterminals[index] = parent;
                                                }
                                            }
                                            Edge.Edge e = phraseStructure.addSecondaryEdge(parent, child);
                                            e.addLabel(symbolTables.getSymbolTable(column.Name), edgelabelSymbol.ToString());
                                            secedgecounter++;
                                        }
                                    }
                                    start = i + 1;
                                }
                            }
                        }
                        else
                        {                         // Terminal
                            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
                            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)
                                {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                    if (columns.hasNext())
                                    {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                                        column = columns.next();
                                    }
                                    if (column.Category == ColumnDescription.INPUT && child != null)
                                    {
                                        syntaxGraph.AddLabel(child, column.Name, (i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_EDGE_LABEL && child != null)
                                    {                                     // && column.getName().equals("EDGELABEL")) {
                                        edgelabelSymbol.Length = 0;
                                        edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        edgelabelTableName.Length = 0;
                                        edgelabelTableName.Append(column.Name);
                                    }
                                    else if (column.Category == ColumnDescription.PHRASE_STRUCTURE_NODE_LABEL && child != null)
                                    {
                                        int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                        parent = nonterminals[index];
                                        if (parent == null)
                                        {
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else
                                            {
                                                parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                            }
                                            nonterminals[index] = parent;
                                        }

                                        Edge.Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
                                        syntaxGraph.AddLabel(e, edgelabelTableName.ToString(), edgelabelSymbol.ToString());
                                    }
                                    else if (column.Category == ColumnDescription.SECONDARY_EDGE_LABEL && child != null)
                                    {
                                        if (secedgecounter % 2 == 0)
                                        {
                                            edgelabelSymbol.Length = 0;
                                            edgelabelSymbol.Append((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            secedgecounter++;
                                        }
                                        else
                                        {
                                            int index = int.Parse((i == n - 1)?line.Substring(start):line.Substring(start, i - start));
                                            if (index == 0)
                                            {
                                                parent = phraseStructure.PhraseStructureRoot;
                                            }
                                            else if (index < START_ID_OF_NONTERMINALS)
                                            {
                                                parent = phraseStructure.GetTokenNode(index);
                                            }
                                            else
                                            {
                                                parent = nonterminals[index];
                                                if (parent == null)
                                                {
                                                    parent = phraseStructure.addNonTerminalNode(index - START_ID_OF_NONTERMINALS + 1);
                                                    nonterminals[index] = parent;
                                                }
                                            }
                                            Edge.Edge e = phraseStructure.addSecondaryEdge(parent, child);
                                            e.addLabel(symbolTables.getSymbolTable(column.Name), edgelabelSymbol.ToString());
                                            secedgecounter++;
                                        }
                                    }
                                    start = i + 1;
                                }
                            }
                        }
                    }
                    else if (line.StartsWith("%%", StringComparison.Ordinal))
                    {                     // comment skip
                    }
                    else if (line.StartsWith("#FORMAT", StringComparison.Ordinal))
                    {
                        //				int index = line.indexOf(' ');
                        //				if (index > -1) {
                        //					try {
                        //						formatVersion = Integer.parseInt(line.substring(index+1));
                        //					} catch (NumberFormatException e) {
                        //
                        //					}
                        //				}
                    }
                    else if (line.StartsWith("#BOT", StringComparison.Ordinal))
                    {
                        //				int index = line.indexOf(' ');
                        //				if (index > -1) {
                        //					if (line.substring(index+1).equals("ORIGIN")) {
                        //						currentHeaderTable = NegraTables.ORIGIN;
                        //					} else if (line.substring(index+1).equals("EDITOR")) {
                        //						currentHeaderTable = NegraTables.EDITOR;
                        //					} else if (line.substring(index+1).equals("WORDTAG")) {
                        //						currentHeaderTable = NegraTables.WORDTAG;
                        //					} else if (line.substring(index+1).equals("MORPHTAG")) {
                        //						currentHeaderTable = NegraTables.MORPHTAG;
                        //					} else if (line.substring(index+1).equals("NODETAG")) {
                        //						currentHeaderTable = NegraTables.NODETAG;
                        //					} else if (line.substring(index+1).equals("EDGETAG")) {
                        //						currentHeaderTable = NegraTables.EDGETAG;
                        //					} else if (line.substring(index+1).equals("SECEDGETAG")) {
                        //						currentHeaderTable = NegraTables.SECEDGETAG;
                        //					} else {
                        //						currentHeaderTable = NegraTables.UNDEF;
                        //					}
                        //				}
                    }
                    else if (line.StartsWith("#EOT", StringComparison.Ordinal))
                    {
                        currentHeaderTable = NegraTables.UNDEF;
                    }
                }
            }
            catch (IOException e)
            {
                throw new DataFormatException("Error when reading from the input file. ", e);
            }
        }
Ejemplo n.º 18
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.º 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(String markingStrategyString, String coveredRoot, String liftingOrder, org.apache.log4j.Logger configLogger, org.maltparser.core.io.dataformat.DataFormatInstance dataFormatInstance, org.maltparser.core.symbol.SymbolTableHandler symbolTables) throws org.maltparser.core.exception.MaltChainedException
        public virtual void initialize(string markingStrategyString, string coveredRoot, string liftingOrder, Logger configLogger, DataFormatInstance dataFormatInstance, SymbolTableHandler symbolTables)
        {
            nodeLifted            = new List <bool>();
            nodeTrace             = new List <List <DependencyNode> >();
            headDeprel            = new List <DependencyNode>();
            nodePath              = new List <bool>();
            isCoveredRoot_Renamed = new List <bool>();
            nodeRelationLength    = new List <int>();
            synacticHeadDeprel    = new List <string>();

            this.configLogger = configLogger;
            if (markingStrategyString.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.NONE;
            }
            else if (markingStrategyString.Equals("baseline", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.BASELINE;
            }
            else if (markingStrategyString.Equals("head", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.HEAD;
            }
            else if (markingStrategyString.Equals("path", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.PATH;
            }
            else if (markingStrategyString.Equals("head+path", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.HEADPATH;
            }
            else if (markingStrategyString.Equals("trace", StringComparison.OrdinalIgnoreCase))
            {
                markingStrategy = PseudoProjectiveEncoding.TRACE;
            }
            deprelColumn      = dataFormatInstance.getColumnDescriptionByName("DEPREL");
            deprelSymbolTable = symbolTables.getSymbolTable(deprelColumn.Name);
            if (markingStrategy == PseudoProjectiveEncoding.HEAD || markingStrategy == PseudoProjectiveEncoding.PATH || markingStrategy == PseudoProjectiveEncoding.HEADPATH)
            {
                ppliftedColumn      = dataFormatInstance.addInternalColumnDescription(symbolTables, "PPLIFTED", "DEPENDENCY_EDGE_LABEL", "BOOLEAN", "", deprelColumn.NullValueStrategy);
                ppliftedSymbolTable = symbolTables.getSymbolTable(ppliftedColumn.Name);
                if (markingStrategy == PseudoProjectiveEncoding.PATH)
                {
                    ppliftedSymbolTable.addSymbol("#true#");
                    ppliftedSymbolTable.addSymbol("#false#");
                }
                else
                {
                    ppliftedSymbolTable.addSymbol("#false#");
                }
            }

            if (markingStrategy == PseudoProjectiveEncoding.PATH || markingStrategy == PseudoProjectiveEncoding.HEADPATH)
            {
                pppathColumn      = dataFormatInstance.addInternalColumnDescription(symbolTables, "PPPATH", "DEPENDENCY_EDGE_LABEL", "BOOLEAN", "", deprelColumn.NullValueStrategy);
                pppathSymbolTable = symbolTables.getSymbolTable(pppathColumn.Name);
                pppathSymbolTable.addSymbol("#true#");
                pppathSymbolTable.addSymbol("#false#");
            }

            if (coveredRoot.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                rootAttachment = CoveredRootAttachment.NONE;
            }
            else if (coveredRoot.Equals("ignore", StringComparison.OrdinalIgnoreCase))
            {
                rootAttachment = CoveredRootAttachment.IGNORE;
            }
            else if (coveredRoot.Equals("left", StringComparison.OrdinalIgnoreCase))
            {
                rootAttachment = CoveredRootAttachment.LEFT;
            }
            else if (coveredRoot.Equals("right", StringComparison.OrdinalIgnoreCase))
            {
                rootAttachment = CoveredRootAttachment.RIGHT;
            }
            else if (coveredRoot.Equals("head", StringComparison.OrdinalIgnoreCase))
            {
                rootAttachment = CoveredRootAttachment.HEAD;
            }

            if (rootAttachment != CoveredRootAttachment.NONE)
            {
                ppcoveredRootColumn      = dataFormatInstance.addInternalColumnDescription(symbolTables, "PPCOVERED", "DEPENDENCY_EDGE_LABEL", "BOOLEAN", "", deprelColumn.NullValueStrategy);
                ppcoveredRootSymbolTable = symbolTables.getSymbolTable(ppcoveredRootColumn.Name);
                ppcoveredRootSymbolTable.addSymbol("#true#");
                ppcoveredRootSymbolTable.addSymbol("#false#");
            }
            if (liftingOrder.Equals("shortest", StringComparison.OrdinalIgnoreCase))
            {
                this.liftingOrder = LiftingOrder.SHORTEST;
            }
            else if (liftingOrder.Equals("deepest", StringComparison.OrdinalIgnoreCase))
            {
                this.liftingOrder = LiftingOrder.DEEPEST;
            }
        }
Ejemplo n.º 20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeSentence(org.maltparser.core.syntaxgraph.TokenStructure syntaxGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void writeSentence(ITokenStructure syntaxGraph)
        {
            if (syntaxGraph == null || dataFormatInstance == null || !syntaxGraph.HasTokens())
            {
                return;
            }
            IEnumerator <ColumnDescription> columns = dataFormatInstance.GetEnumerator();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.symbol.SymbolTableHandler symbolTables = syntaxGraph.getSymbolTables();
            SymbolTableHandler symbolTables = syntaxGraph.SymbolTables;

            foreach (int i in syntaxGraph.TokenIndices)
            {
                writeComments(syntaxGraph, i);
                try
                {
                    ColumnDescription column = null;
                    while (columns.MoveNext())
                    {
                        column = columns.Current;

                        if (column.Category == ColumnDescription.INPUT)
                        {                         // && column.getType() != ColumnDescription.IGNORE) {
                            TokenNode node = syntaxGraph.GetTokenNode(i);
                            if (!column.Name.Equals("ID"))
                            {
                                if (node.hasLabel(symbolTables.getSymbolTable(column.Name)))
                                {
                                    output.Append(node.getLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                                    if (output.Length != 0)
                                    {
                                        writer.Write(output.ToString());
                                    }
                                    else
                                    {
                                        writer.BaseStream.WriteByte('_');
                                    }
                                }
                                else
                                {
                                    writer.BaseStream.WriteByte('_');
                                }
                            }
                            else
                            {
                                writer.Write(Convert.ToString(i));
                            }
                        }
                        else if (column.Category == ColumnDescription.HEAD && syntaxGraph is IDependencyStructure)
                        {
                            if (((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHead())
                            {
                                writer.Write(Convert.ToString(((IDependencyStructure)syntaxGraph).GetDependencyNode(i).Head.Index));
                            }
                            else
                            {
                                writer.Write(Convert.ToString(0));
                            }
                        }
                        else if (column.Category == ColumnDescription.DEPENDENCY_EDGE_LABEL && syntaxGraph is IDependencyStructure)
                        {
                            if (((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHead() && ((IDependencyStructure)syntaxGraph).GetDependencyNode(i).hasHeadEdgeLabel(symbolTables.getSymbolTable(column.Name)))
                            {
                                output.Append(((IDependencyStructure)syntaxGraph).GetDependencyNode(i).getHeadEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                            }
                            else
                            {
                                output.Append(((IDependencyStructure)syntaxGraph).GetDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(column.Name)));
                            }

                            if (output.Length != 0)
                            {
                                writer.Write(output.ToString());
                            }
                        }
                        else
                        {
                            writer.Write(column.DefaultOutput);
                        }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                        if (columns.hasNext())
                        {
                            writer.BaseStream.WriteByte(TAB);
                        }
                        output.Length = 0;
                    }
                    writer.BaseStream.WriteByte(NEWLINE);
                    columns = dataFormatInstance.GetEnumerator();
                }
                catch (IOException e)
                {
                    close();
                    throw new DataFormatException("Could not write to the output file. ", e);
                }
            }
            writeComments(syntaxGraph, syntaxGraph.NTokenNode() + 1);
            try
            {
                writer.BaseStream.WriteByte('\n');
                writer.Flush();
            }
            catch (IOException e)
            {
                close();
                throw new DataFormatException("Could not write to the output file. ", e);
            }
        }