/// <summary> /// Runs the rules inherent in the MyLo schema in N3 format using a static Reasoner /// </summary> public void MyLoSchemaReasoner() { Graph schema = new Graph(); try { FileLoader.Load(schema, @"../../../MyLoSchema.n3"); } catch (RdfParseException parseEx) { Debug.WriteLine("Parser Error - reading MyLoSchema.n3"); Debug.WriteLine(parseEx.Message); } catch (RdfException rdfEx) { Debug.WriteLine("RDF Error - reading MyLoSchema.n3"); Debug.WriteLine(rdfEx.Message); } StaticRdfsReasoner reasoner = new StaticRdfsReasoner(); try { reasoner.Initialise(schema); foreach (IGraph g in _store.Graphs) { reasoner.Apply(g); } } catch (Exception rdfEx) { Debug.WriteLine("Rules Error - applying RDFS Reasoner"); Debug.WriteLine(rdfEx.Message); } }
public HttpResponseMessage InferredGet(string text, double latitude, double longitude) { UnionGraph resultsGraph = GetUnionGraph(); Graph outputGraph = new Graph(); //resultsGraph.NamespaceMap.AddNamespace("dbo", new Uri("http://dbpedia.org/ontology/")); Graph ontology = new Graph(); FileLoader.Load(ontology, System.AppDomain.CurrentDomain.BaseDirectory.ToString() + Constants.Ontology); StaticRdfsReasoner reasoner = new StaticRdfsReasoner(); reasoner.Initialise(ontology); reasoner.Apply(resultsGraph, outputGraph); Collection<BaprLocation> locations = ExtractResults(resultsGraph, GetInferredPlaces(outputGraph)); return Request.CreateResponse(HttpStatusCode.OK, locations); }
public void SparqlViewAndReasonerInteraction() { try { TripleStore store = new TripleStore(); SparqlView view = new SparqlView("CONSTRUCT { ?s a ?type } WHERE { ?s a ?type }", store); view.BaseUri = new Uri("http://example.org/view"); store.Add(view); Console.WriteLine("SPARQL View Empty"); TestTools.ShowGraph(view); Console.WriteLine(); //Load a Graph into the Store to cause the SPARQL View to update Graph g = new Graph(); FileLoader.Load(g, "InferenceTest.ttl"); g.BaseUri = new Uri("http://example.org/data"); store.Add(g); Thread.Sleep(200); if (view.Triples.Count == 0) view.UpdateView(); Console.WriteLine("SPARQL View Populated"); TestTools.ShowGraph(view); Console.WriteLine(); Assert.IsTrue(view.Triples.Count > 0, "View should have updated to contain some Triples"); int lastCount = view.Triples.Count; //Apply an RDFS reasoner StaticRdfsReasoner reasoner = new StaticRdfsReasoner(); reasoner.Initialise(g); store.AddInferenceEngine(reasoner); Thread.Sleep(200); if (view.Triples.Count == lastCount) view.UpdateView(); Console.WriteLine("SPARQL View Populated after Reasoner added"); TestTools.ShowGraph(view); } catch (RdfQueryException queryEx) { TestTools.ReportError("Query Error", queryEx, true); } catch (RdfException ex) { TestTools.ReportError("Error", ex, true); } }