コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void apply(org.maltparser.parser.history.action.GuideUserAction currentAction, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override void apply(GuideUserAction currentAction, ParserConfiguration config)
        {
            PlanarConfig           planarConfig = (PlanarConfig)config;
            Stack <DependencyNode> stack        = planarConfig.Stack;
            Stack <DependencyNode> input        = planarConfig.Input;

            currentAction.getAction(actionContainers);
            Edge e = null;

            switch (transActionContainer.ActionCode)
            {
            case LEFTARC:
                e = planarConfig.DependencyStructure.AddDependencyEdge(input.Peek().Index, stack.Peek().Index);
                addEdgeLabels(e);
                break;

            case RIGHTARC:
                e = planarConfig.DependencyStructure.AddDependencyEdge(stack.Peek().Index, input.Peek().Index);
                addEdgeLabels(e);
                break;

            case REDUCE:
                stack.Pop();
                break;

            default:             //SHIFT
                stack.Push(input.Pop());
                break;
            }
        }
コード例 #2
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));
            }
        }
コード例 #3
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)
            {
                PlanarConfig           planarConfig = (PlanarConfig)parserConfiguration;
                Stack <DependencyNode> sourceStack  = planarConfig.Stack;
                Stack <DependencyNode> sourceInput  = planarConfig.Input;
                DependencyGraph = planarConfig.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);
                    }
                }
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction getDeterministicAction(org.maltparser.parser.history.GuideUserHistory history, org.maltparser.parser.ParserConfiguration config) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config)
        {
            PlanarConfig planarConfig = (PlanarConfig)config;

            if (planarConfig.getRootHandling() != PlanarConfig.NORMAL && planarConfig.Stack.Peek().Root)
            {
                return(updateActionContainers(history, SHIFT, null));
            }
            return(null);
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void update(PlanarConfig config) throws org.maltparser.core.exception.MaltChainedException
        private void update(PlanarConfig config)
        {
            if (subFunction == PlanarSubFunction.STACK)
            {
                address.Address = config.getStackNode(index);
            }
            else if (subFunction == PlanarSubFunction.INPUT)
            {
                address.Address = config.getInputNode(index);
            }
            else
            {
                address.Address = null;
            }
        }
コード例 #6
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            PlanarConfig that = (PlanarConfig)obj;

            if (stack.Count != that.Stack.Count)
            {
                return(false);
            }
            if (input.Count != that.Input.Count)
            {
                return(false);
            }
            if (dependencyGraph.NEdges() != that.DependencyGraph.NEdges())
            {
                return(false);
            }
            for (int i = 0; i < stack.Count; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                if (stack.get(i).Index != that.Stack.get(i).Index)
                {
                    return(false);
                }
            }
            for (int i = 0; i < input.Count; i++)
            {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                if (input.get(i).Index != that.Input.get(i).Index)
                {
                    return(false);
                }
            }
            return(dependencyGraph.Edges.Equals(that.DependencyGraph.Edges));
        }
コード例 #7
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);
        }