示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration configuration) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration configuration)
        {
            StackConfig            config = (StackConfig)configuration;
            Stack <DependencyNode> stack  = config.Stack;

            if (stack.Count < 2)
            {
                return(updateActionContainers(Projective.SHIFT, null));
            }
            else
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                DependencyNode left      = stack.get(stack.Count - 2);
                int            leftIndex = left.Index;
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                int rightIndex = stack.get(stack.Count - 1).Index;
                if (!left.Root && gold.GetTokenNode(leftIndex).Head.Index == rightIndex)
                {
                    return(updateActionContainers(Projective.LEFTARC, gold.GetTokenNode(leftIndex).HeadEdge.LabelSet));
                }
                else if (gold.GetTokenNode(rightIndex).Head.Index == leftIndex && checkRightDependent(gold, config.DependencyGraph, rightIndex))
                {
                    return(updateActionContainers(Projective.RIGHTARC, gold.GetTokenNode(rightIndex).HeadEdge.LabelSet));
                }
                else
                {
                    return(updateActionContainers(Projective.SHIFT, null));
                }                 // Solve the problem with non-projective input.
            }
        }
示例#2
0
 private bool nodeComplete(IDependencyStructure gold, IDependencyStructure parseDependencyGraph, int nodeIndex)
 {
     if (gold.GetTokenNode(nodeIndex).hasLeftDependent())
     {
         if (!parseDependencyGraph.GetTokenNode(nodeIndex).hasLeftDependent())
         {
             return(false);
         }
         else if (gold.GetTokenNode(nodeIndex).LeftmostDependent.Index != parseDependencyGraph.GetTokenNode(nodeIndex).LeftmostDependent.Index)
         {
             return(false);
         }
     }
     if (gold.GetTokenNode(nodeIndex).hasRightDependent())
     {
         if (!parseDependencyGraph.GetTokenNode(nodeIndex).hasRightDependent())
         {
             return(false);
         }
         else if (gold.GetTokenNode(nodeIndex).RightmostDependent.Index != parseDependencyGraph.GetTokenNode(nodeIndex).RightmostDependent.Index)
         {
             return(false);
         }
     }
     return(true);
 }
示例#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);
                }
            }
        }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration configuration) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration configuration)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StackConfig config = (StackConfig)configuration;
            StackConfig config = (StackConfig)configuration;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Stack<org.maltparser.core.syntaxgraph.node.DependencyNode> stack = config.getStack();
            Stack <DependencyNode> stack = config.Stack;

            if (!swapArrayActive)
            {
                createSwapArray(gold);
                swapArrayActive = true;
            }
            if (stack.Count < 2)
            {
                return(updateActionContainers(NonProjective.SHIFT, null));
            }
            else
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode left = stack.get(stack.size()-2);
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                DependencyNode left = stack.get(stack.Count - 2);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode right = stack.get(stack.size() - 1);
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                DependencyNode right = stack.get(stack.Count - 1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int leftIndex = left.getIndex();
                int leftIndex = left.Index;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int rightIndex = right.getIndex();
                int rightIndex = right.Index;
                if (swapArray[leftIndex] > swapArray[rightIndex] && necessarySwap(gold, config.DependencyGraph, right, config.Input))
                {
                    return(updateActionContainers(NonProjective.SWAP, null));
                }
                else if (!left.Root && gold.GetTokenNode(leftIndex).Head.Index == rightIndex && nodeComplete(gold, config.DependencyGraph, leftIndex))
                {
                    return(updateActionContainers(NonProjective.LEFTARC, gold.GetTokenNode(leftIndex).HeadEdge.LabelSet));
                }
                else if (gold.GetTokenNode(rightIndex).Head.Index == leftIndex && nodeComplete(gold, config.DependencyGraph, rightIndex))
                {
                    return(updateActionContainers(NonProjective.RIGHTARC, gold.GetTokenNode(rightIndex).HeadEdge.LabelSet));
                }
                else
                {
                    return(updateActionContainers(NonProjective.SHIFT, null));
                }
            }
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void update(CovingtonConfig covingtonConfig, int trans) throws org.maltparser.core.exception.MaltChainedException
        private void update(CovingtonConfig covingtonConfig, int trans)
        {
            if (trans == SHIFT || trans == RIGHTARC)
            {
                covingtonConfig.Right = covingtonConfig.Right + 1;
                covingtonConfig.Left  = covingtonConfig.Right - 1;
            }
            else
            {
                int leftstop = covingtonConfig.Leftstop;
                int left     = covingtonConfig.Left;
                if (trans == NOARC)
                {
                    IDependencyStructure dg       = covingtonConfig.DependencyStructure;
                    DependencyNode       leftNode = covingtonConfig.Input[covingtonConfig.Left];
                    if (dg.GetTokenNode(leftNode.Index) != null && dg.GetTokenNode(leftNode.Index).hasHead())
                    {
                        left = dg.GetTokenNode(leftNode.Index).Head.Index;
                    }
                    else
                    {
                        left = leftstop - 1;
                    }
                }
                else
                {
                    DependencyNode rightNode = covingtonConfig.RightTarget;
                    left--;
                    DependencyNode leftNode = null;
                    while (left >= leftstop)
                    {
                        leftNode = covingtonConfig.Input[left];
                        if (rightNode.findComponent().Index != leftNode.findComponent().Index)
                        {
                            break;
                        }
                        left--;
                    }
                }

                if (left < leftstop)
                {
                    covingtonConfig.Right = covingtonConfig.Right + 1;
                    covingtonConfig.Left  = covingtonConfig.Right - 1;
                }
                else
                {
                    covingtonConfig.Left = left;
                }
            }
        }
示例#6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean checkRightDependent(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.core.syntaxgraph.DependencyStructure parseDependencyGraph, int index) throws org.maltparser.core.exception.MaltChainedException
        private bool checkRightDependent(IDependencyStructure gold, IDependencyStructure parseDependencyGraph, int index)
        {
            if (gold.GetTokenNode(index).RightmostDependent == null)
            {
                return(true);
            }
            else if (parseDependencyGraph.GetTokenNode(index).RightmostDependent != null)
            {
                if (gold.GetTokenNode(index).RightmostDependent.Index == parseDependencyGraph.GetTokenNode(index).RightmostDependent.Index)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void copyPartialDependencyStructure(DependencyStructure sourceGraph, DependencyStructure targetGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void copyPartialDependencyStructure(IDependencyStructure sourceGraph, IDependencyStructure targetGraph)
        {
            SymbolTable partHead   = cachedSource.SymbolTables.getSymbolTable("PARTHEAD");
            SymbolTable partDeprel = cachedSource.SymbolTables.getSymbolTable("PARTDEPREL");

            if (partHead == null || partDeprel == null)
            {
                return;
            }
            SymbolTable deprel = cachedTarget.SymbolTables.getSymbolTable("DEPREL");

            foreach (int index in sourceGraph.TokenIndices)
            {
                DependencyNode snode = sourceGraph.GetTokenNode(index);
                DependencyNode tnode = targetGraph.GetTokenNode(index);
                if (snode != null && tnode != null)
                {
                    int    spartheadindex = int.Parse(snode.getLabelSymbol(partHead));
                    string spartdeprel    = snode.getLabelSymbol(partDeprel);
                    if (spartheadindex > 0)
                    {
                        Edge.Edge tedge = targetGraph.AddDependencyEdge(spartheadindex, snode.Index);
                        tedge.addLabel(deprel, spartdeprel);
                    }
                }
            }
        }
示例#8
0
        private bool nodeComplete(IDependencyStructure gold, IDependencyStructure parseDependencyGraph, int nodeIndex)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode goldNode = gold.getTokenNode(nodeIndex);
            DependencyNode goldNode = gold.GetTokenNode(nodeIndex);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode parseNode = parseDependencyGraph.getTokenNode(nodeIndex);
            DependencyNode parseNode = parseDependencyGraph.GetTokenNode(nodeIndex);

            if (goldNode.hasLeftDependent())
            {
                if (!parseNode.hasLeftDependent())
                {
                    return(false);
                }
                else if (goldNode.LeftmostDependent.Index != parseNode.LeftmostDependent.Index)
                {
                    return(false);
                }
            }
            if (goldNode.hasRightDependent())
            {
                if (!parseNode.hasRightDependent())
                {
                    return(false);
                }
                else if (goldNode.RightmostDependent.Index != parseNode.RightmostDependent.Index)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration config)
        {
            PlanarConfig         planarConfig = (PlanarConfig)config;
            IDependencyStructure dg           = planarConfig.DependencyGraph;
            DependencyNode       stackPeek    = planarConfig.Stack.Peek();
            int stackPeekIndex = stackPeek.Index;
            int inputPeekIndex = planarConfig.Input.Peek().Index;

            if (!stackPeek.Root && gold.GetTokenNode(stackPeekIndex).Head.Index == inputPeekIndex && !checkIfArcExists(dg, inputPeekIndex, stackPeekIndex))
            {
                return(updateActionContainers(Planar.LEFTARC, gold.GetTokenNode(stackPeekIndex).HeadEdge.LabelSet));
            }
            else if (gold.GetTokenNode(inputPeekIndex).Head.Index == stackPeekIndex && !checkIfArcExists(dg, stackPeekIndex, inputPeekIndex))
            {
                return(updateActionContainers(Planar.RIGHTARC, gold.GetTokenNode(inputPeekIndex).HeadEdge.LabelSet));
            }
            else if (gold.GetTokenNode(inputPeekIndex).hasLeftDependent() && gold.GetTokenNode(inputPeekIndex).LeftmostDependent.Index < stackPeekIndex)
            {
                return(updateActionContainers(Planar.REDUCE, null));
            }
            else if (gold.GetTokenNode(inputPeekIndex).Head.Index < stackPeekIndex && (!gold.GetTokenNode(inputPeekIndex).Head.Root || planarConfig.getRootHandling() == PlanarConfig.NORMAL))
            {
                return(updateActionContainers(Planar.REDUCE, null));
            }
            else
            {
                return(updateActionContainers(Planar.SHIFT, null));
            }
        }
示例#10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration configuration) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration configuration)
        {
            StackConfig            config = (StackConfig)configuration;
            Stack <DependencyNode> stack  = config.Stack;

            if (!swapArrayActive)
            {
                createSwapArray(gold);
                swapArrayActive = true;
            }
            GuideUserAction action = null;

            if (stack.Count < 2)
            {
                action = updateActionContainers(NonProjective.SHIFT, null);
            }
            else
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                DependencyNode left      = stack.get(stack.Count - 2);
                int            leftIndex = left.Index;
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                int rightIndex = stack.get(stack.Count - 1).Index;
                if (swapArray[leftIndex] > swapArray[rightIndex])
                {
                    action = updateActionContainers(NonProjective.SWAP, null);
                }
                else if (!left.Root && gold.GetTokenNode(leftIndex).Head.Index == rightIndex && nodeComplete(gold, config.DependencyGraph, leftIndex))
                {
                    action = updateActionContainers(NonProjective.LEFTARC, gold.GetTokenNode(leftIndex).HeadEdge.LabelSet);
                }
                else if (gold.GetTokenNode(rightIndex).Head.Index == leftIndex && nodeComplete(gold, config.DependencyGraph, rightIndex))
                {
                    action = updateActionContainers(NonProjective.RIGHTARC, gold.GetTokenNode(rightIndex).HeadEdge.LabelSet);
                }
                else
                {
                    action = updateActionContainers(NonProjective.SHIFT, null);
                }
            }
            return(action);
        }
示例#11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration config)
        {
            NivreConfig    nivreConfig    = (NivreConfig)config;
            DependencyNode stackPeek      = nivreConfig.Stack.Peek();
            int            stackPeekIndex = stackPeek.Index;
            int            inputPeekIndex = nivreConfig.Input.Peek().Index;

            if (!nivreConfig.AllowRoot && stackPeek.Root)
            {
                return(updateActionContainers(ArcStandard.SHIFT, null));
            }
            if (!stackPeek.Root && gold.GetTokenNode(stackPeekIndex).Head.Index == inputPeekIndex)
            {
                return(updateActionContainers(ArcStandard.LEFTARC, gold.GetTokenNode(stackPeekIndex).HeadEdge.LabelSet));
            }
            else if (gold.GetTokenNode(inputPeekIndex).Head.Index == stackPeekIndex && checkRightDependent(gold, nivreConfig.DependencyGraph, inputPeekIndex))
            {
                return(updateActionContainers(ArcStandard.RIGHTARC, gold.GetTokenNode(inputPeekIndex).HeadEdge.LabelSet));
            }
            else
            {
                return(updateActionContainers(ArcStandard.SHIFT, null));
            }
        }
示例#12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration config)
        {
            CovingtonConfig covingtonConfig  = (CovingtonConfig)config;
            DependencyNode  leftTarget       = covingtonConfig.LeftTarget;
            int             leftTargetIndex  = leftTarget.Index;
            int             rightTargetIndex = covingtonConfig.RightTarget.Index;

            if (!leftTarget.Root && gold.GetTokenNode(leftTargetIndex).Head.Index == rightTargetIndex)
            {
                return(updateActionContainers(NonProjective.LEFTARC, gold.GetTokenNode(leftTargetIndex).HeadEdge.LabelSet));
            }
            else if (gold.GetTokenNode(rightTargetIndex).Head.Index == leftTargetIndex)
            {
                return(updateActionContainers(NonProjective.RIGHTARC, gold.GetTokenNode(rightTargetIndex).HeadEdge.LabelSet));
            }
            else if (covingtonConfig.AllowShift == true && (!(gold.GetTokenNode(rightTargetIndex).hasLeftDependent() && gold.GetTokenNode(rightTargetIndex).LeftmostDependent.Index < leftTargetIndex) && !(gold.GetTokenNode(rightTargetIndex).Head.Index < leftTargetIndex && (!gold.GetTokenNode(rightTargetIndex).Head.Root || covingtonConfig.Leftstop == 0))))
            {
                return(updateActionContainers(NonProjective.SHIFT, null));
            }
            else
            {
                return(updateActionContainers(NonProjective.NOARC, null));
            }
        }
示例#13
0
        /// <summary>
        /// Gets the shortest pending link between (to or from) the input node and a node to the left of rightmostLimit, such that the link
        /// can be established on the given plane.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.edge.Edge getFirstPendingLinkOnPlane(TwoPlanarConfig config, org.maltparser.core.syntaxgraph.DependencyStructure gold, int plane, int rightmostLimit) throws org.maltparser.core.exception.MaltChainedException
        private Edge getFirstPendingLinkOnPlane(TwoPlanarConfig config, IDependencyStructure gold, int plane, int rightmostLimit)
        {
            TwoPlanarConfig planarConfig = (TwoPlanarConfig)config;
            //DependencyStructure dg = planarConfig.getDependencyGraph(); -> no need, if rightmostLimit is well chosen, due to algorithm invariants
            int inputPeekIndex = planarConfig.Input.Peek().Index;

            Edge current = null;
            int  maxIndex;

            if (planarConfig.getRootHandling() == TwoPlanarConfig.NORMAL)
            {
                maxIndex = -1;                 //count links from dummy root
            }
            else
            {
                maxIndex = 0;                 //do not count links from dummy root
            }

            if (gold.GetTokenNode(inputPeekIndex).hasLeftDependent() && gold.GetTokenNode(inputPeekIndex).LeftmostDependent.Index < rightmostLimit)
            {
                SortedSet <DependencyNode> dependents = gold.GetTokenNode(inputPeekIndex).LeftDependents;
                for (IEnumerator <DependencyNode> iterator = dependents.GetEnumerator(); iterator.MoveNext();)
                {
                    DependencyNode dependent = (DependencyNode)iterator.Current;
                    if (dependent.Index > maxIndex && dependent.Index < rightmostLimit && getLinkDecision(dependent.HeadEdge, config) == plane)
                    {
                        maxIndex = dependent.Index;
                        current  = dependent.HeadEdge;
                    }
                }
            }

            //at this point, current is the first left-pointing link, but we have to check right-pointing link as well

            //System.out.println("in" + inputPeekIndex + " rl" + rightmostLimit);
            if (gold.GetTokenNode(inputPeekIndex).Head.Index < rightmostLimit)
            {
                //System.out.println(":");
                if (gold.GetTokenNode(inputPeekIndex).Head.Index > maxIndex && getLinkDecision(gold.GetTokenNode(inputPeekIndex).HeadEdge, config) == plane)
                {
                    //System.out.println("::");
                    current = gold.GetTokenNode(inputPeekIndex).HeadEdge;
                }
            }

            return(current);
        }
示例#14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration config)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final NivreConfig nivreConfig = (NivreConfig)config;
            NivreConfig nivreConfig = (NivreConfig)config;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode stackPeek = nivreConfig.getStack().peek();
            DependencyNode stackPeek = nivreConfig.Stack.Peek();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int stackPeekIndex = stackPeek.getIndex();
            int stackPeekIndex = stackPeek.Index;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int inputPeekIndex = nivreConfig.getInput().peek().getIndex();
            int inputPeekIndex = nivreConfig.Input.Peek().Index;

            if (!stackPeek.Root && gold.GetTokenNode(stackPeekIndex).Head.Index == inputPeekIndex)
            {
                return(updateActionContainers(ArcEager.LEFTARC, gold.GetTokenNode(stackPeekIndex).HeadEdge.LabelSet));
            }
            else if (gold.GetTokenNode(inputPeekIndex).Head.Index == stackPeekIndex)
            {
                return(updateActionContainers(ArcEager.RIGHTARC, gold.GetTokenNode(inputPeekIndex).HeadEdge.LabelSet));
            }
            else if (!nivreConfig.AllowReduce && !stackPeek.hasHead())
            {
                return(updateActionContainers(ArcEager.SHIFT, null));
            }
            else if (gold.GetTokenNode(inputPeekIndex).hasLeftDependent() && gold.GetTokenNode(inputPeekIndex).LeftmostDependent.Index < stackPeekIndex)
            {
                return(updateActionContainers(ArcEager.REDUCE, null));
            }
            else if (gold.GetTokenNode(inputPeekIndex).Head.Index < stackPeekIndex && (!gold.GetTokenNode(inputPeekIndex).Head.Root || nivreConfig.AllowRoot))
            {
                return(updateActionContainers(ArcEager.REDUCE, null));
            }
            else
            {
                return(updateActionContainers(ArcEager.SHIFT, null));
            }
        }
示例#15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean permissible(org.maltparser.parser.history.action.GuideUserAction currentAction, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override bool permissible(GuideUserAction currentAction, ParserConfiguration config)
        {
            currentAction.getAction(actionContainers);
            int                  trans             = transActionContainer.ActionCode;
            TwoPlanarConfig      planarConfig      = (TwoPlanarConfig)config;
            DependencyNode       activeStackPeek   = planarConfig.ActiveStack.Peek();
            DependencyNode       inactiveStackPeek = planarConfig.InactiveStack.Peek();
            DependencyNode       inputPeek         = planarConfig.Input.Peek();
            IDependencyStructure dg = planarConfig.DependencyGraph;
            //int rootHandling = planarConfig.getRootHandling();
            bool singleHeadConstraint     = planarConfig.requiresSingleHead();
            bool noCoveredRootsConstraint = planarConfig.requiresNoCoveredRoots();
            bool acyclicityConstraint     = planarConfig.requiresAcyclicity();

            //boolean connectednessConstraintOnReduce = planarConfig.requiresConnectednessCheckOnReduce();
            //boolean connectednessConstraintOnShift = planarConfig.requiresConnectednessCheckOnShift();
            if ((trans == LEFTARC || trans == RIGHTARC) && !ActionContainersLabeled)
            {
                return(false);
            }
            //if ((trans == LEFTARC || trans == REDUCE) && stackPeek.isRoot()) {
            //	return false;
            //}
            if (trans == LEFTARC)
            {
                //avoid making root child of something
                if (activeStackPeek.Root)
                {
                    return(false);
                }
                //enforce single-head constraint if present
                if (activeStackPeek.hasHead() && singleHeadConstraint)
                {
                    return(false);
                }
                //avoid two links being created from and to the same node
                if (activeStackPeek.hasHead() && dg.GetTokenNode(activeStackPeek.Index).Head.Index == inputPeek.Index)
                {
                    return(false);
                }
                //enforce acyclicity constraint if present
                if (acyclicityConstraint && activeStackPeek.findComponent().Index == inputPeek.findComponent().Index)
                {
                    return(false);
                }
            }
            if (trans == RIGHTARC)
            {
                //enforce single-head constraint if present
                if (inputPeek.hasHead() && singleHeadConstraint)
                {
                    return(false);
                }
                //avoid two links being created from and to the same node
                if (inputPeek.hasHead() && dg.GetTokenNode(inputPeek.Index).Head.Index == activeStackPeek.Index)
                {
                    return(false);
                }
                //enforce acyclicity constraint if present
                if (acyclicityConstraint && activeStackPeek.findComponent().Index == inputPeek.findComponent().Index)
                {
                    return(false);
                }
            }
            if (trans == REDUCE)
            {
                //do not reduce the dummy root
                if (activeStackPeek.Root)
                {
                    return(false);
                }
                //enforce no-covered-roots constraint if present
                if (!activeStackPeek.hasHead() && noCoveredRootsConstraint)
                {
                    return(false);
                }
                //TODO does this line still make sense? (from Nivre arc-eager)
                //if ( !stackPeek.hasHead() && rootHandling == PlanarConfig.STRICT )
                //	return false;
                //enforce connectedness constraint if present

                /*
                 * if ( connectednessConstraintOnReduce )
                 * {
                 *      boolean path1 = ( stackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() );
                 *      boolean path2;
                 *      if ( planarConfig.getStack().size() < 2 ) path2=false;
                 *      else
                 *      {
                 *              DependencyNode stackPrev = planarConfig.getStack().get(planarConfig.getStack().size()-2);
                 *              path2 = stackPrev.findComponent().getIndex() == stackPeek.findComponent().getIndex();
                 *      }
                 *      return path1 || path2;
                 * }
                 */
            }
            if (trans == SHIFT)
            {
                /*
                 * if ( connectednessConstraintOnShift && planarConfig.getInput().size() == 1 ) //last word
                 * {
                 *      boolean path = ( planarConfig.getDependencyGraph().getTokenNode(1).findComponent().getIndex() == inputPeek.findComponent().getIndex() ); //require connection to 1st
                 *      return path;
                 * }
                 */
            }
            if (trans == REDUCEBOTH)
            {
                //do not reduce the dummy root
                if (activeStackPeek.Root || inactiveStackPeek.Root)
                {
                    return(false);
                }
                //enforce no-covered-roots constraint if present
                if ((!activeStackPeek.hasHead() || inactiveStackPeek.hasHead()) && noCoveredRootsConstraint)
                {
                    return(false);
                }

                //TODO remove this:
                //not using this transition at the moment, so
                return(false);
            }
            if (trans == SWITCH)
            {
                if (planarConfig.reduceAfterSwitch())
                {
                    if (inactiveStackPeek.Root)
                    {
                        return(false);
                    }
                    //enforce no-covered-roots constraint if present
                    if (!inactiveStackPeek.hasHead() && noCoveredRootsConstraint)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (planarConfig.LastAction == SWITCH)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean checkIfArcExists(org.maltparser.core.syntaxgraph.DependencyStructure dg, int index1, int index2) throws org.maltparser.core.exception.MaltChainedException
        private bool checkIfArcExists(IDependencyStructure dg, int index1, int index2)
        {
            return(dg.GetTokenNode(index2).hasHead() && dg.GetTokenNode(index2).Head.Index == index1);
        }
示例#17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean permissible(org.maltparser.parser.history.action.GuideUserAction currentAction, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override bool permissible(GuideUserAction currentAction, ParserConfiguration config)
        {
            currentAction.getAction(actionContainers);
            int                  trans        = transActionContainer.ActionCode;
            PlanarConfig         planarConfig = (PlanarConfig)config;
            DependencyNode       stackPeek    = planarConfig.Stack.Peek();
            DependencyNode       inputPeek    = planarConfig.Input.Peek();
            IDependencyStructure dg           = planarConfig.DependencyGraph;
            //int rootHandling = planarConfig.getRootHandling();
            bool singleHeadConstraint            = planarConfig.requiresSingleHead();
            bool noCoveredRootsConstraint        = planarConfig.requiresNoCoveredRoots();
            bool acyclicityConstraint            = planarConfig.requiresAcyclicity();
            bool connectednessConstraintOnReduce = planarConfig.requiresConnectednessCheckOnReduce();
            bool connectednessConstraintOnShift  = planarConfig.requiresConnectednessCheckOnShift();

            if ((trans == LEFTARC || trans == RIGHTARC) && !ActionContainersLabeled)
            {
                return(false);
            }
            //if ((trans == LEFTARC || trans == REDUCE) && stackPeek.isRoot()) {
            //	return false;
            //}
            if (trans == LEFTARC)
            {
                //avoid making root child of something
                if (stackPeek.Root)
                {
                    return(false);
                }
                //enforce single-head constraint if present
                if (stackPeek.hasHead() && singleHeadConstraint)
                {
                    return(false);
                }
                //avoid two links being created from and to the same node
                if (stackPeek.hasHead() && dg.GetTokenNode(stackPeek.Index).Head.Index == inputPeek.Index)
                {
                    return(false);
                }
                //enforce acyclicity constraint if present
                if (acyclicityConstraint && stackPeek.findComponent().Index == inputPeek.findComponent().Index)
                {
                    return(false);
                }
            }
            if (trans == RIGHTARC)
            {
                //enforce single-head constraint if present
                if (inputPeek.hasHead() && singleHeadConstraint)
                {
                    return(false);
                }
                //avoid two links being created from and to the same node
                if (inputPeek.hasHead() && dg.GetTokenNode(inputPeek.Index).Head.Index == stackPeek.Index)
                {
                    return(false);
                }
                //enforce acyclicity constraint if present
                if (acyclicityConstraint && stackPeek.findComponent().Index == inputPeek.findComponent().Index)
                {
                    return(false);
                }
            }
            if (trans == REDUCE)
            {
                //do not reduce the dummy root
                if (stackPeek.Root)
                {
                    return(false);
                }
                //enforce no-covered-roots constraint if present
                if (!stackPeek.hasHead() && noCoveredRootsConstraint)
                {
                    return(false);
                }
                //TODO does this line still make sense? (from Nivre arc-eager)
                //if ( !stackPeek.hasHead() && rootHandling == PlanarConfig.STRICT )
                //	return false;
                //enforce connectedness constraint if present
                if (connectednessConstraintOnReduce)
                {
                    bool path1 = (stackPeek.findComponent().Index == inputPeek.findComponent().Index);
                    bool path2;
                    if (planarConfig.Stack.Count < 2)
                    {
                        path2 = false;
                    }
                    else
                    {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                        DependencyNode stackPrev = planarConfig.Stack.get(planarConfig.Stack.Count - 2);
                        path2 = stackPrev.findComponent().Index == stackPeek.findComponent().Index;
                    }
                    return(path1 || path2);
                }
            }
            if (trans == SHIFT)
            {
                if (connectednessConstraintOnShift && planarConfig.Input.Count == 1)                                                     //last word
                {
                    bool path = (planarConfig.DependencyGraph.GetTokenNode(1).findComponent().Index == inputPeek.findComponent().Index); //require connection to 1st
                    return(path);
                }
            }
            return(true);
        }
示例#18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction predict(org.maltparser.core.syntaxgraph.DependencyStructure gold, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction predict(IDependencyStructure gold, ParserConfiguration config)
        {
            TwoPlanarConfig      planarConfig      = (TwoPlanarConfig)config;
            IDependencyStructure dg                = planarConfig.DependencyGraph;
            DependencyNode       activeStackPeek   = planarConfig.ActiveStack.Peek();
            DependencyNode       inactiveStackPeek = planarConfig.InactiveStack.Peek();
            int activeStackPeekIndex               = activeStackPeek.Index;
            int inactiveStackPeekIndex             = inactiveStackPeek.Index;
            int inputPeekIndex = planarConfig.Input.Peek().Index;

            //System.out.println("Initting crossings");

            if (crossingsGraph == null)
            {
                initCrossingsGraph(gold);
            }

            //System.out.println("Crossings initted");

            if (!activeStackPeek.Root && gold.GetTokenNode(activeStackPeekIndex).Head.Index == inputPeekIndex && !checkIfArcExists(dg, inputPeekIndex, activeStackPeekIndex))
            {
                if (planarConfig.StackActivityState == TwoPlanarConfig.FIRST_STACK)
                {
                    propagatePlaneConstraint(gold.GetTokenNode(activeStackPeekIndex).HeadEdge, FIRST_PLANE);
                }
                else
                {
                    propagatePlaneConstraint(gold.GetTokenNode(activeStackPeekIndex).HeadEdge, SECOND_PLANE);
                }
                //System.out.println("From " + inputPeekIndex + " to " + activeStackPeekIndex);
                return(updateActionContainers(TwoPlanar.LEFTARC, gold.GetTokenNode(activeStackPeekIndex).HeadEdge.LabelSet));
            }

            else if (gold.GetTokenNode(inputPeekIndex).Head.Index == activeStackPeekIndex && !checkIfArcExists(dg, activeStackPeekIndex, inputPeekIndex))
            {
                if (planarConfig.StackActivityState == TwoPlanarConfig.FIRST_STACK)
                {
                    propagatePlaneConstraint(gold.GetTokenNode(inputPeekIndex).HeadEdge, FIRST_PLANE);
                }
                else
                {
                    propagatePlaneConstraint(gold.GetTokenNode(inputPeekIndex).HeadEdge, SECOND_PLANE);
                }
                //System.out.println("From " + activeStackPeekIndex + " to " + inputPeekIndex);
                return(updateActionContainers(TwoPlanar.RIGHTARC, gold.GetTokenNode(inputPeekIndex).HeadEdge.LabelSet));
            }

            else if (!inactiveStackPeek.Root && gold.GetTokenNode(inactiveStackPeekIndex).Head.Index == inputPeekIndex && !checkIfArcExists(dg, inputPeekIndex, inactiveStackPeekIndex))
            {
                //need to create link, but on the other plane!!
                //TODO is this if branch really necessary? i.e. will this happen? (later branches already switch)
                //System.out.println("Switch one");
                return(updateActionContainers(TwoPlanar.SWITCH, null));
            }

            else if (gold.GetTokenNode(inputPeekIndex).Head.Index == inactiveStackPeekIndex && !checkIfArcExists(dg, inactiveStackPeekIndex, inputPeekIndex))
            {
                //need to create link, but on the other plane!!
                //TODO is this if branch really necessary? i.e. will this happen? (later branches already switch)
                //System.out.println("Switch two");
                return(updateActionContainers(TwoPlanar.SWITCH, null));
            }

            else if (getFirstPendingLinkOnActivePlane(planarConfig, gold) != null)
            {
                //System.out.println("Reduce one");
                return(updateActionContainers(TwoPlanar.REDUCE, null));
            }

            else if (getFirstPendingLinkOnInactivePlane(planarConfig, gold) != null)
            {
                //System.out.println("Switch for reducing");
                return(updateActionContainers(TwoPlanar.SWITCH, null));
            }

            //TODO: double reduce somehow? (check if reduced node is not covered by links of the other plane, or something like that).

            else
            {
                //System.out.println("Shift");
                return(updateActionContainers(TwoPlanar.SHIFT, null));
            }
        }
示例#19
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);
        }
示例#20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void splitArclabels(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        public virtual void splitArclabels(IDependencyStructure pdg)
        {
            int    pathLabelIndex = -1, movedLabelIndex = -1, coveredArcLabelIndex;
            string label;

            initDeprojeciviztion(pdg);
            foreach (int index in pdg.TokenIndices)
            {
                if (pdg.GetTokenNode(index).HeadEdge.hasLabel(deprelSymbolTable))
                {
                    label = deprelSymbolTable.getSymbolCodeToString(pdg.GetTokenNode(index).HeadEdge.getLabelCode(deprelSymbolTable));
                    if (!ReferenceEquals(label, null) && (pathLabelIndex = label.IndexOf("%", StringComparison.Ordinal)) != -1)
                    {
                        label = label.Substring(0, pathLabelIndex);
                        setLabel(pdg.GetTokenNode(index), label);
                        pdg.GetTokenNode(index).HeadEdge.addLabel(pppathSymbolTable, pppathSymbolTable.getSymbolStringToCode("#true#"));
                    }
                    if (!ReferenceEquals(label, null) && (movedLabelIndex = label.IndexOf("|", StringComparison.Ordinal)) != -1 && label.IndexOf("|null", StringComparison.Ordinal) == -1)
                    {
                        if (movedLabelIndex + 1 < label.Length)
                        {
                            pdg.GetTokenNode(index).HeadEdge.addLabel(ppliftedSymbolTable, ppliftedSymbolTable.getSymbolStringToCode(label.Substring(movedLabelIndex + 1)));
                        }
                        else
                        {
                            pdg.GetTokenNode(index).HeadEdge.addLabel(ppliftedSymbolTable, ppliftedSymbolTable.getSymbolStringToCode("#true#"));
                        }
                        label = label.Substring(0, movedLabelIndex);
                        setLabel(pdg.GetTokenNode(index), label);
                    }
                }
            }
            foreach (int index in pdg.TokenIndices)
            {
                if (pdg.GetTokenNode(index).HeadEdge.hasLabel(deprelSymbolTable))
                {
                    label = deprelSymbolTable.getSymbolCodeToString(pdg.GetTokenNode(index).HeadEdge.getLabelCode(deprelSymbolTable));
                    if ((coveredArcLabelIndex = label.IndexOf("|null", StringComparison.Ordinal)) != -1)
                    {
                        label = label.Substring(0, coveredArcLabelIndex);
                        setLabel(pdg.GetTokenNode(index), label);
                        pdg.GetTokenNode(index).HeadEdge.addLabel(ppcoveredRootSymbolTable, ppcoveredRootSymbolTable.getSymbolStringToCode("#true#"));
                    }
                }
            }
        }