コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void initProjectivization(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void initProjectivization(IDependencyStructure pdg)
        {
            nodeLifted.Clear();
            nodeTrace.Clear();
            headDeprel.Clear();
            nodePath.Clear();
            isCoveredRoot_Renamed.Clear();
            nodeRelationLength.Clear();

            foreach (int index in pdg.DependencyIndices)
            {
                nodeLifted.Add(false);
                nodeTrace.Add(new List <DependencyNode>());
                headDeprel.Add(null);
                nodePath.Add(false);
                isCoveredRoot_Renamed.Add(false);
                if (ppliftedSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(ppliftedSymbolTable, ppliftedSymbolTable.getSymbolStringToCode("#false#"));
                }
                if (pppathSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(pppathSymbolTable, pppathSymbolTable.getSymbolStringToCode("#false#"));
                }
                if (ppcoveredRootSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(ppcoveredRootSymbolTable, ppcoveredRootSymbolTable.getSymbolStringToCode("#false#"));
                }
            }
            computeRelationLength(pdg);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(org.maltparser.parser.ParserConfiguration parserConfiguration) throws org.maltparser.core.exception.MaltChainedException
        public virtual void initialize(ParserConfiguration parserConfiguration)
        {
            if (parserConfiguration != null)
            {
                StackConfig            config      = (StackConfig)parserConfiguration;
                Stack <DependencyNode> sourceStack = config.Stack;
                Stack <DependencyNode> sourceInput = config.Input;
                DependencyGraph = config.DependencyGraph;
                for (int i = 0, n = sourceStack.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    stack.Push(dependencyGraph.GetDependencyNode(sourceStack.get(i).Index));
                }
                for (int i = 0, n = sourceInput.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    input.Push(dependencyGraph.GetDependencyNode(sourceInput.get(i).Index));
                }
            }
            else
            {
                stack.Push(dependencyGraph.DependencyRoot);
                for (int i = dependencyGraph.HighestTokenIndex; i > 0; i--)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode node = dependencyGraph.getDependencyNode(i);
                    DependencyNode node = dependencyGraph.GetDependencyNode(i);
                    if (node != null && !node.hasHead())
                    {
                        input.Push(node);
                    }
                }
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void computeRelationLength(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void computeRelationLength(IDependencyStructure pdg)
        {
            nodeRelationLength.Add(0);
            foreach (int index in pdg.TokenIndices)
            {
                nodeRelationLength.Add(Math.Abs(pdg.GetDependencyNode(index).Index - pdg.GetDependencyNode(index).Head.Index));
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void assignPseudoProjectiveDeprels(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void assignPseudoProjectiveDeprels(IDependencyStructure pdg)
        {
            int newLabelCode;

            foreach (int index in pdg.TokenIndices)
            {
                if (!isCoveredRoot(pdg.GetDependencyNode(index)))
                {
                    if (markingStrategy == PseudoProjectiveEncoding.HEAD || markingStrategy == PseudoProjectiveEncoding.PATH || markingStrategy == PseudoProjectiveEncoding.HEADPATH)
                    {
                        if (markingStrategy == PseudoProjectiveEncoding.PATH)
                        {
                            if (nodeLifted[index])
                            {
                                newLabelCode = ppliftedSymbolTable.getSymbolStringToCode("#true#");
                            }
                            else
                            {
                                newLabelCode = ppliftedSymbolTable.getSymbolStringToCode("#false#");
                            }
                            pdg.GetDependencyNode(index).HeadEdge.addLabel(ppliftedSymbolTable, newLabelCode);
                        }
                        else
                        {
                            if (nodeLifted[index])
                            {
                                newLabelCode = ppliftedSymbolTable.addSymbol(deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(headDeprel[index].Index).HeadEdge.getLabelCode(deprelSymbolTable)));
                            }
                            else
                            {
                                newLabelCode = ppliftedSymbolTable.getSymbolStringToCode("#false#");
                            }
                            pdg.GetDependencyNode(index).HeadEdge.addLabel(ppliftedSymbolTable, newLabelCode);
                        }
                    }

                    if (markingStrategy == PseudoProjectiveEncoding.PATH || markingStrategy == PseudoProjectiveEncoding.HEADPATH)
                    {
                        if (nodePath[index])
                        {
                            newLabelCode = pppathSymbolTable.getSymbolStringToCode("#true#");
                        }
                        else
                        {
                            newLabelCode = pppathSymbolTable.getSymbolStringToCode("#false#");
                        }
                        pdg.GetDependencyNode(index).HeadEdge.addLabel(pppathSymbolTable, newLabelCode);
                    }
                }
                else if (!(rootAttachment == CoveredRootAttachment.NONE || rootAttachment == CoveredRootAttachment.IGNORE))
                {
                    pdg.GetDependencyNode(index).HeadEdge.addLabel(ppcoveredRootSymbolTable, ppcoveredRootSymbolTable.getSymbolStringToCode("#true#"));
                }
            }
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean attachCoveredRoots(org.maltparser.core.syntaxgraph.DependencyStructure pdg, org.maltparser.core.syntaxgraph.node.DependencyNode deepest) throws org.maltparser.core.exception.MaltChainedException
        private bool attachCoveredRoots(IDependencyStructure pdg, DependencyNode deepest)
        {
            int            i;
            bool           foundCoveredRoot = false;
            DependencyNode coveredRootHead;

            for (i = Math.Min(deepest.Index, deepest.Head.Index) + 1; i < Math.Max(deepest.Index, deepest.Head.Index); i++)
            {
                int leftMostIndex = pdg.GetDependencyNode(i).LeftmostProperDescendantIndex;
                if (leftMostIndex == -1)
                {
                    leftMostIndex = i;
                }
                int rightMostIndex = pdg.GetDependencyNode(i).RightmostProperDescendantIndex;
                if (rightMostIndex == -1)
                {
                    rightMostIndex = i;
                }
                if (!nodeLifted[i] && pdg.GetDependencyNode(i).Head.Root&& !deepest.Head.Root && Math.Min(deepest.Index, deepest.Head.Index) < leftMostIndex && rightMostIndex < Math.Max(deepest.Index, deepest.Head.Index))
                {
                    if (rootAttachment == CoveredRootAttachment.LEFT)
                    {
                        if (deepest.Head.Index < deepest.Index)
                        {
                            coveredRootHead = deepest.Head;
                        }
                        else
                        {
                            coveredRootHead = deepest;
                        }
                    }
                    else if (rootAttachment == CoveredRootAttachment.RIGHT)
                    {
                        if (deepest.Index < deepest.Head.Index)
                        {
                            coveredRootHead = deepest.Head;
                        }
                        else
                        {
                            coveredRootHead = deepest;
                        }
                    }
                    else
                    {
                        coveredRootHead = deepest.Head;
                    }
                    pdg.MoveDependencyEdge(coveredRootHead.Index, pdg.GetDependencyNode(i).Index);
                    CoveredRoot      = pdg.GetDependencyNode(i);
                    foundCoveredRoot = true;
                }
            }
            return(foundCoveredRoot);
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void deattachCoveredRootsForDeprojectivization(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void deattachCoveredRootsForDeprojectivization(IDependencyStructure pdg)
        {
            foreach (int index in pdg.TokenIndices)
            {
                if (pdg.GetDependencyNode(index).HeadEdge.hasLabel(deprelSymbolTable))
                {
                    if (pdg.GetDependencyNode(index).HeadEdge.hasLabel(ppcoveredRootSymbolTable) && ppcoveredRootSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(ppcoveredRootSymbolTable)).Equals("#true#"))
                    {
                        pdg.MoveDependencyEdge(pdg.DependencyRoot.Index, pdg.GetDependencyNode(index).Index);
                    }
                }
            }
        }
コード例 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.node.DependencyNode getShortestNonProjectiveNode(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private DependencyNode getShortestNonProjectiveNode(IDependencyStructure pdg)
        {
            DependencyNode shortestNonProjectiveNode = null;

            foreach (int index in pdg.DependencyIndices)
            {
                if (!pdg.GetDependencyNode(index).Projective&& (shortestNonProjectiveNode == null || nodeRelationLength[index] < nodeRelationLength[shortestNonProjectiveNode.Index]))
                {
                    //					|| (nodeRelationLength.get(index) == nodeRelationLength.get(shortestNonProjectiveNode.getIndex())))) {
                    shortestNonProjectiveNode = pdg.GetDependencyNode(index);
                }
            }
            return(shortestNonProjectiveNode);
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.node.DependencyNode getDeepestNonProjectiveNode(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private DependencyNode getDeepestNonProjectiveNode(IDependencyStructure pdg)
        {
            DependencyNode deepestNonProjectiveNode = null;

            foreach (int index in pdg.DependencyIndices)
            {
                if (!pdg.GetDependencyNode(index).Projective&& (deepestNonProjectiveNode == null || pdg.GetDependencyNode(index).DependencyNodeDepth > pdg.GetDependencyNode(deepestNonProjectiveNode.Index).DependencyNodeDepth))
                {
                    deepestNonProjectiveNode = pdg.GetDependencyNode(index);
                }
            }

            return(deepestNonProjectiveNode);
        }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean necessarySwap(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.core.syntaxgraph.DependencyStructure parse, org.maltparser.core.syntaxgraph.node.DependencyNode node, java.util.Stack<org.maltparser.core.syntaxgraph.node.DependencyNode> input) throws org.maltparser.core.exception.MaltChainedException
        private bool necessarySwap(IDependencyStructure gold, IDependencyStructure parse, DependencyNode node, Stack <DependencyNode> input)
        {
            DependencyNode left  = node;
            int            index = input.Count - 1;

            if (index < 0)
            {
                return(true);
            }
            DependencyNode right = input.Peek();

            int rc = -1;

            while (projectiveInterval(parse, left, right))
            {
                if (rc == right.Index)
                {
                    return(false);
                }
                if (gold.GetDependencyNode(node.Index).Head.Index == right.Index)
                {
                    return(!leftComplete(gold, node));
                }
                if (gold.GetDependencyNode(right.Index).Head.Index == node.Index)
                {
                    if (gold.GetDependencyNode(right.Index).hasRightDependent())
                    {
                        rc = gold.GetDependencyNode(right.Index).RightmostProperDescendantIndex;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (index > 0)
                {
                    left = right;
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    right = input.get(--index);
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
コード例 #10
0
        /// <summary>
        /// Same as parse(String[] tokens), but instead it returns an array of tokens with a head index and a dependency type at the end of string
        /// </summary>
        /// <param name="tokens"> an array of tokens to parse </param>
        /// <returns> an array of tokens with a head index and a dependency type at the end of string </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String[] parseTokens(String[] tokens) throws org.maltparser.core.exception.MaltChainedException
        public virtual string[] parseTokens(string[] tokens)
        {
            IDependencyStructure outputGraph = parse(tokens);
            StringBuilder        sb          = new StringBuilder();

            string[]    outputTokens = new string[tokens.Length];
            SymbolTable deprelTable  = outputGraph.SymbolTables.getSymbolTable("DEPREL");

            foreach (int?index in outputGraph.TokenIndices)
            {
                sb.Length = 0;
                if (index <= tokens.Length)
                {
                    DependencyNode node = outputGraph.GetDependencyNode(index.Value);
                    sb.Append(tokens[index - 1]);
                    sb.Append('\t');
                    sb.Append(node.Head.Index);
                    sb.Append('\t');
                    if (node.HeadEdge.hasLabel(deprelTable))
                    {
                        sb.Append(node.HeadEdge.getLabelSymbol(deprelTable));
                    }
                    else
                    {
                        sb.Append(outputGraph.GetDefaultRootEdgeLabelSymbol(deprelTable));
                    }
                    outputTokens[index - 1] = sb.ToString();
                }
            }
            return(outputTokens);
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void deprojectivize(org.maltparser.core.syntaxgraph.DependencyStructure pdg, int markingStrategy) throws org.maltparser.core.exception.MaltChainedException
        public void deprojectivize(IDependencyStructure pdg, int markingStrategy)
        {
            SymbolTable deprelSymbolTable   = pdg.SymbolTables.getSymbolTable("DEPREL");
            SymbolTable ppliftedSymbolTable = pdg.SymbolTables.getSymbolTable("PPLIFTED");
            SymbolTable pppathSymbolTable   = pdg.SymbolTables.getSymbolTable("PPPATH");

            bool[] nodeLifted = new bool[pdg.NDependencyNode()];
            Arrays.fill(nodeLifted, false);
            bool[] nodePath = new bool[pdg.NDependencyNode()];
            Arrays.fill(nodePath, false);
            string[] synacticHeadDeprel = new string[pdg.NDependencyNode()];
            Arrays.fill(synacticHeadDeprel, null);

            foreach (int index in pdg.TokenIndices)
            {
                Edge e = pdg.GetDependencyNode(index).HeadEdge;
                if (e.hasLabel(deprelSymbolTable))
                {
                    if (e.hasLabel(pppathSymbolTable) && pppathSymbolTable.getSymbolCodeToString(e.getLabelCode(pppathSymbolTable)).Equals("#true#"))
                    {
                        nodePath[pdg.GetDependencyNode(index).Index] = true;
                    }
                    if (e.hasLabel(ppliftedSymbolTable) && !ppliftedSymbolTable.getSymbolCodeToString(e.getLabelCode(ppliftedSymbolTable)).Equals("#false#"))
                    {
                        nodeLifted[index] = true;

                        if (!ppliftedSymbolTable.getSymbolCodeToString(e.getLabelCode(ppliftedSymbolTable)).Equals("#true#"))
                        {
                            synacticHeadDeprel[index] = ppliftedSymbolTable.getSymbolCodeToString(e.getLabelCode(ppliftedSymbolTable));
                        }
                    }
                }
            }
            deattachCoveredRootsForDeprojectivization(pdg, deprelSymbolTable);
            if (markingStrategy == HEAD && needsDeprojectivizeWithHead(pdg, nodeLifted, nodePath, synacticHeadDeprel, deprelSymbolTable))
            {
                deprojectivizeWithHead(pdg, pdg.DependencyRoot, nodeLifted, nodePath, synacticHeadDeprel, deprelSymbolTable);
            }
            else if (markingStrategy == PATH)
            {
                deprojectivizeWithPath(pdg, pdg.DependencyRoot, nodeLifted, nodePath);
            }
            else if (markingStrategy == HEADPATH)
            {
                deprojectivizeWithHeadAndPath(pdg, pdg.DependencyRoot, nodeLifted, nodePath, synacticHeadDeprel, deprelSymbolTable);
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates a immutable dependency graph
        /// </summary>
        /// <param name="dataFormat"> a data format that describes the label types (or the columns in the input and output) </param>
        /// <param name="sourceGraph"> a dependency graph that implements the interface org.maltparser.core.syntaxgraph.DependencyStructure </param>
        /// <param name="defaultRootLabel"> the default root label </param>
        /// <exception cref="MaltChainedException"> </exception>
        public ConcurrentDependencyGraph(DataFormat.DataFormat dataFormat, IDependencyStructure sourceGraph, string defaultRootLabel)
        {
            DataFormat = dataFormat;

            nodes = new ConcurrentDependencyNode[sourceGraph.NDependencyNode()];

            // Add nodes
            nodes[0] = new ConcurrentDependencyNode(this, 0, null); // ROOT

            foreach (int index in sourceGraph.TokenIndices)
            {
                DependencyNode gNode = sourceGraph.GetDependencyNode(index);

                string[] columns = new string[dataFormat.NumberOfColumns()];

                for (int i = 0; i < dataFormat.NumberOfColumns(); i++)
                {
                    ColumnDescription column = dataFormat.GetColumnDescription(i);

                    if (!column.Internal)
                    {
                        if (column.Category == ColumnDescription.Input)
                        {
                            columns[i] = gNode.getLabelSymbol(sourceGraph.SymbolTables.getSymbolTable(column.Name));
                        }
                        else if (column.Category == ColumnDescription.Head)
                        {
                            if (gNode.hasHead())
                            {
                                columns[i] = Convert.ToString(gNode.HeadEdge.Source.Index);
                            }
                            else
                            {
                                columns[i] = Convert.ToString(-1);
                            }
                        }
                        else if (column.Category == ColumnDescription.DependencyEdgeLabel)
                        {
                            SymbolTable sourceTable = sourceGraph.SymbolTables.getSymbolTable(column.Name);

                            if (gNode.HeadEdge.hasLabel(sourceTable))
                            {
                                columns[i] = gNode.HeadEdge.getLabelSymbol(sourceTable);
                            }
                            else
                            {
                                columns[i] = defaultRootLabel;
                            }
                        }
                        else
                        {
                            columns[i] = "_";
                        }
                    }
                }
                nodes[index] = new ConcurrentDependencyNode(this, index, columns);
            }
        }
コード例 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(org.maltparser.parser.ParserConfiguration parserConfiguration) throws org.maltparser.core.exception.MaltChainedException
        public virtual void initialize(ParserConfiguration parserConfiguration)
        {
            if (parserConfiguration != null)
            {
                CovingtonConfig       covingtonConfig = (CovingtonConfig)parserConfiguration;
                List <DependencyNode> sourceInput     = covingtonConfig.Input;
                DependencyGraph = covingtonConfig.DependencyGraph;
                for (int i = 0, n = sourceInput.Count; i < n; i++)
                {
                    input.Add(dependencyGraph.GetDependencyNode(sourceInput[i].Index));
                }
                left      = covingtonConfig.Left;
                right     = covingtonConfig.Right;
                rightstop = covingtonConfig.Rightstop;
                leftstop  = covingtonConfig.Leftstop;
            }
            else
            {
                for (int i = 0, n = dependencyGraph.HighestTokenIndex; i <= n; i++)
                {
                    DependencyNode node = dependencyGraph.GetDependencyNode(i);
                    if (node != null)
                    {
                        input.Add(node);
                    }
                }
                if (allowRoot == true)
                {
                    leftstop = 0;
                }
                else
                {
                    leftstop = 1;
                }
                rightstop = dependencyGraph.HighestTokenIndex;
                left      = leftstop;
                right     = left + 1;
            }
        }
コード例 #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void deprojectivize(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        public virtual void deprojectivize(IDependencyStructure pdg)
        {
            initDeprojeciviztion(pdg);

            foreach (int index in pdg.TokenIndices)
            {
                if (pdg.GetDependencyNode(index).HeadEdge.hasLabel(deprelSymbolTable))
                {
                    if (pdg.GetDependencyNode(index).HeadEdge.hasLabel(pppathSymbolTable) && pppathSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(pppathSymbolTable)).Equals("#true#"))
                    {
                        Path = pdg.GetDependencyNode(index);
                    }
                    if (pdg.GetDependencyNode(index).HeadEdge.hasLabel(ppliftedSymbolTable) && !ppliftedSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(ppliftedSymbolTable)).Equals("#false#"))
                    {
                        nodeLifted[index] = true;
                        if (!ppliftedSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(ppliftedSymbolTable)).Equals("#true#"))
                        {
                            synacticHeadDeprel[index] = ppliftedSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(ppliftedSymbolTable));
                        }
                    }
                }
            }
            deattachCoveredRootsForDeprojectivization(pdg);
            if (markingStrategy == PseudoProjectiveEncoding.HEAD && needsDeprojectivizeWithHead(pdg))
            {
                deprojectivizeWithHead(pdg, pdg.DependencyRoot);
            }
            else if (markingStrategy == PseudoProjectiveEncoding.PATH)
            {
                deprojectivizeWithPath(pdg, pdg.DependencyRoot);
            }
            else if (markingStrategy == PseudoProjectiveEncoding.HEADPATH)
            {
                deprojectivizeWithHeadAndPath(pdg, pdg.DependencyRoot);
            }
        }
コード例 #15
0
        // Check whether there is at least one node in the specified dependency structure that can be lifted.
        // If this is not the case, there is no need to call deprojectivizeWithHead.

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean needsDeprojectivizeWithHead(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private bool needsDeprojectivizeWithHead(IDependencyStructure pdg)
        {
            foreach (int index in pdg.DependencyIndices)
            {
                if (nodeLifted[index])
                {
                    DependencyNode node = pdg.GetDependencyNode(index);
                    if (breadthFirstSearchSortedByDistanceForHead(pdg, node.Head, node, synacticHeadDeprel[index]) != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #16
0
        protected internal virtual void CopyDynamicInput(IDependencyStructure source, IDependencyStructure target)
        {
            foreach (int index in source.TokenIndices)
            {
                DependencyNode sNode = source.GetDependencyNode(index);

                DependencyNode tNode = target.GetDependencyNode(index);

                foreach (SymbolTable table in sNode.LabelTypes)
                {
                    if (!tNode.hasLabel(table))
                    {
                        tNode.addLabel(table, sNode.getLabelSymbol(table));
                    }
                }
            }
        }
コード例 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int process(int signal) throws org.maltparser.core.exception.MaltChainedException
        public override int process(int signal)
        {
            if (task.Equals("projectivity"))
            {
                if (cachedSource == null)
                {
                    cachedSource = (IDependencyStructure)flowChartinstance.getFlowChartRegistry(typeof(IDependencyStructure), sourceName);
                }
                try
                {
                    writer.append("graph # ");
                    writer.append(Convert.ToString(graphCounter));
                    writer.append('\n');
                    foreach (int index in cachedSource.TokenIndices)
                    {
                        DependencyNode node = cachedSource.GetDependencyNode(index);

                        writer.append(Convert.ToString(node.Index));
                        writer.append('\t');
                        writer.append(Convert.ToString(node.Head.Index));
                        writer.append('\t');
                        writer.append('#');
                        writer.append('\t');
                        if (node.Projective)
                        {
                            writer.append("@P");
                        }
                        else
                        {
                            writer.append("@N");
                        }
                        writer.append('\n');
                    }
                    writer.append('\n');
                }
                catch (IOException e)
                {
                    throw new MaltChainedException("", e);
                }
                graphCounter++;
            }
            return(signal);
        }
コード例 #18
0
        /// <summary>
        /// Copies the edges of the source dependency structure to the target dependency structure
        /// </summary>
        /// <param name="source"> a source dependency structure </param>
        /// <param name="target"> a target dependency structure </param>
        /// <exception cref="MaltChainedException"> </exception>
        protected internal virtual void CopyEdges(IDependencyStructure source, IDependencyStructure target)
        {
            foreach (int index in source.TokenIndices)
            {
                DependencyNode sNode = source.GetDependencyNode(index);

                if (sNode.hasHead())
                {
                    Edge s = sNode.HeadEdge;

                    Edge t = target.AddDependencyEdge(s.Source.Index, s.Target.Index);

                    foreach (SymbolTable table in s.LabelTypes)
                    {
                        t.addLabel(table, s.getLabelSymbol(table));
                    }
                }
            }
        }
コード例 #19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean leftComplete(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.core.syntaxgraph.node.DependencyNode right) throws org.maltparser.core.exception.MaltChainedException
        private bool leftComplete(IDependencyStructure gold, DependencyNode right)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode goldNode = gold.getDependencyNode(right.getIndex());
            DependencyNode goldNode = gold.GetDependencyNode(right.Index);

            if (!goldNode.hasLeftDependent())
            {
                return(true);
            }
            else if (!right.hasLeftDependent())
            {
                return(false);
            }
            else if (goldNode.LeftmostDependent.Index == right.LeftmostDependent.Index)
            {
                return(true);
            }
            return(false);
        }
コード例 #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean projectiveInterval(org.maltparser.core.syntaxgraph.DependencyStructure parse, org.maltparser.core.syntaxgraph.node.DependencyNode left, org.maltparser.core.syntaxgraph.node.DependencyNode right) throws org.maltparser.core.exception.MaltChainedException
        private bool projectiveInterval(IDependencyStructure parse, DependencyNode left, DependencyNode right)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int l = swapArray.get(left.getIndex());
            int l = swapArray[left.Index];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int r = swapArray.get(right.getIndex());
            int            r    = swapArray[right.Index];
            DependencyNode node = null;

            if (l > r)
            {
                return(false);
            }
            else
            {
                for (int i = l + 1; i < r; i++)
                {
                    for (int j = 0; j < swapArray.Count; j++)
                    {
                        if (swapArray[j] == i)
                        {
                            node = parse.GetDependencyNode(j);
                            break;
                        }
                    }
                    while (node.hasHead())
                    {
                        node = node.Head;
                    }
                    if (!(node == left || node == right))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
コード例 #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void projectivize(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        public virtual void projectivize(IDependencyStructure pdg)
        {
            id++;
            if (!pdg.Tree)
            {
                configLogger.info("\n[Warning: Sentence '" + id + "' cannot projectivize, because the dependency graph is not a tree]\n");
                return;
            }
            DependencyNode deepestNonProjectiveNode;

            initProjectivization(pdg);
            if (rootAttachment == CoveredRootAttachment.IGNORE)
            {
                if (markingStrategy != PseudoProjectiveEncoding.NONE)
                {
                    while (!pdg.Projective)
                    {
                        if (liftingOrder == LiftingOrder.DEEPEST)
                        {
                            deepestNonProjectiveNode = getDeepestNonProjectiveNode(pdg);
                        }
                        else
                        {
                            deepestNonProjectiveNode = getShortestNonProjectiveNode(pdg);
                        }
                        if (!attachCoveredRoots(pdg, deepestNonProjectiveNode))
                        {
                            nodeLifted[deepestNonProjectiveNode.Index] = true;
                            setHeadDeprel(deepestNonProjectiveNode, deepestNonProjectiveNode.Head);
                            Path = deepestNonProjectiveNode.Head;
                            pdg.MoveDependencyEdge(pdg.GetDependencyNode(deepestNonProjectiveNode.Head.Head.Index).Index, deepestNonProjectiveNode.Index);
                        }
                    }
                    deattachCoveredRootsForProjectivization(pdg);
                }
            }
            else
            {
                if (rootAttachment != CoveredRootAttachment.NONE)
                {
                    foreach (int index in pdg.TokenIndices)
                    {
                        attachCoveredRoots(pdg, pdg.GetTokenNode(index));
                    }
                }
                if (markingStrategy != PseudoProjectiveEncoding.NONE)
                {
                    while (!pdg.Projective)
                    {
                        if (liftingOrder == LiftingOrder.DEEPEST)
                        {
                            deepestNonProjectiveNode = getDeepestNonProjectiveNode(pdg);
                        }
                        else
                        {
                            deepestNonProjectiveNode = getShortestNonProjectiveNode(pdg);
                        }
                        nodeLifted[deepestNonProjectiveNode.Index] = true;
                        setHeadDeprel(deepestNonProjectiveNode, deepestNonProjectiveNode.Head);
                        Path = deepestNonProjectiveNode.Head;
                        pdg.MoveDependencyEdge(pdg.GetDependencyNode(deepestNonProjectiveNode.Head.Head.Index).Index, deepestNonProjectiveNode.Index);
                    }
                }
            }
            // collectTraceStatistics(pdg);
            assignPseudoProjectiveDeprels(pdg);
        }
コード例 #22
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void assignPseudoProjectiveDeprelsForMerge(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void assignPseudoProjectiveDeprelsForMerge(IDependencyStructure pdg)
        {
            List <string> originalDeprel = new List <string>();
            string        newLabel;

            originalDeprel.Add(null);
            foreach (int index in pdg.TokenIndices)
            {
                originalDeprel.Add(deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)));
            }
            foreach (int index in pdg.TokenIndices)
            {
                newLabel = null;
                if (!isCoveredRoot(pdg.GetDependencyNode(index)))
                {
                    if (markingStrategy == PseudoProjectiveEncoding.HEAD)
                    {
                        if (nodeLifted[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|"
                                       + originalDeprel[headDeprel[index].Index];
                            // } else {
                            // newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.getDependencyNode(index).getHeadEdge().getLabelCode(deprelSymbolTable));
                        }
                    }
                    else if (markingStrategy == PseudoProjectiveEncoding.PATH)
                    {
                        if (nodeLifted[index] && nodePath[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|%";
                        }
                        else if (nodeLifted[index] && !nodePath[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|";
                        }
                        else if (!nodeLifted[index] && nodePath[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "%";
                        }
                    }
                    else if (markingStrategy == PseudoProjectiveEncoding.HEADPATH)
                    {
                        if (nodeLifted[index] && nodePath[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|"
                                       + originalDeprel[headDeprel[index].Index] + "%";
                        }
                        else if (nodeLifted[index] && !nodePath[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|"
                                       + originalDeprel[headDeprel[index].Index];
                        }
                        else if (!nodeLifted[index] && nodePath[index])
                        {
                            newLabel = originalDeprel[pdg.GetDependencyNode(index).Index] + "%";
                        }
                    }
                    else if (markingStrategy == PseudoProjectiveEncoding.TRACE)
                    {
                        if (nodeLifted[index])
                        {
                            newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|";
                        }
                    }
                }
                else if (!(rootAttachment == CoveredRootAttachment.NONE || rootAttachment == CoveredRootAttachment.IGNORE))
                {
                    newLabel = deprelSymbolTable.getSymbolCodeToString(pdg.GetDependencyNode(index).HeadEdge.getLabelCode(deprelSymbolTable)) + "|null";
                }
                if (!ReferenceEquals(newLabel, null))
                {
                    setLabel(pdg.GetDependencyNode(index), newLabel);
                }
            }
        }