public void OntologyClassTopAndBottom() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); //Get the class of Vehicles OntologyClass vehicle = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Vehicle")); Assert.IsTrue(vehicle.IsTopClass); Assert.IsFalse(vehicle.IsBottomClass); //Get the class of cars OntologyClass car = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Assert.IsFalse(car.IsTopClass); Assert.IsFalse(car.IsBottomClass); //Get the class of sports cars OntologyClass sportsCar = g.CreateOntologyClass(new Uri("http://example.org/vehicles/SportsCar")); Assert.IsFalse(sportsCar.IsTopClass); Assert.IsTrue(sportsCar.IsBottomClass); }
public void OntologyDomainAndRangeOfClassProperties() { 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 List <OntologyProperty> ranges = cls.IsRangeOf.ToList(); List <OntologyProperty> domains = cls.IsDomainOf.ToList(); //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 OntologyClassBasic() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); //Get the class of Ground Vehicles OntologyClass groundVehicle = g.CreateOntologyClass(new Uri("http://example.org/vehicles/GroundVehicle")); Console.WriteLine("Got the class of Ground Vehicles"); foreach (OntologyClass c in groundVehicle.SuperClasses) { Console.WriteLine("Super Class: " + c.Resource.ToString()); } foreach (OntologyClass c in groundVehicle.SubClasses) { Console.WriteLine("Sub Class: " + c.Resource.ToString()); } Console.WriteLine(); //Get the class of Cars OntologyClass car = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Console.WriteLine("Got the class of Cars"); foreach (OntologyClass c in car.SuperClasses) { Console.WriteLine("Super Class: " + c.Resource.ToString()); } foreach (OntologyClass c in car.SubClasses) { Console.WriteLine("Sub Class: " + c.Resource.ToString()); } foreach (OntologyResource r in car.Instances) { Console.WriteLine("Instance: " + r.Resource.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 OntologyClassSiblings() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); //Get the class of Cars OntologyClass car = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); //Get siblings List <OntologyClass> siblings = car.Siblings.ToList(); Assert.AreEqual(2, siblings.Count); Assert.IsFalse(siblings.Contains(car)); }
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 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 OntologyClassSubClasses() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "InferenceTest.ttl"); //Get the class of Ground Vehicles OntologyClass groundVehicle = g.CreateOntologyClass(new Uri("http://example.org/vehicles/GroundVehicle")); Console.WriteLine("Got the class of Ground Vehicles"); //Check counts of super classes Assert.AreEqual(1, groundVehicle.SuperClasses.Count()); Assert.AreEqual(1, groundVehicle.DirectSuperClasses.Count()); Assert.AreEqual(0, groundVehicle.IndirectSuperClasses.Count()); //Check counts of sub-classes Assert.AreEqual(5, groundVehicle.SubClasses.Count()); Assert.AreEqual(3, groundVehicle.DirectSubClasses.Count()); Assert.AreEqual(2, groundVehicle.IndirectSubClasses.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()); } }