Exemple #1
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            TwoPlanarConfig that = (TwoPlanarConfig)obj;

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

            if (theConfig.getRootHandling() != TwoPlanarConfig.NORMAL && theConfig.ActiveStack.Peek().Root)
            {
                return(updateActionContainers(history, SHIFT, null));
            }
            return(null);
        }
Exemple #3
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)
        {
            TwoPlanarConfig        planarConfig  = (TwoPlanarConfig)config;
            Stack <DependencyNode> activeStack   = planarConfig.ActiveStack;
            Stack <DependencyNode> inactiveStack = planarConfig.InactiveStack;
            Stack <DependencyNode> input         = planarConfig.Input;

            currentAction.getAction(actionContainers);
            Edge e          = null;
            int  actionCode = transActionContainer.ActionCode;

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

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

            case SWITCH:
                planarConfig.switchStacks();
                if (planarConfig.reduceAfterSwitch())
                {
                    planarConfig.ActiveStack.Pop();
                }
                break;

            case REDUCE:
                activeStack.Pop();
                break;

            case REDUCEBOTH:
                activeStack.Pop();
                inactiveStack.Pop();
                break;

            default:             //SHIFT
                DependencyNode n = input.Pop();
                activeStack.Push(n);
                inactiveStack.Push(n);
                break;
            }
            planarConfig.LastAction = actionCode;
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.edge.Edge getFirstPendingLinkOnAnyPlane(TwoPlanarConfig config, org.maltparser.core.syntaxgraph.DependencyStructure gold) throws org.maltparser.core.exception.MaltChainedException
        private Edge getFirstPendingLinkOnAnyPlane(TwoPlanarConfig config, IDependencyStructure gold)
        {
            Edge e1    = getFirstPendingLinkOnActivePlane(config, gold);
            Edge e2    = getFirstPendingLinkOnInactivePlane(config, gold);
            int  left1 = Math.Min(e1.Source.Index, e1.Target.Index);
            int  left2 = Math.Min(e2.Source.Index, e2.Target.Index);

            if (left1 > left2)
            {
                return(e1);
            }
            else
            {
                return(e2);
            }
        }
Exemple #5
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);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void update(TwoPlanarConfig config) throws org.maltparser.core.exception.MaltChainedException
        private void update(TwoPlanarConfig config)
        {
            if (subFunction == TwoPlanarSubFunction.ACTIVESTACK)
            {
                address.Address = config.getActiveStackNode(index);
            }
            else if (subFunction == TwoPlanarSubFunction.INACTIVESTACK)
            {
                address.Address = config.getInactiveStackNode(index);
            }
            else if (subFunction == TwoPlanarSubFunction.INPUT)
            {
                address.Address = config.getInputNode(index);
            }
            else
            {
                address.Address = null;
            }
        }
Exemple #7
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)
            {
                TwoPlanarConfig planarConfig = (TwoPlanarConfig)parserConfiguration;
                activeStack = planarConfig.activeStack;
                Stack <DependencyNode> sourceActiveStack   = planarConfig.ActiveStack;
                Stack <DependencyNode> sourceInactiveStack = planarConfig.InactiveStack;
                Stack <DependencyNode> sourceInput         = planarConfig.Input;
                DependencyGraph = planarConfig.DependencyGraph;
                for (int i = 0, n = sourceActiveStack.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:
                    ActiveStack.Push(dependencyGraph.GetDependencyNode(sourceActiveStack.get(i).Index));
                }
                for (int i = 0, n = sourceInactiveStack.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:
                    InactiveStack.Push(dependencyGraph.GetDependencyNode(sourceInactiveStack.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
            {
                ActiveStack.Push(dependencyGraph.DependencyRoot);
                InactiveStack.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)
                    {
                        input.Push(node);
                    }
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Decides in which plane link e should be created.
        /// </summary>
        private int getLinkDecision(Edge e, TwoPlanarConfig config)
        {
            int constraint = getPlaneConstraint(e);

            if (constraint == ANY_PLANE)
            {
                //choose active plane
                if (config.StackActivityState == TwoPlanarConfig.FIRST_STACK)
                {
                    return(FIRST_PLANE);
                }
                else
                {
                    return(SECOND_PLANE);
                }
            }
            else
            {
                return(constraint);
            }
        }
Exemple #9
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);
        }
Exemple #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 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));
            }
        }
Exemple #11
0
        /// <summary>
        /// Gets the shortest pending link between (to or from) the input node and a node to the left of the top of the inactive stack,
        /// such that the link can be established on the inactive plane.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.edge.Edge getFirstPendingLinkOnInactivePlane(TwoPlanarConfig config, org.maltparser.core.syntaxgraph.DependencyStructure gold) throws org.maltparser.core.exception.MaltChainedException
        private Edge getFirstPendingLinkOnInactivePlane(TwoPlanarConfig config, IDependencyStructure gold)
        {
            return(getFirstPendingLinkOnPlane(config, gold, config.StackActivityState == TwoPlanarConfig.FIRST_STACK ? SECOND_PLANE : FIRST_PLANE, config.InactiveStack.Peek().Index));
        }