private void ProcessClass(OntologyClass ontologyClass, SchemaType parentType) { if (IncludeInOutput(ontologyClass)) { var schemaType = new SchemaType(); var resource = ontologyClass.Resource as IUriNode; schemaType.Name = MakeTypeName(resource); schemaType.TypeUri = resource.Uri; if (parentType == null) { // Needs to define an Id property schemaType.IdentifierProperty = new SchemaProperty { Name = _args.IdentifierPropertyName, DeclaredType = typeof (string), }; } else { schemaType.DerivedFrom = parentType; } foreach (var derivedClass in ontologyClass.DirectSubClasses) { ProcessClass(derivedClass, schemaType); } } }
/// <summary> /// Removes a disjoint class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also removes this class as a disjoint class of the given class /// </remarks> public bool RemoveDisjointClass(OntologyClass @class) { bool a = RemoveDisjointClass(@class.Resource); bool b = @class.RemoveDisjointClass(_resource); return(a || b); }
/// <summary> /// Adds a new disjoint class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also adds this class as a disjoint class of the given class /// </remarks> public bool AddDisjointClass(OntologyClass @class) { bool a = this.AddDisjointClass(@class.Resource); bool b = @class.AddDisjointClass(this._resource); return(a || b); }
/// <summary> /// Removes a super-class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also removes this class as a sub-class of the given class /// </remarks> public bool RemoveSuperClass(OntologyClass @class) { bool a = RemoveSuperClass(@class.Resource); bool b = @class.RemoveSubClass(_resource); return(a || b); }
public void OntologyClassTopAndBottom() { //Load Test Data Console.WriteLine("Loading in the standard test data InferenceTest.ttl"); OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "resources\\InferenceTest.ttl"); //Get the class of Vehicles OntologyClass vehicle = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Vehicle")); Assert.True(vehicle.IsTopClass); Assert.False(vehicle.IsBottomClass); //Get the class of cars OntologyClass car = g.CreateOntologyClass(new Uri("http://example.org/vehicles/Car")); Assert.False(car.IsTopClass); Assert.False(car.IsBottomClass); //Get the class of sports cars OntologyClass sportsCar = g.CreateOntologyClass(new Uri("http://example.org/vehicles/SportsCar")); Assert.False(sportsCar.IsTopClass); Assert.True(sportsCar.IsBottomClass); }
/// <summary> /// Removes an equivalent class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> public bool RemoveEquivalentClass(OntologyClass @class) { bool a = this.RemoveEquivalentClass(@class.Resource); bool b = @class.RemoveEquivalentClass(this._resource); return(a || b); }
public void OntologyDomainAndRangeOfClassProperties() { OntologyGraph g = new OntologyGraph(); FileLoader.Load(g, "resources\\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()); } }
/// <summary> /// Adds an equivalent class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also adds this class as an equivalent class of the given class /// </remarks> public bool AddEquivalentClass(OntologyClass @class) { bool a = AddEquivalentClass(@class.Resource); bool b = @class.AddEquivalentClass(_resource); return(a || b); }
/// <summary> /// Helper method which finds all the Types given for this Resource /// </summary> private void IntialiseClasses() { IUriNode rdfType = this._graph.CreateUriNode(UriFactory.Create(OntologyHelper.PropertyType)); foreach (Triple t in this._graph.GetTriplesWithSubjectPredicate(this._resource, rdfType)) { OntologyClass c = new OntologyClass(t.Object, this._graph); this._classes.Add(c); } }
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)); }
/// <summary> /// Gets whether this Class is equal to another Class /// </summary> /// <param name="obj">Object to test</param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (obj is OntologyClass) { OntologyClass other = (OntologyClass)obj; return(other.Resource.Equals(this._resource) && ReferenceEquals(other.Graph, this._graph)); } else { return(false); } }
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 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 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()); }
/// <summary> /// Determines if this ontology class is to be included in the generated schema /// </summary> /// <param name="ontologyClass"></param> /// <returns></returns> private bool IncludeInOutput(OntologyClass ontologyClass) { return ontologyClass.Resource is IUriNode; }
/// <summary> /// Gets whether the Individual belongs to a specific class /// </summary> /// <param name="class">Class</param> /// <returns></returns> public bool HasClass(OntologyClass @class) { return this._classes.Any(c => c.Equals(@class)); }
/// <summary> /// Helper method which finds all the Types given for this Resource /// </summary> private void IntialiseClasses() { IUriNode rdfType = this._graph.CreateUriNode(new Uri(OntologyHelper.PropertyType)); foreach (Triple t in this._graph.GetTriplesWithSubjectPredicate(this._resource, rdfType)) { OntologyClass c = new OntologyClass(t.Object, this._graph); this._classes.Add(c); } }
/// <summary> /// Gets whether the Individual belongs to a specific class /// </summary> /// <param name="class">Class</param> /// <returns></returns> public bool HasClass(OntologyClass @class) { return(this._classes.Any(c => c.Equals(@class))); }
/// <summary> /// Adds a new super-class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also adds this class as a sub-class of the given class /// </remarks> public bool AddSuperClass(OntologyClass @class) { bool a = this.AddSuperClass(@class.Resource); bool b = @class.AddSubClass(this._resource); return (a || b); }
/// <summary> /// Adds an equivalent class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also adds this class as an equivalent class of the given class /// </remarks> public bool AddEquivalentClass(OntologyClass @class) { bool a = this.AddEquivalentClass(@class.Resource); bool b = @class.AddEquivalentClass(this._resource); return (a || b); }
/// <summary> /// Removes a disjoint class for this class /// </summary> /// <param name="class">Class</param> /// <returns></returns> /// <remarks> /// This overload also removes this class as a disjoint class of the given class /// </remarks> public bool RemoveDisjointClass(OntologyClass @class) { bool a = this.RemoveDisjointClass(@class.Resource); bool b = @class.RemoveDisjointClass(this._resource); return (a || b); }