Ejemplo n.º 1
0
        public void TestTreeInsertParserTraining() {
            var parseSamples = ParserTestUtil.CreateParseTrainStream();
            var headRules = ParserTestUtil.CreateTestHeadRules();

            var model = SharpNL.Parser.TreeInsert.Parser.Train("en", parseSamples, headRules, 100, 0);

            var parser = ParserFactory.Create(model);

            // Tests parsing to make sure the code does not has
            // a bug which fails always with a runtime exception
           var p = parser.Parse(Parse.ParseParse("She was just another freighter from the " +
                   "States and she seemed as commonplace as her name ."));

            ParserModel deserialized;

            using (var data = new MemoryStream()) {
                model.Serialize(new UnclosableStream(data));

                data.Seek(0, SeekOrigin.Begin);

                deserialized = new ParserModel(data);
            }

            Assert.NotNull(deserialized);


            // TODO: compare both models
        }
Ejemplo n.º 2
0
        public void TestChunkingParserTraining() {

            var parseSamples = ParserTestUtil.CreateParseTestStream();
            //var testSamples = ParserTestUtil.CreateParseTestStream();
            var headRules = ParserTestUtil.CreateTestHeadRules();

            var model = SharpNL.Parser.Chunking.Parser.Train("en", parseSamples, headRules, 100, 0);

            Assert.NotNull(model);

            var parser = ParserFactory.Create(model);

            Assert.NotNull(parser);

            ParserModel deserialized;
            using (var stream = new MemoryStream()) {

                model.Serialize(new UnclosableStream(stream));

                stream.Seek(0, SeekOrigin.Begin);

                deserialized = new ParserModel(stream);
            }

            Assert.NotNull(deserialized);

            // TODO: compare both models
        }
Ejemplo n.º 3
0
        public static IParser Create(ParserModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            return(Create(model, AbstractBottomUpParser.DefaultBeamSize, AbstractBottomUpParser.DefaultAdvancePercentage));
        }
Ejemplo n.º 4
0
        public static IParser Create(ParserModel model, int beamSize, double advancePercentage) {
            if (model == null)
                throw new ArgumentNullException("model");

            switch (model.ParserType) {
                case ParserType.Chunking:
                    return new Chunking.Parser(model, beamSize, advancePercentage);
                case ParserType.TreeInsert:
                    return new TreeInsert.Parser(model, beamSize, advancePercentage);
                default:
                    throw new InvalidOperationException("Unexpected model parser.");
            }
        }
Ejemplo n.º 5
0
        public static IParser Create(ParserModel model, int beamSize, double advancePercentage)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            switch (model.ParserType)
            {
            case ParserType.Chunking:
                return(new Chunking.Parser(model, beamSize, advancePercentage));

            case ParserType.TreeInsert:
                return(new TreeInsert.Parser(model, beamSize, advancePercentage));

            default:
                throw new InvalidOperationException("Unexpected model parser.");
            }
        }
Ejemplo n.º 6
0
        public static IParser Create(ParserModel model) {
            if (model == null)
                throw new ArgumentNullException("model");

            return Create(model, AbstractBottomUpParser.DefaultBeamSize, AbstractBottomUpParser.DefaultAdvancePercentage);
        }