public static ParserConfiguration GetDefaultConfiguration()
        {
            var config = new ParserConfiguration();
            config.KeyValueSeparators = new string[] { ":", "=" };

            return config;
        }
        private IClassifier CreateClassifierFromConfiguration(ParserConfiguration configuration)
        {
            var parser = Activator.CreateInstance(configuration.Parser);
            var dataProcessor = Activator.CreateInstance(configuration.DataProcessor);

            var classifierType = typeof(ParserBasedClassifier<>).MakeGenericType(configuration.Data);
            return (IClassifier)Activator.CreateInstance(classifierType, parser, dataProcessor, classificationTypeService);
        }
예제 #3
0
파일: Parser.cs 프로젝트: sdkdevs/csly
        public virtual BuildResult <ParserConfiguration <IN, OUT> > BuildExpressionParser(
            BuildResult <Parser <IN, OUT> > result, string startingRule = null)
        {
            var exprResult = new BuildResult <ParserConfiguration <IN, OUT> >(Configuration);

            exprResult    = ExpressionRulesGenerator.BuildExpressionRules(Configuration, Instance.GetType(), exprResult);
            Configuration = exprResult.Result;
            SyntaxParser.Init(exprResult.Result, startingRule);
            if (startingRule != null)
            {
                Configuration.StartingRule       = startingRule;
                SyntaxParser.StartingNonTerminal = startingRule;
            }

            if (exprResult.IsError)
            {
                result.AddErrors(exprResult.Errors);
            }
            else
            {
                result.Result.Configuration = Configuration;
            }
            return(exprResult);
        }
예제 #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 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));
            }
        }
예제 #5
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));
            }
        }
예제 #6
0
 public Parser()
 {
     Configuration = ParserConfiguration.DefaultConfiguration;
 }
예제 #7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LumenWorksCsvParser{TRecord}" /> class.
 /// </summary>
 /// <param name="configuration">parser configuration</param>
 /// <param name="logger">injected logger</param>
 public LumenWorksCsvParser(ParserConfiguration configuration, ILogger logger)
     : base(configuration, logger)
 {
     Arguments.NotNull(configuration, nameof(configuration));
     Arguments.NotNull(logger, nameof(logger));
 }
예제 #8
0
 public PacketFactory(ParserConfiguration parserConfiguration)
 {
     _parserConfiguration = parserConfiguration;
     _observationPoint    = _parserConfiguration.ObservationPoint;
     _distanceCalculator  = new DistanceCalculator();
 }
예제 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.parser.history.action.GuideUserAction defaultAction(org.maltparser.parser.history.GuideUserHistory history, org.maltparser.parser.ParserConfiguration configuration) throws org.maltparser.core.exception.MaltChainedException
        public override GuideUserAction defaultAction(GuideUserHistory history, ParserConfiguration configuration)
        {
            return(updateActionContainers(history, 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 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);
        }
예제 #11
0
 public MapParser(ParserConfiguration conf)
 {
     configuration = conf;
 }
예제 #12
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)
        {
            return(null);
        }
예제 #13
0
 public NMEASentenceListener(ParserConfiguration parserConfiguration)
 {
     _port = parserConfiguration.ListenOnPort;
 }
예제 #14
0
        public Parser(ParserConfiguration configuration)
        {
            Guard.IsNotNull(() => configuration);

            Configuration = configuration;
        }
예제 #15
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));
            }
        }
예제 #16
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);
        }
예제 #17
0
 public RecipeScanner(ParserConfiguration config)
 {
     Configuration = config;
 }
예제 #18
0
        public void Write(IEnumerable <PropertyAttributeHolder <CommandVerbAttribute> > verbs, IEnumerable <PropertyAttributeHolder <CommandArgumentAttribute> > switches, ParserConfiguration conf)
        {
            if (switches == null)
            {
                throw new ArgumentNullException(nameof(switches));
            }

            var arguments = switches.OrderByDescending(prop => prop.Attribute.Required)
                            .Select(prop => new
            {
                Holder   = prop,
                ArgBrief =
                    $"{conf.LongSwitch}{prop.Property.Name}" +
                    (prop.Attribute.IsShortAvailable()
                                            ? $", {conf.ShortSwitch}{prop.Attribute.ShortName}"
                                            : string.Empty)
            }).ToList();

            var verbsSwitches = verbs
                                .Select(prop => new
            {
                Holder   = prop,
                ArgBrief =
                    !string.IsNullOrWhiteSpace(prop.Attribute.Name)
                        ? prop.Attribute.Name
                        : prop.Property.Name + " (verb) "
            }).ToList();

            var longestSwitch = arguments.Any() ? arguments.Max(p => p.ArgBrief.Length) : -1;

            const string inted = "   ";

            this.writer.WriteLine("Program arguments:");

            foreach (var verb in verbsSwitches)
            {
                var missingChars = longestSwitch - verb.ArgBrief.Length;

                this.writer.Write(inted);
                this.writer.Write(verb.ArgBrief);

                if (missingChars > 0)
                {
                    this.writer.Write(new string(' ', missingChars));
                }

                this.writer.Write(" ");
                this.writer.Write(verb.Holder.Attribute.Description);

                this.writer.WriteLine();
            }

            foreach (var argument in arguments)
            {
                var missingChars = longestSwitch - argument.ArgBrief.Length;

                this.writer.Write(inted);
                this.writer.Write(argument.ArgBrief);

                if (missingChars > 0)
                {
                    this.writer.Write(new string(' ', missingChars));
                }

                this.writer.Write(" ");

                if (!argument.Holder.Attribute.Required)
                {
                    this.writer.Write("(optional)");
                }

                this.writer.Write(" ");
                this.writer.Write(argument.Holder.Attribute.Description);

                this.writer.WriteLine();
            }
        }
예제 #19
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)
        {
            NivreConfig nivreConfig = (NivreConfig)config;

            if (!nivreConfig.AllowRoot && nivreConfig.Stack.Peek().Root)
            {
                return(updateActionContainers(history, SHIFT, null));
            }
            return(null);
        }
예제 #20
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);
        }
예제 #21
0
 public EBNFSyntaxTreeVisitor(ParserConfiguration <IN, OUT> conf, object parserInstance) : base(conf,
                                                                                                parserInstance)
 {
 }
예제 #22
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)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final NivreConfig nivreConfig = (NivreConfig)config;
            NivreConfig nivreConfig = (NivreConfig)config;

            if (!nivreConfig.EnforceTree)
            {
                if (!nivreConfig.AllowRoot && nivreConfig.Stack.Peek().Root)
                {
                    return(updateActionContainers(history, SHIFT, null));
                }
            }
            else
            {
                //Added
                if (!nivreConfig.AllowRoot && nivreConfig.Stack.Peek().Root&& !nivreConfig.End)
                {
                    return(updateActionContainers(history, SHIFT, null));
                }

                if (nivreConfig.Input.Count == 0 && nivreConfig.Stack.Peek().hasHead())
                {
                    return(updateActionContainers(history, REDUCE, null));
                }

                if (nivreConfig.Input.Count == 0 && !nivreConfig.Stack.Peek().hasHead())
                {
                    return(updateActionContainers(history, UNSHIFT, null));
                }
            }
            return(null);
        }
예제 #23
0
 public ParserAgent(IObjectFactory factory)
 {
     _factory        = factory;
     _configurations = _factory.GetInstance <IConfigurationManager>().ParserConfiguration;
 }
예제 #24
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)
        {
//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 java.util.Stack<org.maltparser.core.syntaxgraph.node.DependencyNode> stack = nivreConfig.getStack();
            Stack <DependencyNode> stack = nivreConfig.Stack;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Stack<org.maltparser.core.syntaxgraph.node.DependencyNode> input = nivreConfig.getInput();
            Stack <DependencyNode> input = nivreConfig.Input;

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

            if (!nivreConfig.EnforceTree)
            {
                switch (transActionContainer.ActionCode)
                {
                case LEFTARC:
                    e = nivreConfig.DependencyStructure.AddDependencyEdge(input.Peek().Index, stack.Peek().Index);
                    addEdgeLabels(e);
                    stack.Pop();
                    break;

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

                case REDUCE:
                    stack.Pop();
                    break;

                default:
                    stack.Push(input.Pop());
                    break;
                }
            }
            else
            {
                switch (transActionContainer.ActionCode)
                {
                case LEFTARC:
                    e = nivreConfig.DependencyStructure.AddDependencyEdge(input.Peek().Index, stack.Peek().Index);
                    addEdgeLabels(e);
                    stack.Pop();
                    break;

                case RIGHTARC:
                    e = nivreConfig.DependencyStructure.AddDependencyEdge(stack.Peek().Index, input.Peek().Index);
                    addEdgeLabels(e);
                    stack.Push(input.Pop());
                    if (input.Count == 0 && !nivreConfig.End)
                    {
                        nivreConfig.End = true;
                    }
                    break;

                case REDUCE:
                    stack.Pop();
                    break;

                case UNSHIFT:
                    input.Push(stack.Pop());
                    break;

                default:
                    stack.Push(input.Pop());

                    if (input.Count == 0 && !nivreConfig.End)
                    {
                        nivreConfig.End = true;
                    }

                    break;
                }
            }
        }
예제 #25
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)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final CovingtonConfig covingtonConfig = (CovingtonConfig)config;
            CovingtonConfig covingtonConfig = (CovingtonConfig)config;

            if (!covingtonConfig.AllowRoot && covingtonConfig.LeftTarget.Root)
            {
                return(updateActionContainers(history, NOARC, null));
            }
            return(null);
        }
        public void Parser_Received_Full_Recipe()
        {
            // Arrange
            var inputString = @"
description

a great recipe for chicken wings

ingredients

1 cup franks red hot
1 cup butter
1 cup bbq sauce
1 cup v8
1 lb chicken wings

instructions

1) mix redhot, butter, bbq sauce, and v8 together stirring frequently
2) bake, grill or deep fry chicken wings
3) coat chicken wings in sauce 
4) put wings on grill for a minute or two (optional)

";
            var recipeParserConfiguration = new ParserConfiguration {
                ReportExceptions = true
            };
            var recipeParser = new RecipeParser(recipeParserConfiguration);
            var recipe       = new Recipe
            {
                Description = "a great recipe for chicken wings",
                Steps       = new List <Step>
                {
                    new Step
                    {
                        Ordinal      = 1,
                        Instructions = "mix redhot, butter, bbq sauce, and v8 together stirring frequently"
                    },
                    new Step {
                        Ordinal = 2, Instructions = "bake, grill or deep fry chicken wings"
                    },
                    new Step {
                        Ordinal = 3, Instructions = "coat chicken wings in sauce"
                    },
                    new Step {
                        Ordinal = 4, Instructions = "put wings on grill for a minute or two (optional)"
                    }
                }
            };

            // Act
            var output = recipeParser.Parse(inputString);

            // Assert
            Assert.NotNull(output);
            Assert.Equal(ParseStatus.Succeeded, output.Status);
            Assert.Empty(output.Errors);
            Assert.NotEmpty(output.Output.Ingredients);
            Assert.NotEmpty(output.Output.Steps);
            Assert.Matches(recipe.Description, output.Output.Description);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 1).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 1).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 2).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 2).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 3).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 3).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 4).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 4).Instructions);
        }
 public EBNFRecursiveDescentSyntaxParser(ParserConfiguration <IN, OUT> configuration, string startingNonTerminal)
     : base(configuration, startingNonTerminal)
 {
 }
예제 #28
0
 public SyntaxTreeVisitor(ParserConfiguration <IN, OUT> conf, object parserInstance)
 {
     ParserClass            = ParserClass;
     Configuration          = conf;
     ParserVsisitorInstance = parserInstance;
 }
예제 #29
0
 public void Initialize()
 {
     ParserConfiguration = new ParserConfiguration();
 }