public void OntologyDomainAndRangeOfClassManual() { OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); //Get the Class of interest OntologyClass cls = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Vehicle")); //Find Triples where Predicate is rdfs:range or rdfs:domain and the Object is the Class IUriNode rdfsRange = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "range")); IUriNode rdfsDomain = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "domain")); List <OntologyProperty> ranges = new List <OntologyProperty>(); List <OntologyProperty> domains = new List <OntologyProperty>(); foreach (Triple t in cls.TriplesWithObject) { if (t.Predicate.Equals(rdfsRange)) { ranges.Add(new OntologyProperty(t.Subject, g)); } else if (t.Predicate.Equals(rdfsDomain)) { domains.Add(new OntologyProperty(t.Subject, g)); } } //Do whatever you want with the Ranges and Domains... Console.WriteLine("Ranges"); foreach (OntologyProperty range in ranges) { Console.WriteLine(range.ToString()); } Console.WriteLine(); Console.WriteLine("Domains"); foreach (OntologyProperty domain in domains) { Console.WriteLine(domain.ToString()); } }
public void OntologyReasonerGraph() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); OntologyClass c = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Console.WriteLine("Things which are cars in an Ontology Graph"); foreach (OntologyResource r in c.Instances) { Console.WriteLine(r.Resource.ToString()); } Console.WriteLine(); ReasonerGraph g2 = new ReasonerGraph(g, new RdfsReasoner()); OntologyClass c2 = g2.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Console.WriteLine("Things which are cars in a Reasoner Graph using an RDFS Reasoner"); foreach (OntologyResource r in c2.Instances) { Console.WriteLine(r.Resource.ToString()); } Console.WriteLine(); Console.WriteLine("Original Graph has " + g.Triples.Count + " Triples"); Console.WriteLine("Reasoner Graph has " + g2.Triples.Count + " Triples"); Assert.IsTrue(g2.Triples.Count > g.Triples.Count, "Reasoner Graph should have more Triples"); Assert.AreEqual(g, g2.BaseGraph, "Original Graph should be equal to the Reasoner Graphs BaseGraph"); Console.WriteLine(); Console.WriteLine("Going to do a GetTriplesWithSubject() call on both Graphs to see if ReasonerGraph behaves as expected"); IUriNode fiesta = g.CreateUriNode(new Uri("http://example.org/vehicles/FordFiesta")); Console.WriteLine("Original Graph:"); foreach (Triple t in g.GetTriplesWithSubject(fiesta)) { Console.WriteLine(t.ToString()); } Console.WriteLine(); Console.WriteLine("Reasoner Graph:"); foreach (Triple t in g2.GetTriplesWithSubject(fiesta)) { Console.WriteLine(t.ToString()); } }
public void OntologyClassCount2() { OntologyGraph g = new OntologyGraph(); g.LoadFromFile("swrc.owl"); Assert.IsFalse(g.IsEmpty); OntologyClass classOfClasses = g.CreateOntologyClass(g.CreateUriNode("owl:Class")); int count = 0; HashSet <INode> resources = new HashSet <INode>(); //This iterates over the things that are a class foreach (OntologyResource c in classOfClasses.Instances) { count++; resources.Add(c.Resource); } Console.WriteLine("Count = " + count); Console.WriteLine("Distinct Count = " + resources.Count); Assert.AreEqual(resources.Count, count); }
public void OntologyDomainAndRangeOfClass() { OntologyGraph g = new OntologyGraph(); //Load your data into the Graph from somewhere... FileLoader.Load(g, "InferenceTest.ttl"); //Get the Class of interest OntologyClass cls = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Vehicle")); //Find Triples where Predicate is rdfs:range or rdfs:domain and the Object is the Class IUriNode rdfsRange = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "range")); IUriNode rdfsDomain = g.CreateUriNode(new Uri(NamespaceMapper.RDFS + "domain")); List<OntologyProperty> ranges = new List<OntologyProperty>(); List<OntologyProperty> domains = new List<OntologyProperty>(); foreach (Triple t in cls.TriplesWithObject) { if (t.Predicate.Equals(rdfsRange)) { ranges.Add(new OntologyProperty(t.Subject, g)); } else if (t.Predicate.Equals(rdfsDomain)) { domains.Add(new OntologyProperty(t.Subject, g)); } } //Do whatever you want with the Ranges and Domains... Console.WriteLine("Ranges"); foreach (OntologyProperty range in ranges) { Console.WriteLine(range.ToString()); } Console.WriteLine(); Console.WriteLine("Domains"); foreach (OntologyProperty domain in domains) { Console.WriteLine(domain.ToString()); } }
public void OntologyReasonerGraph() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); OntologyClass c = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Console.WriteLine("Things which are cars in an Ontology Graph"); foreach (OntologyResource r in c.Instances) { Console.WriteLine(r.Resource.ToString()); } Console.WriteLine(); ReasonerGraph g2 = new ReasonerGraph(g, new RdfsReasoner()); OntologyClass c2 = g2.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Console.WriteLine("Things which are cars in a Reasoner Graph using an RDFS Reasoner"); foreach (OntologyResource r in c2.Instances) { Console.WriteLine(r.Resource.ToString()); } Console.WriteLine(); Console.WriteLine("Original Graph has " + g.Triples.Count + " Triples"); Console.WriteLine("Reasoner Graph has " + g2.Triples.Count + " Triples"); Assert.IsTrue(g2.Triples.Count > g.Triples.Count, "Reasoner Graph should have more Triples"); Assert.AreEqual(g, g2.BaseGraph, "Original Graph should be equal to the Reasoner Graphs BaseGraph"); Console.WriteLine(); Console.WriteLine("Going to do a GetTriplesWithSubject() call on both Graphs to see if ReasonerGraph behaves as expected"); IUriNode fiesta = g.CreateUriNode(new Uri("http://example.org/vehicles/FordFiesta")); Console.WriteLine("Original Graph:"); foreach (Triple t in g.GetTriplesWithSubject(fiesta)) { Console.WriteLine(t.ToString()); } Console.WriteLine(); Console.WriteLine("Reasoner Graph:"); foreach (Triple t in g2.GetTriplesWithSubject(fiesta)) { Console.WriteLine(t.ToString()); } }