/// <summary> /// Enlists the classes which are directly (or indirectly, if inference is requested) children of the lens class /// </summary> public List <(bool, RDFOntologyClass)> SubClasses(bool enableInference) { List <(bool, RDFOntologyClass)> result = new List <(bool, RDFOntologyClass)>(); //First-level enlisting of subclasses foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Model.ClassModel.Relations.SubClassOf.SelectEntriesByObject(this.OntologyClass).Where(te => !te.IsInference())) { result.Add((false, (RDFOntologyClass)sf.TaxonomySubject)); } //Inference-enabled discovery of subclasses if (enableInference) { List <RDFOntologyClass> subClasses = RDFOntologyHelper.GetSubClassesOf(this.Ontology.Model.ClassModel, this.OntologyClass).ToList(); foreach (RDFOntologyClass subClass in subClasses) { if (!result.Any(f => f.Item2.Equals(subClass))) { result.Add((true, subClass)); } } } return(result); }
/// <summary> /// Enlists the facts which are directly (or indirectly, if inference is requested) equivalent to the lens fact /// </summary> public List <(bool, RDFOntologyFact)> SameFacts(bool enableInference) { List <(bool, RDFOntologyFact)> result = new List <(bool, RDFOntologyFact)>(); //First-level enlisting of same facts foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Data.Relations.SameAs.SelectEntriesBySubject(this.OntologyFact).Where(te => !te.IsInference())) { result.Add((false, (RDFOntologyFact)sf.TaxonomyObject)); } //Inference-enabled discovery of same facts if (enableInference) { List <RDFOntologyFact> sameFacts = RDFOntologyHelper.GetSameFactsAs(this.Ontology.Data, this.OntologyFact).ToList(); foreach (RDFOntologyFact sameFact in sameFacts) { if (!result.Any(f => f.Item2.Equals(sameFact))) { result.Add((true, sameFact)); } } } return(result); }
/// <summary> /// Enlists the properties which are directly (or indirectly, if inference is requested) disjoint with the lens property /// </summary> public List <(bool, RDFOntologyProperty)> DisjointProperties(bool enableInference) { List <(bool, RDFOntologyProperty)> result = new List <(bool, RDFOntologyProperty)>(); //First-level enlisting of disjoint properties foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Model.PropertyModel.Relations.PropertyDisjointWith.SelectEntriesBySubject(this.OntologyProperty).Where(te => !te.IsInference())) { result.Add((false, (RDFOntologyProperty)sf.TaxonomyObject)); } //Inference-enabled discovery of disjoint properties if (enableInference) { List <RDFOntologyProperty> disjointProperties = RDFOntologyHelper.GetPropertiesDisjointWith(this.Ontology.Model.PropertyModel, this.OntologyProperty).ToList(); foreach (RDFOntologyProperty disjointProperty in disjointProperties) { if (!result.Any(f => f.Item2.Equals(disjointProperty))) { result.Add((true, disjointProperty)); } } } return(result); }
/// <summary> /// Enlists the properties which are directly (or indirectly, if inference is requested) inverse of the lens property /// </summary> public List <(bool, RDFOntologyObjectProperty)> InverseProperties(bool enableInference) { List <(bool, RDFOntologyObjectProperty)> result = new List <(bool, RDFOntologyObjectProperty)>(); if (this.OntologyProperty.IsObjectProperty()) { //First-level enlisting of inverse properties foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Model.PropertyModel.Relations.InverseOf.SelectEntriesBySubject(this.OntologyProperty).Where(te => !te.IsInference())) { result.Add((false, (RDFOntologyObjectProperty)sf.TaxonomyObject)); } //Inference-enabled discovery of inverse properties if (enableInference) { List <RDFOntologyObjectProperty> inverseProperties = RDFOntologyHelper.GetInversePropertiesOf(this.Ontology.Model.PropertyModel, (RDFOntologyObjectProperty)this.OntologyProperty) .OfType <RDFOntologyObjectProperty>() .ToList(); foreach (RDFOntologyObjectProperty inverseProperty in inverseProperties) { if (!result.Any(f => f.Item2.Equals(inverseProperty))) { result.Add((true, inverseProperty)); } } } } return(result); }
/// <summary> /// Enlists the facts/literals which are directly (or indirectly, if inference is requested) members of the lens class /// </summary> public List <(bool, RDFOntologyResource)> Members(bool enableInference) { List <(bool, RDFOntologyResource)> result = new List <(bool, RDFOntologyResource)>(); //First-level enlisting of members (datatype class) if (RDFOntologyHelper.CheckIsLiteralCompatibleClass(this.Ontology.Model.ClassModel, this.OntologyClass)) { IEnumerable <RDFOntologyLiteral> ontlits = this.Ontology.Data.Literals.Values.Where(ol => ol.Value is RDFTypedLiteral); foreach (RDFOntologyLiteral ontlit in ontlits.Where(ol => RDFModelUtilities.GetDatatypeFromEnum(((RDFTypedLiteral)ol.Value).Datatype).Equals(this.OntologyClass.ToString()))) { if (!result.Any(ol => ol.Equals(ontlit))) { result.Add((false, ontlit)); } } } //First-level enlisting of members (object class) else { foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Data.Relations.ClassType.SelectEntriesByObject(this.OntologyClass).Where(te => !te.IsInference())) { result.Add((false, sf.TaxonomySubject)); } } //Inference-enabled discovery of members if (enableInference) { RDFOntologyData members = RDFOntologyHelper.GetMembersOf(this.Ontology, this.OntologyClass); foreach (RDFOntologyFact fact in members) { if (!result.Any(f => f.Item2.Equals(fact))) { result.Add((true, fact)); } } foreach (RDFOntologyLiteral literal in members.Literals.Values) { if (!result.Any(f => f.Item2.Equals(literal))) { result.Add((true, literal)); } } } return(result); }
/// <summary> /// Enlists the classes to which the lens fact directly (or indirectly, if inference is requested) belongs /// </summary> public List <(bool, RDFOntologyClass)> ClassTypes(bool enableInference) { List <(bool, RDFOntologyClass)> result = new List <(bool, RDFOntologyClass)>(); //First-level enlisting of class types foreach (RDFOntologyTaxonomyEntry sf in this.Ontology.Data.Relations.ClassType.SelectEntriesBySubject(this.OntologyFact).Where(te => !te.IsInference())) { result.Add((false, (RDFOntologyClass)sf.TaxonomyObject)); } //Inference-enabled discovery of class types if (enableInference) { //Skip already enlisted classes and also reserved/literal-compatible classes var availableclasses = this.Ontology.Model.ClassModel.Where(cls => !result.Any(res => res.Item2.Equals(cls)) && !RDFOntologyChecker.CheckReservedClass(cls) && !RDFOntologyHelper.CheckIsLiteralCompatibleClass(this.Ontology.Model.ClassModel, cls)); var membersCache = new Dictionary <long, RDFOntologyData>(); //Evaluate enumerations foreach (var e in availableclasses.Where(cls => cls.IsEnumerateClass())) { if (!membersCache.ContainsKey(e.PatternMemberID)) { membersCache.Add(e.PatternMemberID, this.Ontology.GetMembersOfEnumerate((RDFOntologyEnumerateClass)e)); } if (membersCache[e.PatternMemberID].Facts.ContainsKey(this.OntologyFact.PatternMemberID)) { result.Add((true, e)); } } //Evaluate restrictions foreach (var r in availableclasses.Where(cls => cls.IsRestrictionClass())) { if (!membersCache.ContainsKey(r.PatternMemberID)) { membersCache.Add(r.PatternMemberID, this.Ontology.GetMembersOfRestriction((RDFOntologyRestriction)r)); } if (membersCache[r.PatternMemberID].Facts.ContainsKey(this.OntologyFact.PatternMemberID)) { result.Add((true, r)); } } //Evaluate simple classes foreach (var c in availableclasses.Where(cls => cls.IsSimpleClass())) { if (!membersCache.ContainsKey(c.PatternMemberID)) { membersCache.Add(c.PatternMemberID, this.Ontology.GetMembersOfClass(c)); } if (membersCache[c.PatternMemberID].Facts.ContainsKey(this.OntologyFact.PatternMemberID)) { result.Add((true, c)); } } //Evaluate composite classes foreach (var c in availableclasses.Where(cls => cls.IsCompositeClass())) { if (!membersCache.ContainsKey(c.PatternMemberID)) { membersCache.Add(c.PatternMemberID, this.Ontology.GetMembersOfComposite(c, membersCache)); } if (membersCache[c.PatternMemberID].Facts.ContainsKey(this.OntologyFact.PatternMemberID)) { result.Add((true, c)); } } } return(result); }