/// <summary> /// Adds the "aFact -> objectProperty -> bFact" relation to the data /// </summary> public RDFOntologyData AddAssertionRelation(RDFOntologyFact aFact, RDFOntologyObjectProperty objectProperty, RDFOntologyFact bFact) { if (aFact != null && objectProperty != null && bFact != null) { //Enforce preliminary check on usage of BASE properties if (!RDFOntologyChecker.CheckReservedProperty(objectProperty)) { //Enforce taxonomy checks before adding the assertion //Creation of transitive cycles is not allowed (OWL-DL) if (RDFOntologyChecker.CheckTransitiveAssertionCompatibility(this, aFact, objectProperty, bFact)) { this.Relations.Assertions.AddEntry(new RDFOntologyTaxonomyEntry(aFact, objectProperty, bFact)); } else { //Raise warning event to inform the user: Assertion relation cannot be added to the data because it violates the taxonomy transitive consistency RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation between fact '{0}' and fact '{1}' with transitive property '{2}' cannot be added to the data because it would violate the taxonomy consistency (transitive cycle detected).", aFact, bFact, objectProperty)); } } else { //Raise warning event to inform the user: Assertion relation cannot be added to the data because usage of BASE reserved properties compromises the taxonomy consistency RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation between fact '{0}' and fact '{1}' cannot be added to the data because usage of BASE reserved properties compromises the taxonomy consistency.", aFact, bFact)); } } return(this); }
/// <summary> /// Adds the "ontologyFact -> rdf:type -> ontologyClass" relation to the data. /// </summary> public RDFOntologyData AddClassTypeRelation(RDFOntologyFact ontologyFact, RDFOntologyClass ontologyClass) { if (ontologyFact != null && ontologyClass != null) { //Enforce preliminary check on usage of BASE classes if (!RDFOntologyChecker.CheckReservedClass(ontologyClass)) { //Enforce taxonomy checks before adding the ClassType relation if (RDFOntologyChecker.CheckClassTypeCompatibility(ontologyClass)) { this.Relations.ClassType.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDF.TYPE.ToRDFOntologyObjectProperty(), ontologyClass)); } else { //Raise warning event to inform the user: ClassType relation cannot be added to the data because only plain classes can be explicitly assigned as class types of facts RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("ClassType relation between fact '{0}' and class '{1}' cannot be added to the data because only plain classes can be explicitly assigned as class types of facts.", ontologyFact, ontologyClass)); } } else { //Raise warning event to inform the user: ClassType relation cannot be added to the data because usage of BASE reserved classes compromises the taxonomy consistency RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("ClassType relation between fact '{0}' and class '{1}' cannot be added to the data because because usage of BASE reserved classes compromises the taxonomy consistency.", ontologyFact, ontologyClass)); } } return(this); }
/// <summary> /// Validate the given ontology against a set of RDFS/OWL-DL rules, detecting errors and inconsistencies affecting its model and data. /// </summary> public static RDFOntologyValidatorReport Validate(this RDFOntology ontology) { var report = new RDFOntologyValidatorReport(); if (ontology != null) { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Validator is going to be applied on Ontology '{0}'...", ontology.Value)); //STEP 1: Expand ontology RDFOntology expOntology = ontology.UnionWith(RDFBASEOntology.Instance); //STEP 2: Execute rules Parallel.ForEach(Rules, r => report.MergeEvidences(r.ExecuteRule(expOntology))); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Validator has been applied on Ontology '{0}': found " + report.EvidencesCount + " evidences.", ontology.Value)); } return report; }
/// <summary> /// Applies the reasoner on the given ontology, producing a reasoning report. /// </summary> public RDFOntologyReasonerReport ApplyToOntology(ref RDFOntology ontology) { var report = new RDFOntologyReasonerReport(); if (ontology != null) { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Reasoner is going to be applied on Ontology '{0}'...", ontology.Value)); //STEP 1: Expand ontology var ontologyValue = ontology.Value; ontology = ontology.UnionWith(RDFBASEOntology.Instance); //STEP 2: Execute BASE rules #region BASE rules var baseRules = this.Rules.Where(x => x.RulePriority <= RDFOntologyReasonerRuleset.RulesCount) .OrderBy(x => x.RulePriority); foreach (var bRule in baseRules) { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Launching execution of BASE reasoning rule '{0}'...", bRule)); var bRuleReport = bRule.ExecuteRule(ontology); report.Merge(bRuleReport); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Completed execution of BASE reasoning rule '{0}': found {1} evidences.", bRule, bRuleReport.EvidencesCount)); } #endregion //STEP 3: Execute custom rules #region Custom rules var customRules = this.Rules.Where(x => x.RulePriority > RDFOntologyReasonerRuleset.RulesCount) .OrderBy(x => x.RulePriority); foreach (var cRule in customRules) { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Launching execution of reasoning rule '{0}'...", cRule)); var cRuleReport = cRule.ExecuteRule(ontology); report.Merge(cRuleReport); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Completed execution of reasoning rule '{0}': found {1} evidences.", cRule, cRuleReport.EvidencesCount)); } #endregion //STEP 4: Unexpand ontology ontology = ontology.DifferenceWith(RDFBASEOntology.Instance); ontology.Value = ontologyValue; RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Reasoner has been applied on Ontology '{0}': found " + report.EvidencesCount + " evidences.", ontology.Value)); } return(report); }
/// <summary> /// Validate the given ontology against a set of RDFS/OWL-DL rules, detecting errors and inconsistencies affecting its model and data. /// </summary> public static RDFOntologyValidatorReport Validate(this RDFOntology ontology) { var report = new RDFOntologyValidatorReport(); if (ontology != null) { RDFSemanticsEvents.RaiseSemanticsInfo(string.Format("Validator is going to be applied on Ontology '{0}': this may require intensive processing, depending on size and complexity of domain knowledge.", ontology.Value)); //STEP 1: Expand ontology RDFOntology expOntology = ontology.UnionWith(RDFBASEOntology.Instance); //STEP 2: Execute rules Parallel.ForEach(Rules, r => report.MergeEvidences(r.ExecuteRule(expOntology))); RDFSemanticsEvents.RaiseSemanticsInfo(string.Format("Validator has been applied on Ontology '{0}': found " + report.EvidencesCount + " evidences.", ontology.Value)); } return(report); }
/// <summary> /// Adds the "aFact -> owl:differentFrom -> bFact" relation to the data /// </summary> public RDFOntologyData AddDifferentFromRelation(RDFOntologyFact aFact, RDFOntologyFact bFact) { if (aFact != null && bFact != null && !aFact.Equals(bFact)) { //Enforce taxonomy checks before adding the DifferentFrom relation if (RDFOntologyChecker.CheckDifferentFromCompatibility(this, aFact, bFact)) { this.Relations.DifferentFrom.AddEntry(new RDFOntologyTaxonomyEntry(aFact, RDFVocabulary.OWL.DIFFERENT_FROM.ToRDFOntologyObjectProperty(), bFact)); this.Relations.DifferentFrom.AddEntry(new RDFOntologyTaxonomyEntry(bFact, RDFVocabulary.OWL.DIFFERENT_FROM.ToRDFOntologyObjectProperty(), aFact).SetInference(RDFSemanticsEnums.RDFOntologyInferenceType.API)); } else { //Raise warning event to inform the user: DifferentFrom relation cannot be added to the data because it violates the taxonomy consistency RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("DifferentFrom relation between fact '{0}' and fact '{1}' cannot be added to the data because it violates the taxonomy consistency.", aFact, bFact)); } } return(this); }
/// <summary> /// Adds the "ontologyFact -> datatypeProperty -> ontologyLiteral" relation to the data /// </summary> public RDFOntologyData AddAssertionRelation(RDFOntologyFact ontologyFact, RDFOntologyDatatypeProperty datatypeProperty, RDFOntologyLiteral ontologyLiteral) { if (ontologyFact != null && datatypeProperty != null && ontologyLiteral != null) { //Enforce preliminary check on usage of BASE properties if (!RDFOntologyChecker.CheckReservedProperty(datatypeProperty)) { this.Relations.Assertions.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, datatypeProperty, ontologyLiteral)); this.AddLiteral(ontologyLiteral); } else { //Raise warning event to inform the user: Assertion relation cannot be added to the data because usage of BASE reserved properties compromises the taxonomy consistency RDFSemanticsEvents.RaiseSemanticsWarning(String.Format("Assertion relation between fact '{0}' and literal '{1}' cannot be added to the data because usage of BASE reserved properties compromises the taxonomy consistency.", ontologyFact, ontologyLiteral)); } } return(this); }
/// <summary> /// Adds the given standard annotation to the given ontology fact /// </summary> public RDFOntologyData AddStandardAnnotation(RDFSemanticsEnums.RDFOntologyStandardAnnotation standardAnnotation, RDFOntologyFact ontologyFact, RDFOntologyResource annotationValue) { if (ontologyFact != null && annotationValue != null) { switch (standardAnnotation) { //owl:versionInfo case RDFSemanticsEnums.RDFOntologyStandardAnnotation.VersionInfo: if (annotationValue.IsLiteral()) { this.Annotations.VersionInfo.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.OWL.VERSION_INFO.ToRDFOntologyAnnotationProperty(), annotationValue)); } else { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Cannot annotate ontology fact with owl:versionInfo value '{0}' because it is not an ontology literal", annotationValue)); } break; //owl:versionIRI case RDFSemanticsEnums.RDFOntologyStandardAnnotation.VersionIRI: RDFSemanticsEvents.RaiseSemanticsInfo("Cannot annotate ontology fact with owl:versionIRI because it is reserved for ontologies"); break; //rdfs:comment case RDFSemanticsEnums.RDFOntologyStandardAnnotation.Comment: if (annotationValue.IsLiteral()) { this.Annotations.Comment.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDFS.COMMENT.ToRDFOntologyAnnotationProperty(), annotationValue)); } else { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Cannot annotate ontology fact with rdfs:comment value '{0}' because it is not an ontology literal", annotationValue)); } break; //rdfs:label case RDFSemanticsEnums.RDFOntologyStandardAnnotation.Label: if (annotationValue.IsLiteral()) { this.Annotations.Label.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDFS.LABEL.ToRDFOntologyAnnotationProperty(), annotationValue)); } else { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Cannot annotate ontology fact with rdfs:label value '{0}' because it is not an ontology literal", annotationValue)); } break; //rdfs:seeAlso case RDFSemanticsEnums.RDFOntologyStandardAnnotation.SeeAlso: this.Annotations.SeeAlso.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDFS.SEE_ALSO.ToRDFOntologyAnnotationProperty(), annotationValue)); break; //rdfs:isDefinedBy case RDFSemanticsEnums.RDFOntologyStandardAnnotation.IsDefinedBy: this.Annotations.IsDefinedBy.AddEntry(new RDFOntologyTaxonomyEntry(ontologyFact, RDFVocabulary.RDFS.IS_DEFINED_BY.ToRDFOntologyAnnotationProperty(), annotationValue)); break; //owl:priorVersion case RDFSemanticsEnums.RDFOntologyStandardAnnotation.PriorVersion: RDFSemanticsEvents.RaiseSemanticsInfo("Cannot annotate ontology fact with owl:priorVersion because it is reserved for ontologies"); break; //owl:imports case RDFSemanticsEnums.RDFOntologyStandardAnnotation.Imports: RDFSemanticsEvents.RaiseSemanticsInfo("Cannot annotate ontology fact with owl:imports because it is reserved for ontologies"); break; //owl:backwardCompatibleWith case RDFSemanticsEnums.RDFOntologyStandardAnnotation.BackwardCompatibleWith: RDFSemanticsEvents.RaiseSemanticsInfo("Cannot annotate ontology fact with owl:backwardCompatibleWith because it is reserved for ontologies"); break; //owl:incompatibleWith case RDFSemanticsEnums.RDFOntologyStandardAnnotation.IncompatibleWith: RDFSemanticsEvents.RaiseSemanticsInfo("Cannot annotate ontology fact with owl:incompatibleWith because it is reserved for ontologies"); break; } } return(this); }