Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean deprojectivizeWithHeadAndPath(org.maltparser.core.syntaxgraph.DependencyStructure pdg, org.maltparser.core.syntaxgraph.node.DependencyNode node) throws org.maltparser.core.exception.MaltChainedException
        private bool deprojectivizeWithHeadAndPath(IDependencyStructure pdg, DependencyNode node)
        {
            bool           success = true, childSuccess = false;
            int            i, childAttempts = 2;
            DependencyNode child, possibleSyntacticHead;

            if (node.hasHead() && node.HeadEdge.Labeled && nodeLifted[node.Index] && nodePath[node.Index])
            {
                possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.Head, node, synacticHeadDeprel[node.Index]);
                if (possibleSyntacticHead != null)
                {
                    pdg.MoveDependencyEdge(possibleSyntacticHead.Index, node.Index);
                    nodeLifted[node.Index] = false;
                }
                else
                {
                    success = false;
                }
            }
            if (node.hasHead() && node.HeadEdge.Labeled && nodeLifted[node.Index])
            {
                possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.Head, node, synacticHeadDeprel[node.Index]);
                if (possibleSyntacticHead != null)
                {
                    pdg.MoveDependencyEdge(possibleSyntacticHead.Index, node.Index);
                    nodeLifted[node.Index] = false;
                }
                else
                {
                    success = false;
                }
            }
            while (!childSuccess && childAttempts > 0)
            {
                childSuccess = true;
                List <DependencyNode> children = new List <DependencyNode>();
                i = 0;
                while ((child = node.getLeftDependent(i)) != null)
                {
                    children.Add(child);
                    i++;
                }
                i = 0;
                while ((child = node.getRightDependent(i)) != null)
                {
                    children.Add(child);
                    i++;
                }
                for (i = 0; i < children.Count; i++)
                {
                    child = children[i];
                    if (!deprojectivizeWithHeadAndPath(pdg, child))
                    {
                        childSuccess = false;
                    }
                }
                childAttempts--;
            }
            return(childSuccess && success);
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean deprojectivizeWithHeadAndPath(org.maltparser.core.syntaxgraph.DependencyStructure pdg, org.maltparser.core.syntaxgraph.node.DependencyNode node, boolean[] nodeLifted, boolean[] nodePath, String[] synacticHeadDeprel, org.maltparser.core.symbol.SymbolTable deprelSymbolTable) throws org.maltparser.core.exception.MaltChainedException
        private bool deprojectivizeWithHeadAndPath(IDependencyStructure pdg, DependencyNode node, bool[] nodeLifted, bool[] nodePath, string[] synacticHeadDeprel, SymbolTable deprelSymbolTable)
        {
            bool           success = true, childSuccess = false;
            int            i, childAttempts = 2;
            DependencyNode possibleSyntacticHead;

            if (node.hasHead() && node.HeadEdge.Labeled && nodeLifted[node.Index] && nodePath[node.Index])
            {
                possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.Head, node, synacticHeadDeprel[node.Index], nodePath, deprelSymbolTable);
                if (possibleSyntacticHead != null)
                {
                    pdg.MoveDependencyEdge(possibleSyntacticHead.Index, node.Index);
                    nodeLifted[node.Index] = false;
                }
                else
                {
                    success = false;
                }
            }
            if (node.hasHead() && node.HeadEdge.Labeled && nodeLifted[node.Index])
            {
                possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.Head, node, synacticHeadDeprel[node.Index], nodePath, deprelSymbolTable);
                if (possibleSyntacticHead != null)
                {
                    pdg.MoveDependencyEdge(possibleSyntacticHead.Index, node.Index);
                    nodeLifted[node.Index] = false;
                }
                else
                {
                    success = false;
                }
            }
            while (!childSuccess && childAttempts > 0)
            {
                childSuccess = true;
                IList <DependencyNode> children = node.ListOfDependents;
                for (i = 0; i < children.Count; i++)
                {
                    if (!deprojectivizeWithHeadAndPath(pdg, children[i], nodeLifted, nodePath, synacticHeadDeprel, deprelSymbolTable))
                    {
                        childSuccess = false;
                    }
                }
                childAttempts--;
            }
            return(childSuccess && success);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void deattachCoveredRootsForProjectivization(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void deattachCoveredRootsForProjectivization(IDependencyStructure pdg)
        {
            foreach (int index in pdg.TokenIndices)
            {
                if (isCoveredRoot(pdg.GetTokenNode(index)))
                {
                    pdg.MoveDependencyEdge(pdg.DependencyRoot.Index, pdg.GetTokenNode(index).Index);
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
                    }
                }
            }
        }
Esempio n. 6
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);
        }