/// <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); }