/// <summary> /// Analyzes the given ontology and produces a detailed report of found evidences /// </summary> internal RDFOntologyValidatorReport AnalyzeOntology(RDFOntology ontology) { var report = new RDFOntologyValidatorReport(); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Validator is going to be applied on Ontology '{0}'", ontology.Value)); //Expand ontology ontology = ontology.UnionWith(RDFBASEOntology.Instance); //Execute rules Parallel.ForEach(this.Rules, rule => { rule.ExecuteRule(ontology, report); }); //Unexpand ontology ontology = ontology.DifferenceWith(RDFBASEOntology.Instance); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Validator has been applied on Ontology '{0}'", ontology.Value)); return(report); }
/// <summary> /// Applies the given SPARQL SELECT query to the given ontology (which is converted into /// a RDF graph including semantic inferences in respect of the given export behavior) /// </summary> public static RDFSelectQueryResult ApplyToOntology(this RDFSelectQuery selectQuery, RDFOntology ontology, RDFSemanticsEnums.RDFOntologyInferenceExportBehavior ontologyInferenceExportBehavior = RDFSemanticsEnums.RDFOntologyInferenceExportBehavior.ModelAndData) { var result = new RDFSelectQueryResult(); if (selectQuery != null) { if (ontology != null) { RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Ontology '{0}' is going to be converted into a graph on which the SPARQL SELECT query will be applied. Please, remember that if the ontology validation has raised warnings or errors, you may get unexpected query results due to inconsistent semantic inferences!", ontology.Value)); var ontGraph = ontology.ToRDFGraph(ontologyInferenceExportBehavior); return(selectQuery.ApplyToGraph(ontGraph)); } } return(result); }
/// <summary> /// Triggers the execution of the given rule on the given ontology. /// Returns a boolean indicating if new evidences have been found. /// </summary> internal Boolean TriggerRule(String ruleName, RDFOntology ontology, RDFOntologyReasoningReport report) { var reasonerRule = this.SelectRule(ruleName); if (reasonerRule != null) { //Raise launching signal RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Launching execution of reasoning rule '{0}'", ruleName)); //Launch the reasoning rule var oldCnt = report.EvidencesCount; reasonerRule.ExecuteRule(ontology, report); var newCnt = report.EvidencesCount - oldCnt; //Raise termination signal RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Completed execution of reasoning rule '{0}': found {1} new evidences", ruleName, newCnt)); return(newCnt > 0); } return(false); }
/// <summary> /// Applies the reasoner on the given ontology, producing a reasoning report. /// </summary> public RDFOntologyReasonerReport ApplyToOntology(ref RDFOntology ontology) { if (ontology != null) { var report = new RDFOntologyReasonerReport(); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Reasoner is going to be applied on Ontology '{0}'", ontology.Value)); //Expand ontology ontology = ontology.UnionWith(RDFBASEOntology.Instance); #region Triggers //Apply first rules this.TriggerRule("EquivalentClassTransitivity", ontology, report); this.TriggerRule("SubClassTransitivity", ontology, report); this.TriggerRule("DisjointWithEntailment", ontology, report); this.TriggerRule("EquivalentPropertyTransitivity", ontology, report); this.TriggerRule("SubPropertyTransitivity", ontology, report); this.TriggerRule("SameAsTransitivity", ontology, report); this.TriggerRule("DifferentFromEntailment", ontology, report); //Apply second rules this.TriggerRule("DomainEntailment", ontology, report); this.TriggerRule("RangeEntailment", ontology, report); this.TriggerRule("ClassTypeEntailment", ontology, report); this.TriggerRule("InverseOfEntailment", ontology, report); this.TriggerRule("SymmetricPropertyEntailment", ontology, report); this.TriggerRule("TransitivePropertyEntailment", ontology, report); this.TriggerRule("PropertyEntailment", ontology, report); this.TriggerRule("SameAsEntailment", ontology, report); #endregion //Unexpand ontology ontology = ontology.DifferenceWith(RDFBASEOntology.Instance); RDFSemanticsEvents.RaiseSemanticsInfo(String.Format("Reasoner has been applied on Ontology '{0}'", ontology.Value)); return(report); } throw new RDFSemanticsException("Cannot apply RDFOntologyReasoner because given \"ontology\" parameter is null."); }
/// <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); }