private void RunTest(IFullTextIndexer indexer, String query, int expectedResults, bool exact) { this.EnsureTestData(); indexer.Index(this._dataset); indexer.Dispose(); //Build the SPARQL Query and parse it SparqlParameterizedString queryString = new SparqlParameterizedString(query); queryString.Namespaces = this.GetQueryNamespaces(); SparqlQuery q = this._parser.ParseFromString(queryString); SparqlFormatter formatter = new SparqlFormatter(q.NamespaceMap); Console.WriteLine("Parsed Query:"); Console.WriteLine(formatter.Format(q)); LuceneSearchProvider provider = new LuceneSearchProvider(LuceneTestHarness.LuceneVersion, LuceneTestHarness.Index); FullTextPropertyFunctionFactory factory = new FullTextPropertyFunctionFactory(); try { PropertyFunctionFactory.AddFactory(factory); q.AlgebraOptimisers = new IAlgebraOptimiser[] { new FullTextOptimiser(provider) }; Options.AlgebraOptimisation = true; LeviathanQueryProcessor processor = new LeviathanQueryProcessor(this._dataset); SparqlResultSet results = processor.ProcessQuery(q) as SparqlResultSet; if (results != null) { TestTools.ShowResults(results); if (exact) { Assert.Equal(expectedResults, results.Count); } else { Assert.True(expectedResults >= results.Count, "Got more results that the expected maximum"); } } else { Assert.True(false, "Did not get a SPARQL Result Set as expected"); } } finally { PropertyFunctionFactory.RemoveFactory(factory); provider.Dispose(); LuceneTestHarness.Index.Dispose(); } }
private void TestExtractPatterns(String query, int expectedPatterns, int expectedSubjArgs, int expectedObjArgs) { FullTextPropertyFunctionFactory factory = new FullTextPropertyFunctionFactory(); try { PropertyFunctionFactory.AddFactory(factory); SparqlParameterizedString queryString = new SparqlParameterizedString(query); queryString.Namespaces.AddNamespace("pf", new Uri(FullTextHelper.FullTextMatchNamespace)); SparqlQuery q = this._parser.ParseFromString(queryString); SparqlFormatter formatter = new SparqlFormatter(queryString.Namespaces); Console.WriteLine(formatter.Format(q)); Console.WriteLine(); List <IPropertyFunctionPattern> ps = PropertyFunctionHelper.ExtractPatterns(q.RootGraphPattern.TriplePatterns); Console.WriteLine(ps.Count + " Pattern(s) extracted"); foreach (IPropertyFunctionPattern propFunc in ps.Where(p => p.PropertyFunction is FullTextMatchPropertyFunction)) { Console.WriteLine("Match Variable: " + propFunc.SubjectArgs.First().ToString()); Console.WriteLine("Score Variable: " + (propFunc.SubjectArgs.Count() > 1 ? propFunc.SubjectArgs.Skip(1).First().ToString() : "N/A")); Console.WriteLine("Search Term: " + propFunc.ObjectArgs.First().ToString()); Console.WriteLine("Threshold/Limit: " + (propFunc.ObjectArgs.Count() > 1 ? propFunc.ObjectArgs.Skip(1).First().ToString() : "N/A")); Console.WriteLine("Limit: " + (propFunc.ObjectArgs.Count() > 2 ? propFunc.ObjectArgs.Skip(2).First().ToString() : "N/A")); Console.WriteLine(); if (expectedSubjArgs > 0) { Assert.Equal(expectedSubjArgs, propFunc.SubjectArgs.Count()); } if (expectedObjArgs > 0) { Assert.Equal(expectedObjArgs, propFunc.ObjectArgs.Count()); } } Assert.Equal(expectedPatterns, ps.Count); } finally { PropertyFunctionFactory.RemoveFactory(factory); } }