Beispiel #1
0
        public void ParseTest()
        {
            DependencyParser parser = new DependencyParser();

            string[] input = new string[] {
                "1	از	_	PREP	PREP	_	12	VPP	_\t_",
                "2	نصایح	_	N	IANM	_",
                "3	باارزش	_	ADJ	AJP	_",
                "4	مولای	_	N	ANM	_",
                "5	متقیان	_	N	ANM	_",
                "6	حضرت	_	N	ANM	_",
                "7	علی	_	N	ANM	_",
                "8	(	_	PUNC	PUNC	_",
                "9	علیه‌السلام	_	N	IANM	_",
                "10	)	_	PUNC	PUNC	_",
                "11	پند	_	N	IANM	_",
                "12	بگیرید	_	V	ACT	_",
                "13	.	_	PUNC	PUNC	_",
            };
            var expected =
                "1	از	_	PREP	PREP	_	12	VPP	_	_\n"+
                "2	نصایح	_	N	IANM	_	1	POSDEP	_	_\n"+
                "3	باارزش	_	ADJ	AJP	_	2	MOZ	_	_\n"+
                "4	مولای	_	N	ANM	_	3	MOZ	_	_\n"+
                "5	متقیان	_	N	ANM	_	4	MOZ	_	_\n"+
                "6	حضرت	_	N	ANM	_	5	MOZ	_	_\n"+
                "7	علی	_	N	ANM	_	6	MOZ	_	_\n"+
                "8	(	_	PUNC	PUNC	_	7	MOZ	_	_\n"+
                "9	علیه‌السلام	_	N	IANM	_	8	POSDEP	_	_\n"+
                "10	)	_	PUNC	PUNC	_	9	PUNC	_	_\n"+
                "11	پند	_	N	IANM	_	7	APP	_	_\n"+
                "12	بگیرید	_	V	ACT	_	11	ROOT	_	_\n"+
                "13	.	_	PUNC	PUNC	_	12	PUNC	_	_\n";
            var graph  = parser.Parse(input);
            var actual = graph.toString();

            Assert.AreEqual(expected, actual, "Failed to stem of '" + input + "'");



            parser.Normalizer = new Normalizer();
            parser.Lemmatizer = new Lemmatizer();


            string inputSentence = "من به مدرسه رفته بودم.";

            expected = "1	من	من	PR	PR	_	4	SBJ	_	_\n"+
                       "2	به	به	PREP	PREP	_	4	VPP	_	_\n"+
                       "3	مدرسه	مدرسه	N	N	_	2	POSDEP	_	_\n"+
                       "4	رفته بودم	رفت#رو	V	V	_	0	ROOT	_	_\n"+
                       "5	.	.	PUNC	PUNC	_	4	PUNC	_	_\n";
            var iterator = parser.RawParse(inputSentence).GetEnumerator();

            iterator.MoveNext();
            graph  = iterator.Current;
            actual = graph.toString();


            Assert.AreEqual(expected, actual, "Failed to stem of '" + input + "'");
        }
Beispiel #2
0
        ///<summary>Creates a FilteredTable that wraps a table with the specified filter.</summary>
        public FilteredTable(ITable <TRow> table, Expression <Func <TRow, bool> > filter)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            typedTable   = table;
            untypedTable = (Table)table;

            dependency  = DependencyParser.GetDependencyTree(table.Schema, filter);
            this.filter = filter.Compile();
            dependency.Register(untypedTable);

            writableRows = typedTable.Rows.Where(this.filter).ToList();
            Rows         = new TypedReadOnlyRowCollection <TRow>(writableRows);

            dependency.RowInvalidated += Dependency_RowInvalidated;
            //The table handlers should be added after the dependency is created.
            //This way, changes to dependent columns in our table will be handled
            //by the dependency first, and the row will be added / removed before
            //we receive ValueChanged. The one drawback is that we will then fire
            //our ValueChanged immediately after RowAdded.
            Table.RowAdded     += Table_RowAdded;
            Table.RowRemoved   += Table_RowRemoved;
            Table.ValueChanged += Table_ValueChanged;
        }
Beispiel #3
0
        public CodeUnit(Dependency currentDependency, Dependency namespaceDependency, DependencyParser parser, bool isLibrary = false)
        {
            _namespaceDependency = namespaceDependency;
            _parser = parser;

            CurrentDependency = currentDependency;
            IsLibrary         = isLibrary;
        }
Beispiel #4
0
        public DependencyParseAnnotator(Properties properties)
        {
            string modelPath = PropertiesUtils.GetString(properties, "model", DependencyParser.DefaultModel);

            parser            = DependencyParser.LoadFromModelFile(modelPath, properties);
            nThreads          = PropertiesUtils.GetInt(properties, "testThreads", DefaultNthreads);
            maxTime           = PropertiesUtils.GetLong(properties, "sentenceTimeout", DefaultMaxtime);
            extraDependencies = MetaClass.Cast(properties.GetProperty("extradependencies", "NONE"), typeof(GrammaticalStructure.Extras));
        }
        internal override ICollection GetBuildResultVirtualPathDependencies()
        {
            DependencyParser parser = this.CreateDependencyParser();

            if (parser == null)
            {
                return(null);
            }
            parser.Init(base.VirtualPathObject);
            return(parser.GetVirtualPathDependencies());
        }
        public void ParseTest()
        {
            DependencyParser parser = new DependencyParser();
            string[] input = new string[] {
                "1	از	_	PREP	PREP	_	12	VPP	_\t_",
                "2	نصایح	_	N	IANM	_",
                "3	باارزش	_	ADJ	AJP	_",
                "4	مولای	_	N	ANM	_",
                "5	متقیان	_	N	ANM	_",
                "6	حضرت	_	N	ANM	_",
                "7	علی	_	N	ANM	_",
                "8	(	_	PUNC	PUNC	_",
                "9	علیه‌السلام	_	N	IANM	_",
                "10	)	_	PUNC	PUNC	_",
                "11	پند	_	N	IANM	_",
                "12	بگیرید	_	V	ACT	_",
                "13	.	_	PUNC	PUNC	_",
            };
            var expected =
                "1	از	_	PREP	PREP	_	12	VPP	_	_\n" +
                "2	نصایح	_	N	IANM	_	1	POSDEP	_	_\n" +
                "3	باارزش	_	ADJ	AJP	_	2	MOZ	_	_\n" +
                "4	مولای	_	N	ANM	_	3	MOZ	_	_\n" +
                "5	متقیان	_	N	ANM	_	4	MOZ	_	_\n" +
                "6	حضرت	_	N	ANM	_	5	MOZ	_	_\n" +
                "7	علی	_	N	ANM	_	6	MOZ	_	_\n" +
                "8	(	_	PUNC	PUNC	_	7	MOZ	_	_\n" +
                "9	علیه‌السلام	_	N	IANM	_	8	POSDEP	_	_\n" +
                "10	)	_	PUNC	PUNC	_	9	PUNC	_	_\n" +
                "11	پند	_	N	IANM	_	7	APP	_	_\n" +
                "12	بگیرید	_	V	ACT	_	11	ROOT	_	_\n" +
                "13	.	_	PUNC	PUNC	_	12	PUNC	_	_\n" ;
            var graph = parser.Parse(input);
            var actual = graph.toString();

            Assert.AreEqual(expected, actual, "Failed to stem of '" + input + "'");

            parser.Normalizer = new Normalizer();
            parser.Lemmatizer = new Lemmatizer();

            string inputSentence = "من به مدرسه رفته بودم.";
            expected = "1	من	من	PR	PR	_	4	SBJ	_	_\n" +
                        "2	به	به	PREP	PREP	_	4	VPP	_	_\n" +
                        "3	مدرسه	مدرسه	N	N	_	2	POSDEP	_	_\n" +
                        "4	رفته بودم	رفت#رو	V	V	_	0	ROOT	_	_\n" +
                        "5	.	.	PUNC	PUNC	_	4	PUNC	_	_\n";
            var iterator = parser.RawParse(inputSentence).GetEnumerator();
            iterator.MoveNext();
            graph = iterator.Current;
            actual = graph.toString();

            Assert.AreEqual(expected, actual, "Failed to stem of '" + input + "'");
        }
        public void ParseEscapedSpacesTest()
        {
            DependencyParser parser = new DependencyParser();

            parser.Parse(@"test.o: test.c my\ test.h my\ \test.h");
            List <string> expected = new List <string>();

            expected.Add(@"test.c");
            expected.Add(@"my test.h");
            expected.Add(@"my \test.h");
            CollectionAssert.AreEquivalent(expected, parser.Dependencies);
        }
		public void ForeignKeyColumnTest() {
			Expression<Func<Row, object>> func = r =>
				r.Field<Row>("Number") != null;

			var dep = DependencyParser.GetDependencyTree(PowersSchema, func);

			Assert.IsFalse(dep.RequiresDataContext);
			var srd = (SameRowDependency)dep;

			Assert.AreEqual(0, srd.NestedDependencies.Count);
			Assert.AreEqual(1, srd.DependentColumns.Count);
			Assert.AreEqual(PowersKeyColumn, srd.DependentColumns[0]);
		}
        public void ParseMultiLineTest()
        {
            DependencyParser parser = new DependencyParser();

            parser.Parse("test.o: test.c \\\n foo.h\\\n bar.h   baz.h");
            List <string> expected = new List <string>();

            expected.Add(@"test.c");
            expected.Add(@"foo.h");
            expected.Add(@"bar.h");
            expected.Add(@"baz.h");
            CollectionAssert.AreEquivalent(expected, parser.Dependencies);
        }
		public void ChildRowsTest() {
			Expression<Func<Row, object>> func = r =>
				r.ChildRows("Powers");

			var dep = DependencyParser.GetDependencyTree(NumbersSchema, func);

			Assert.IsTrue(dep.RequiresDataContext);
			var ad = (AggregateDependency)dep;

			Assert.AreEqual(1, ad.Dependencies.Count);

			var prd = (ChildRowDependency)ad.Dependencies[0];
			Assert.AreEqual(0, prd.NestedDependencies.Count);
			Assert.AreEqual(0, prd.DependentColumns.Count);
			Assert.AreEqual(PowersKeyColumn.ChildRelation, prd.ChildRelation);
		}
Beispiel #11
0
        static void Main(string[] args)
        {
            // Path to models extracted from `stanford-parser-3.5.0-models.jar`
            //var jarRoot = @"c:\models\stanford-parser-full-2014-10-31\stanford-parser-3.5.0-models";
            //var modelsDirectory = jarRoot + @"\edu\stanford\nlp\models";
            var modelsDirectory = PathToApplication + @"Resources\models";

            // Loading english PCFG parser from file
            //var lp = LexicalizedParser.loadModel(modelsDirectory + @"\lexparser\englishPCFG.ser.gz");

            // This sample shows parsing a list of correctly tokenized words

            /*var sent = new[] { "This", "is", "an", "easy", "sentence", "." };
             * var rawWords = Sentence.toCoreLabelList(sent);
             * var tree = lp.apply(rawWords);
             * tree.pennPrint();*/

            // This option shows loading and using an explicit tokenizer

            //Console.WriteLine("\n{0}\n", tdl);

            // Extract collapsed dependencies from parsed tree

            /*var tp = new TreePrint("typedDependenciesCollapsed");
             * tp.printTree(tree2);*/


            var sentences = new List <string>()
            {
                "He keeps barging in and asking stupid questions when I'm trying to work.",
                "If you bash your monitor about like that, it won't last long."
            };

            foreach (var sentence in sentences)
            {
                var deps = DependencyParser.ParseDepencyRelationshipsInSentence(sentence);
                Console.WriteLine(sentence);
                foreach (var dep in deps)
                {
                    Console.WriteLine(dep);
                }
                Console.WriteLine("----");
            }

            Console.WriteLine("======== END ==========");
            Console.ReadKey();
        }
Beispiel #12
0
        public void GetAllOperationCallsInFunctionTest1()
        {
            //Assert
            var              dir        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string           contents   = File.ReadAllText(dir + "\\TestData\\Functions1.apl").ToLower();
            DependencyParser parser     = new DependencyParser();
            FileReader       f          = new FileReader();
            var              tableNames = f.ReadTableNames();

            parser.TableNames = tableNames;

            //Act
            string        operation          = ConstantsClass.ParsingConstants.InsertString;
            List <string> tablesAndFunctions = parser.GetTableNames(contents, operation);

            //Asset
            Assert.Equal("ARTIKELTAXIERUNG", tablesAndFunctions[0].ToUpper());
        }
Beispiel #13
0
        public void CutFileOnCurrentFunctionAndRestTest1()
        {
            //Arrange
            var              dir        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string           contents   = File.ReadAllText(dir + "\\TestData\\Functions1.apl").ToLower();
            DependencyParser parser     = new DependencyParser();
            FileReader       f          = new FileReader();
            var              tableNames = f.ReadTableNames();

            parser.TableNames = tableNames;
            string functionText = "";

            //Act
            string operation = ConstantsClass.ParsingConstants.InsertString;

            parser.CutFileOnCurrentFunctionAndRest(ref contents, operation, ref functionText);

            Console.WriteLine(functionText);
        }
		public void ParentRowColumnTest() {
			Expression<Func<Row, object>> func = r =>
				((Row)r["Number"])["Number"].ToString() + (r.Field<Row>("Number").Field<bool>("IsEven") ? "/" : "-");

			var dep = DependencyParser.GetDependencyTree(PowersSchema, func);

			Assert.IsTrue(dep.RequiresDataContext);
			var srd = (SameRowDependency)dep;

			Assert.AreEqual(1, srd.NestedDependencies.Count);
			Assert.AreEqual(1, srd.DependentColumns.Count);
			Assert.AreEqual(PowersKeyColumn, srd.DependentColumns[0]);

			var prd = (ParentRowDependency)srd.NestedDependencies[0];
			Assert.AreEqual(0, prd.NestedDependencies.Count);
			Assert.AreEqual(PowersKeyColumn, prd.ParentColumn);

			Assert.IsTrue(NumbersSchema.Columns.SequenceEqual(prd.DependentColumns));
		}
		public void ChildRowsColumnTest() {
			Expression<Func<Row, object>> func = r =>
			-(int)r["Number"] + r.ChildRows("Powers").Last().Field<int>("Exponent") * r.ChildRows("Powers").Sum(p => (int)p["Value"] / p.Field<long>("Number"));

			var dep = DependencyParser.GetDependencyTree(NumbersSchema, func);

			Assert.IsTrue(dep.RequiresDataContext);
			var srd = (SameRowDependency)dep;

			Assert.AreEqual(1, srd.NestedDependencies.Count);
			Assert.AreEqual(1, srd.DependentColumns.Count);
			Assert.AreEqual(NumbersSchema.Columns[0], srd.DependentColumns[0]);

			var crd = (ChildRowDependency)srd.NestedDependencies[0];
			Assert.AreEqual(0, crd.NestedDependencies.Count);
			Assert.AreEqual(PowersKeyColumn.ChildRelation, crd.ChildRelation);

			Assert.IsTrue(PowersSchema.Columns.OrderBy(c => c.Name).SequenceEqual(crd.DependentColumns.OrderBy(c => c.Name)));
		}
        // static main method only
        public static void Main(string[] args)
        {
            string modelPath  = DependencyParser.DefaultModel;
            string taggerPath = "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger";

            for (int argIndex = 0; argIndex < args.Length;)
            {
                switch (args[argIndex])
                {
                case "-tagger":
                {
                    taggerPath = args[argIndex + 1];
                    argIndex  += 2;
                    break;
                }

                case "-model":
                {
                    modelPath = args[argIndex + 1];
                    argIndex += 2;
                    break;
                }

                default:
                {
                    throw new Exception("Unknown argument " + args[argIndex]);
                }
                }
            }
            string               text      = "I can almost always tell when movies use fake dinosaurs.";
            MaxentTagger         tagger    = new MaxentTagger(taggerPath);
            DependencyParser     parser    = DependencyParser.LoadFromModelFile(modelPath);
            DocumentPreprocessor tokenizer = new DocumentPreprocessor(new StringReader(text));

            foreach (IList <IHasWord> sentence in tokenizer)
            {
                IList <TaggedWord>   tagged = tagger.TagSentence(sentence);
                GrammaticalStructure gs     = parser.Predict(tagged);
                // Print typed dependencies
                log.Info(gs);
            }
        }
Beispiel #17
0
        public void GetTableFunctionsDictTest1()
        {
            //Assert
            var              dir        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string           contents   = File.ReadAllText(dir + "\\TestData\\Functions1.apl").ToLower();
            DependencyParser parser     = new DependencyParser();
            FileReader       f          = new FileReader();
            var              tableNames = f.ReadTableNames();

            parser.TableNames = tableNames;

            //Act
            string operation = ConstantsClass.ParsingConstants.InsertString;

            parser.FindTableOperations(operation, contents);
            var records = parser.RequestRecords;

            //Asset
            Assert.Single(records);
        }
Beispiel #18
0
        public void ParseDocumentTest1()
        {
            //Assert
            var              dir        = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string           contents   = File.ReadAllText(dir + "\\TestData\\artikel.apl").ToLower();
            DependencyParser parser     = new DependencyParser();
            FileReader       f          = new FileReader();
            var              tableNames = f.ReadTableNames();

            parser.TableNames = tableNames;

            //Act
            parser.ParseDocument(contents, "artikel");

            var tablesAndFunctions = parser.RequestRecords;



            //Asset
            Assert.NotEmpty(tablesAndFunctions);
        }
		public void NestedRelationTest() {
			Expression<Func<Row, object>> func = r =>
				from power in ((Row)r["Number"]).ChildRows("Powers")
				where (int)power["Exponent"] % 2 == 0
				select power.Field<int>("Value")
					 / power.Field<Row>("Number").ChildRows("Powers").Sum(p => p.Field<int>("Value"));

			var dep = DependencyParser.GetDependencyTree(PowersSchema, func);

			Assert.IsTrue(dep.RequiresDataContext);

			var srd = (SameRowDependency)dep;
			Assert.AreEqual(1, srd.NestedDependencies.Count);
			Assert.AreEqual(1, srd.DependentColumns.Count);
			Assert.AreEqual(PowersKeyColumn, srd.DependentColumns[0]);

			var prd = (ParentRowDependency)srd.NestedDependencies[0];	// ((Row)r["Number"]).
			Assert.AreEqual(0, prd.DependentColumns.Count);
			Assert.AreEqual(1, prd.NestedDependencies.Count);
			Assert.AreEqual(PowersKeyColumn, prd.ParentColumn);

			var crd = (ChildRowDependency)prd.NestedDependencies[0];	// ((Row)r["Number"]).ChildRows("Powers") (In from clause)
			Assert.AreEqual(1, crd.NestedDependencies.Count);
			Assert.AreEqual(PowersKeyColumn.ChildRelation, crd.ChildRelation);

			Assert.IsTrue(PowersSchema.Columns.OrderBy(c => c.Name).SequenceEqual(crd.DependentColumns.OrderBy(c => c.Name)));

			prd = (ParentRowDependency)crd.NestedDependencies[0];	// / power.Field<Row>("Number").
			Assert.AreEqual(0, prd.DependentColumns.Count);
			Assert.AreEqual(1, prd.NestedDependencies.Count);
			Assert.AreEqual(PowersKeyColumn, prd.ParentColumn);


			crd = (ChildRowDependency)prd.NestedDependencies[0];	// Field<Row>("Number").ChildRows("Powers") (in select clause)
			Assert.AreEqual(0, crd.NestedDependencies.Count);
			Assert.AreEqual(1, crd.DependentColumns.Count);
			Assert.AreEqual(PowersKeyColumn.ChildRelation, crd.ChildRelation);

			Assert.AreEqual(PowersSchema.Columns["Value"], crd.DependentColumns[0]);
		}
Beispiel #20
0
        public string Parsa_Oie(string text)
        {
            // first parse input sentence
            string parsedString = ParsPer.Parse(text);
            List <DependencyParseNode> parsedStructure = DependencyParser.LoadCoNLL09FormatSentence(parsedString);

            // then match OiePatterns to sentence
            List <OieRelation> relations = OieTreePattern.ExtractRelations(parsedStructure,
                                                                           ReadPatternsFile.ReadFromFile("c:\\Parsa-OIE-Patterns-Farsi.txt"));

            StringBuilder result = new StringBuilder();

            foreach (OieRelation relation in relations)
            {
                result.Append(string.Format("[{0},{1}] {5:0.000} ({2} <-> {3} <-> {4})\n",
                                            relation.matchedPatternLine, relation.matchedPatternIndex, relation.arg1, relation.arg2,
                                            relation.rel, relation.confidenceScore));
            }


            return(result.ToString());
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            var files = FileReader.ReadGuptaFiles();

            DependencyParser parser = new DependencyParser();
            FileReader       f      = new FileReader();
            var tableNames          = f.ReadTableNames();

            parser.TableNames = tableNames;

            foreach (var file in files)
            {
                parser.ParseDocument(file.Item1, file.Item2.ToLower());
            }



            foreach (var file in files)
            {
                Console.WriteLine(file.Item1);
                if (file.Item1 == "patimp")
                {
                    Console.WriteLine("Attention");
                    parser.FindFunctionCalls(file.Item1, file.Item2.ToLower());
                }
                else
                {
                    parser.FindFunctionCalls(file.Item1, file.Item2.ToLower());
                }
            }

            List <RequestRecord> records = parser.RequestRecords;

            WriteToFile(records);

            Console.WriteLine(@"Sucessfully parsed {0} files", files.Count);
            Console.ReadLine();
        }
Beispiel #22
0
        public void GetTableNameTest1()
        {
            //Assert
            var              dir      = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName;
            string           contents = File.ReadAllText(dir + "\\TestData\\Functions1.apl").ToLower();
            DependencyParser parser   = new DependencyParser();
            FileReader       f        = new FileReader();
            var              tables   = f.ReadTableNames();

            parser.TableNames = tables;
            string functionText = "";

            //Act
            string operation = ConstantsClass.ParsingConstants.InsertString;

            parser.CutFileOnCurrentFunctionAndRest(ref contents, operation, ref functionText);
            List <string> tableNames  = parser.GetTableNames(functionText, operation);
            string        functinName = parser.GetFunctionName(functionText);

            //Asset
            Assert.Equal("ARTIKELTAXIERUNG", tableNames[0].ToUpper());
            Assert.Equal("updateliefertax", functinName);
        }
Beispiel #23
0
        ///<summary>Adds a calculated column to the schema.</summary>
        ///<typeparam name="TValue">The type of the column's value.</typeparam>
        ///<typeparam name="TRow">The strongly-typed row used to calculate the column's value.</typeparam>
        ///<param name="name">The name of the column.</param>
        ///<param name="expression">An expression used to calculate the column's value.</param>
        public CalculatedColumn AddCalculatedColumn <TRow, TValue>(string name, Expression <Func <TRow, TValue> > expression) where TRow : Row
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            var compiled = expression.Compile();

            return(AddColumn(new CalculatedColumn(Schema, name, typeof(TValue), row => compiled((TRow)row), () => DependencyParser.GetDependencyTree(Schema, expression))));
        }