예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.maltparser.core.syntaxgraph.node.DependencyNode breadthFirstSearchSortedByDistanceForHeadAndPath(org.maltparser.core.syntaxgraph.DependencyStructure dg, org.maltparser.core.syntaxgraph.node.DependencyNode start, org.maltparser.core.syntaxgraph.node.DependencyNode avoid, String syntacticHeadDeprelCode) throws org.maltparser.core.exception.MaltChainedException
        private DependencyNode breadthFirstSearchSortedByDistanceForHeadAndPath(IDependencyStructure dg, DependencyNode start, DependencyNode avoid, string syntacticHeadDeprelCode)
        {
            DependencyNode        dependent;
            List <DependencyNode> nodes = new List <DependencyNode>(), newNodes = null, secondChance = new List <DependencyNode>();

            nodes.AddRange(findAllDependentsVectorSortedByDistanceToPProjNode(dg, start, avoid, true));
            while (nodes.Count > 0)
            {
                dependent = nodes.RemoveAt(0);
                if (((newNodes = findAllDependentsVectorSortedByDistanceToPProjNode(dg, dependent, avoid, true)).Count) == 0 && deprelSymbolTable.getSymbolCodeToString(dependent.HeadEdge.getLabelCode(deprelSymbolTable)).Equals(syntacticHeadDeprelCode))
                {
                    return(dependent);
                }
                nodes.AddRange(newNodes);
                if (deprelSymbolTable.getSymbolCodeToString(dependent.HeadEdge.getLabelCode(deprelSymbolTable)).Equals(syntacticHeadDeprelCode) && newNodes.Count != 0)
                {
                    secondChance.Add(dependent);
                }
            }
            if (secondChance.Count > 0)
            {
                return(secondChance[0]);
            }
            return(null);
        }
예제 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void initProjectivization(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void initProjectivization(IDependencyStructure pdg)
        {
            nodeLifted.Clear();
            nodeTrace.Clear();
            headDeprel.Clear();
            nodePath.Clear();
            isCoveredRoot_Renamed.Clear();
            nodeRelationLength.Clear();

            foreach (int index in pdg.DependencyIndices)
            {
                nodeLifted.Add(false);
                nodeTrace.Add(new List <DependencyNode>());
                headDeprel.Add(null);
                nodePath.Add(false);
                isCoveredRoot_Renamed.Add(false);
                if (ppliftedSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(ppliftedSymbolTable, ppliftedSymbolTable.getSymbolStringToCode("#false#"));
                }
                if (pppathSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(pppathSymbolTable, pppathSymbolTable.getSymbolStringToCode("#false#"));
                }
                if (ppcoveredRootSymbolTable != null && index != 0)
                {
                    pdg.GetDependencyNode(index).HeadEdge.LabelSet.put(ppcoveredRootSymbolTable, ppcoveredRootSymbolTable.getSymbolStringToCode("#false#"));
                }
            }
            computeRelationLength(pdg);
        }
예제 #3
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.
            }
        }
예제 #4
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)
        {
            CovingtonConfig      covingtonConfig = (CovingtonConfig)config;
            DependencyNode       leftTarget      = covingtonConfig.LeftTarget;
            DependencyNode       rightTarget     = covingtonConfig.RightTarget;
            IDependencyStructure dg = covingtonConfig.DependencyGraph;

            currentAction.getAction(actionContainers);
            int trans = transActionContainer.ActionCode;

            if (trans == SHIFT && covingtonConfig.AllowShift == false)
            {
                return(false);
            }
            if ((trans == LEFTARC || trans == RIGHTARC) && !ActionContainersLabeled)
            {
                return(false);
            }
            if (trans == LEFTARC && leftTarget.Root)
            {
                return(false);
            }
            if (trans == LEFTARC && dg.HasLabeledDependency(leftTarget.Index))
            {
                return(false);
            }
            if (trans == RIGHTARC && dg.HasLabeledDependency(rightTarget.Index))
            {
                return(false);
            }
            return(true);
        }
예제 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public int process(int signal) throws org.maltparser.core.exception.MaltChainedException
        public override int process(int signal)
        {
            if (taskName.Equals("process"))
            {
                if (cachedSourceGraph == null)
                {
                    cachedSourceGraph = (IDependencyStructure)flowChartinstance.getFlowChartRegistry(typeof(IDependencyStructure), sourceName);
                }
                if (cachedTargetGraph == null)
                {
                    cachedTargetGraph = (IDependencyStructure)flowChartinstance.getFlowChartRegistry(typeof(IDependencyStructure), targetName);
                }
                if (modeName.Equals("learn"))
                {
                    singleMalt.OracleParse(cachedSourceGraph, cachedTargetGraph);
                }
                else if (modeName.Equals("parse"))
                {
                    singleMalt.Parse(cachedSourceGraph);
                    //				if (cachedSourceGraph instanceof MappablePhraseStructureGraph) {
                    //					System.out.println("MappablePhraseStructureGraph");
                    //					((MappablePhraseStructureGraph)cachedSourceGraph).getMapping().connectUnattachedSpines((MappablePhraseStructureGraph)cachedSourceGraph);
                    //				}
                }
            }
            return(signal);
        }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.DependencyStructure parse(org.maltparser.core.syntaxgraph.DependencyStructure goldDependencyGraph, org.maltparser.core.syntaxgraph.DependencyStructure parseDependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        public override IDependencyStructure parse(IDependencyStructure goldDependencyGraph, IDependencyStructure parseDependencyGraph)
        {
            parserState.clear();
            parserState.initialize(parseDependencyGraph);
            currentParserConfiguration = parserState.Configuration;

            TransitionSystem transitionSystem = parserState.TransitionSystem;

            while (!parserState.TerminalState)
            {
                GuideUserAction action = transitionSystem.getDeterministicAction(parserState.History, currentParserConfiguration);
                if (action == null)
                {
                    action = oracleGuide.predict(goldDependencyGraph, currentParserConfiguration);
                    try
                    {
                        classifierGuide.addInstance(featureModel, (GuideDecision)action);
                    }
                    catch (System.NullReferenceException e)
                    {
                        throw new MaltChainedException("The guide cannot be found. ", e);
                    }
                }
                parserState.apply(action);
            }
            CopyEdges(currentParserConfiguration.DependencyGraph, parseDependencyGraph);
            parseDependencyGraph.LinkAllTreesToRoot();
            oracleGuide.finalizeSentence(parseDependencyGraph);
            return(parseDependencyGraph);
        }
예제 #7
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));
            }
        }
예제 #8
0
        /// <summary>
        /// Same as parse(String[] tokens), but instead it returns an array of tokens with a head index and a dependency type at the end of string
        /// </summary>
        /// <param name="tokens"> an array of tokens to parse </param>
        /// <returns> an array of tokens with a head index and a dependency type at the end of string </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String[] parseTokens(String[] tokens) throws org.maltparser.core.exception.MaltChainedException
        public virtual string[] parseTokens(string[] tokens)
        {
            IDependencyStructure outputGraph = parse(tokens);
            StringBuilder        sb          = new StringBuilder();

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

            foreach (int?index in outputGraph.TokenIndices)
            {
                sb.Length = 0;
                if (index <= tokens.Length)
                {
                    DependencyNode node = outputGraph.GetDependencyNode(index.Value);
                    sb.Append(tokens[index - 1]);
                    sb.Append('\t');
                    sb.Append(node.Head.Index);
                    sb.Append('\t');
                    if (node.HeadEdge.hasLabel(deprelTable))
                    {
                        sb.Append(node.HeadEdge.getLabelSymbol(deprelTable));
                    }
                    else
                    {
                        sb.Append(outputGraph.GetDefaultRootEdgeLabelSymbol(deprelTable));
                    }
                    outputTokens[index - 1] = sb.ToString();
                }
            }
            return(outputTokens);
        }
예제 #9
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);
                    }
                }
            }
        }
예제 #10
0
        private void initCrossingsGraph(IDependencyStructure dg)
        {
            crossingsGraph = new IdentityHashMap <Edge, IList <Edge> >();
            SortedSet <Edge> edges = dg.Edges;

            //System.out.println(edges.size());
            //System.out.println(dg.nEdges());
            for (IEnumerator <Edge> iterator1 = edges.GetEnumerator(); iterator1.MoveNext();)
            {
                Edge edge1 = iterator1.Current;
                for (IEnumerator <Edge> iterator2 = edges.GetEnumerator(); iterator2.MoveNext();)
                {
                    Edge edge2 = iterator2.Current;
                    if (edge1.Source.Index < edge2.Source.Index && cross(edge1, edge2))
                    {
                        //System.out.println("Crossing!");
                        IList <Edge> crossingEdge1 = crossingsGraph[edge1];
                        if (crossingEdge1 == null)
                        {
                            crossingEdge1         = new LinkedList <Edge>();
                            crossingsGraph[edge1] = crossingEdge1;
                        }
                        crossingEdge1.Add(edge2);
                        IList <Edge> crossingEdge2 = crossingsGraph[edge2];
                        if (crossingEdge2 == null)
                        {
                            crossingEdge2         = new LinkedList <Edge>();
                            crossingsGraph[edge2] = crossingEdge2;
                        }
                        crossingEdge2.Add(edge1);
                    }
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.syntaxgraph.DependencyStructure parse(org.maltparser.core.syntaxgraph.DependencyStructure parseDependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        public override IDependencyStructure Parse(IDependencyStructure parseDependencyGraph)
        {
            parserState.clear();
            parserState.initialize(parseDependencyGraph);
            currentParserConfiguration = parserState.Configuration;
            parseCount++;

            diagnostics.writeToDiaFile(parseCount + "");
            while (!parserState.TerminalState)
            {
                GuideUserAction action = parserState.TransitionSystem.getDeterministicAction(parserState.History, currentParserConfiguration);
                if (action == null)
                {
                    action = predict();
                }
                else
                {
                    diagnostics.writeToDiaFile(" *");
                }

                diagnostics.writeToDiaFile(" " + parserState.TransitionSystem.getActionString(action));

                parserState.apply(action);
            }
            CopyEdges(currentParserConfiguration.DependencyGraph, parseDependencyGraph);
            CopyDynamicInput(currentParserConfiguration.DependencyGraph, parseDependencyGraph);
            parseDependencyGraph.LinkAllTreesToRoot();

            diagnostics.writeToDiaFile("\n");

            return(parseDependencyGraph);
        }
예제 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void initialize(org.maltparser.parser.ParserConfiguration parserConfiguration) throws org.maltparser.core.exception.MaltChainedException
        public virtual void initialize(ParserConfiguration parserConfiguration)
        {
            if (parserConfiguration != null)
            {
                StackConfig            config      = (StackConfig)parserConfiguration;
                Stack <DependencyNode> sourceStack = config.Stack;
                Stack <DependencyNode> sourceInput = config.Input;
                DependencyGraph = config.DependencyGraph;
                for (int i = 0, n = sourceStack.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    stack.Push(dependencyGraph.GetDependencyNode(sourceStack.get(i).Index));
                }
                for (int i = 0, n = sourceInput.Count; i < n; i++)
                {
//JAVA TO C# CONVERTER TODO TASK: There is no direct .NET Stack equivalent to Java Stack methods based on internal indexing:
                    input.Push(dependencyGraph.GetDependencyNode(sourceInput.get(i).Index));
                }
            }
            else
            {
                stack.Push(dependencyGraph.DependencyRoot);
                for (int i = dependencyGraph.HighestTokenIndex; i > 0; i--)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.core.syntaxgraph.node.DependencyNode node = dependencyGraph.getDependencyNode(i);
                    DependencyNode node = dependencyGraph.GetDependencyNode(i);
                    if (node != null && !node.hasHead())
                    {
                        input.Push(node);
                    }
                }
            }
        }
예제 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void process(Object[] arguments) throws org.maltparser.core.exception.MaltChainedException
        public virtual void process(object[] arguments)
        {
            if (mode == LEARN)
            {
                if (arguments.Length < 2 || !(arguments[0] is IDependencyStructure) || !(arguments[1] is IDependencyStructure))
                {
                    throw new MaltChainedException("The single malt learn task must be supplied with at least two dependency structures. ");
                }
                IDependencyStructure systemGraph = (IDependencyStructure)arguments[0];
                IDependencyStructure goldGraph   = (IDependencyStructure)arguments[1];
                if (systemGraph.HasTokens() && Guide != null)
                {
                    Guide.finalizeSentence(((Trainer)Algorithm).parse(goldGraph, systemGraph));
                }
            }
            else if (mode == PARSE)
            {
                if (arguments.Length < 1 || !(arguments[0] is IDependencyStructure))
                {
                    throw new MaltChainedException("The single malt parse task must be supplied with at least one input terminal structure and one output dependency structure. ");
                }
                IDependencyStructure processGraph = (IDependencyStructure)arguments[0];
                if (processGraph.HasTokens())
                {
                    parser.Parse(processGraph);
                    //				((Parser)getAlgorithm()).parse(processGraph);
                }
            }
        }
예제 #14
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);
 }
예제 #15
0
        //	public void updateFeatureModel() throws MaltChainedException {
        //		featureModel.update();
        //	}

//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void finalizeSentence(org.maltparser.core.syntaxgraph.DependencyStructure dependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void finalizeSentence(IDependencyStructure dependencyGraph)
        {
            if (instanceModel != null)
            {
                instanceModel.finalizeSentence(dependencyGraph);
            }
        }
예제 #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void finalizeSentence(org.maltparser.core.syntaxgraph.DependencyStructure dependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void finalizeSentence(IDependencyStructure dependencyGraph)
        {
            if (decisionModel != null)
            {
                decisionModel.finalizeSentence(dependencyGraph);
            }
        }
예제 #17
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);
        }
예제 #18
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);
        }
예제 #19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void parse(org.maltparser.core.syntaxgraph.DependencyStructure graph) throws org.maltparser.core.exception.MaltChainedException
        public void Parse(IDependencyStructure graph)
        {
            if (graph.HasTokens())
            {
                LWDeterministicParser parser = new LWDeterministicParser(this, graph.SymbolTables);
                parser.parse(graph);
            }
        }
예제 #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void parse(org.maltparser.core.syntaxgraph.DependencyStructure graph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void Parse(IDependencyStructure graph)
        {
            if (graph.HasTokens())
            {
                //			((Parser)getAlgorithm()).parse(graph);
                parser.Parse(graph);
            }
        }
예제 #21
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void computeRelationLength(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void computeRelationLength(IDependencyStructure pdg)
        {
            nodeRelationLength.Add(0);
            foreach (int index in pdg.TokenIndices)
            {
                nodeRelationLength.Add(Math.Abs(pdg.GetDependencyNode(index).Index - pdg.GetDependencyNode(index).Head.Index));
            }
        }
예제 #22
0
        /// <summary>
        /// Creates a immutable dependency graph
        /// </summary>
        /// <param name="dataFormat"> a data format that describes the label types (or the columns in the input and output) </param>
        /// <param name="sourceGraph"> a dependency graph that implements the interface org.maltparser.core.syntaxgraph.DependencyStructure </param>
        /// <param name="defaultRootLabel"> the default root label </param>
        /// <exception cref="MaltChainedException"> </exception>
        public ConcurrentDependencyGraph(DataFormat.DataFormat dataFormat, IDependencyStructure sourceGraph, string defaultRootLabel)
        {
            DataFormat = dataFormat;

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

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

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

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

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

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

                            if (gNode.HeadEdge.hasLabel(sourceTable))
                            {
                                columns[i] = gNode.HeadEdge.getLabelSymbol(sourceTable);
                            }
                            else
                            {
                                columns[i] = defaultRootLabel;
                            }
                        }
                        else
                        {
                            columns[i] = "_";
                        }
                    }
                }
                nodes[index] = new ConcurrentDependencyNode(this, index, columns);
            }
        }
예제 #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void createSwapArray(org.maltparser.core.syntaxgraph.DependencyStructure goldDependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        private void createSwapArray(IDependencyStructure goldDependencyGraph)
        {
            swapArray.Clear();
            for (int i = 0; i <= goldDependencyGraph.HighestDependencyNodeIndex; i++)
            {
                swapArray.Add(new int?(i));
            }
            createSwapArray(goldDependencyGraph.DependencyRoot, 0);
        }
예제 #24
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);
                }
            }
        }
예제 #25
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void assignPseudoProjectiveDeprels(org.maltparser.core.syntaxgraph.DependencyStructure pdg) throws org.maltparser.core.exception.MaltChainedException
        private void assignPseudoProjectiveDeprels(IDependencyStructure pdg)
        {
            int newLabelCode;

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

                    if (markingStrategy == PseudoProjectiveEncoding.PATH || markingStrategy == PseudoProjectiveEncoding.HEADPATH)
                    {
                        if (nodePath[index])
                        {
                            newLabelCode = pppathSymbolTable.getSymbolStringToCode("#true#");
                        }
                        else
                        {
                            newLabelCode = pppathSymbolTable.getSymbolStringToCode("#false#");
                        }
                        pdg.GetDependencyNode(index).HeadEdge.addLabel(pppathSymbolTable, newLabelCode);
                    }
                }
                else if (!(rootAttachment == CoveredRootAttachment.NONE || rootAttachment == CoveredRootAttachment.IGNORE))
                {
                    pdg.GetDependencyNode(index).HeadEdge.addLabel(ppcoveredRootSymbolTable, ppcoveredRootSymbolTable.getSymbolStringToCode("#true#"));
                }
            }
        }
예제 #26
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void finalizeSentence(org.maltparser.core.syntaxgraph.DependencyStructure dependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        public virtual void finalizeSentence(IDependencyStructure dependencyGraph)
        {
            try
            {
                method.finalizeSentence(dependencyGraph);
            }
            catch (NullReferenceException e)
            {
                throw new GuideException("The learner cannot be found. ", e);
            }
        }
예제 #27
0
 private void initDeprojeciviztion(IDependencyStructure pdg)
 {
     nodeLifted.Clear();
     nodePath.Clear();
     synacticHeadDeprel.Clear();
     foreach (int index in pdg.DependencyIndices)
     {
         nodeLifted.Add(false);
         nodePath.Add(false);
         synacticHeadDeprel.Add(null);
     }
 }
예제 #28
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);
        }
예제 #29
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));
                }
            }
        }
예제 #30
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void createSwapArray(org.maltparser.core.syntaxgraph.DependencyStructure goldDependencyGraph) throws org.maltparser.core.exception.MaltChainedException
        private void createSwapArray(IDependencyStructure goldDependencyGraph)
        {
            swapArray.Clear();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int n = goldDependencyGraph.getHighestDependencyNodeIndex();
            int n = goldDependencyGraph.HighestDependencyNodeIndex;

            for (int i = 0; i <= n; i++)
            {
                swapArray.Add(new int?(i));
            }
            createSwapArray(goldDependencyGraph.DependencyRoot, 0);
        }