-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deep refactoring of OWLReasoner internals
- Loading branch information
Marco De Salvo
committed
Dec 13, 2023
1 parent
3aae12f
commit 8241ab3
Showing
33 changed files
with
313 additions
and
214 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
OWLSharp.Test/Extensions/SWRL/Reasoner/SWRLReasonerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright 2014-2024 Marco De Salvo | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OWLSharp.Extensions.TIME; | ||
using RDFSharp.Model; | ||
using RDFSharp.Query; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace OWLSharp.Extensions.SWRL.Test | ||
{ | ||
[TestClass] | ||
public class SWRLReasonerTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
public void ShouldAddSWRLRule() | ||
{ | ||
OWLReasoner reasoner = new OWLReasoner(); | ||
reasoner.AddSWRLRule(new SWRLRule("testRule", "description", | ||
new SWRLAntecedent(), new SWRLConsequent())); | ||
|
||
Assert.IsNotNull(reasoner); | ||
Assert.IsNotNull(reasoner.Rules); | ||
Assert.IsTrue(reasoner.Rules.Count == 3); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("STD")); | ||
Assert.IsTrue(reasoner.Rules["STD"] is List<OWLEnums.OWLReasonerRules> stdRules && stdRules.Count == 0); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("SWRL")); | ||
Assert.IsTrue(reasoner.Rules["SWRL"] is List<SWRLRule> swrlRules && swrlRules.Count == 1); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("TIME")); | ||
Assert.IsTrue(reasoner.Rules["TIME"] is List<TIMEEnums.TIMEReasonerRules> timeRules && timeRules.Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldReasonWithSWRLRule() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.DeclareClass(new RDFResource("ex:class")); | ||
ontology.Data.DeclareIndividual(new RDFResource("ex:indiv")); | ||
ontology.Data.DeclareIndividualType(new RDFResource("ex:indiv"), new RDFResource("ex:class")); | ||
|
||
OWLReasoner reasoner = new OWLReasoner(); | ||
reasoner.AddSWRLRule(new SWRLRule("testRule", "this is test rule", | ||
new SWRLAntecedent().AddAtom(new SWRLClassAtom(new RDFResource("ex:class"), new RDFVariable("?C"))), | ||
new SWRLConsequent().AddAtom(new SWRLObjectPropertyAtom(RDFVocabulary.RDF.TYPE, new RDFVariable("?C"), RDFVocabulary.OWL.INDIVIDUAL)))); | ||
|
||
OWLReasonerReport reasonerReport = reasoner.ApplyToOntology(ontology); | ||
|
||
Assert.IsNotNull(reasonerReport); | ||
Assert.IsTrue(reasonerReport.EvidencesCount == 1); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldReasonWithSWRLRuleAndSubscribedEvents() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.DeclareClass(new RDFResource("ex:class")); | ||
ontology.Data.DeclareIndividual(new RDFResource("ex:indiv")); | ||
ontology.Data.DeclareIndividualType(new RDFResource("ex:indiv"), new RDFResource("ex:class")); | ||
|
||
OWLReasoner reasoner = new OWLReasoner(); | ||
reasoner.AddSWRLRule(new SWRLRule("testRule", "this is test rule", | ||
new SWRLAntecedent().AddAtom(new SWRLClassAtom(new RDFResource("ex:class"), new RDFVariable("?C"))), | ||
new SWRLConsequent().AddAtom(new SWRLObjectPropertyAtom(RDFVocabulary.RDF.TYPE, new RDFVariable("?C"), RDFVocabulary.OWL.INDIVIDUAL)))); | ||
|
||
string warningMsg = null; | ||
OWLEvents.OnInfo += (string msg) => { warningMsg += msg; }; | ||
|
||
OWLReasonerReport reasonerReport = reasoner.ApplyToOntology(ontology); | ||
|
||
Assert.IsNotNull(reasonerReport); | ||
Assert.IsTrue(reasonerReport.EvidencesCount == 1); | ||
Assert.IsNotNull(warningMsg); | ||
Assert.IsTrue(warningMsg.IndexOf("found 1 evidences") > -1); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ShouldReasonWithSWRLRuleAsync() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.DeclareClass(new RDFResource("ex:class")); | ||
ontology.Data.DeclareIndividual(new RDFResource("ex:indiv")); | ||
ontology.Data.DeclareIndividualType(new RDFResource("ex:indiv"), new RDFResource("ex:class")); | ||
|
||
OWLReasoner reasoner = new OWLReasoner(); | ||
reasoner.AddSWRLRule(new SWRLRule("testRule", "this is test rule", | ||
new SWRLAntecedent().AddAtom(new SWRLClassAtom(new RDFResource("ex:class"), new RDFVariable("?C"))), | ||
new SWRLConsequent().AddAtom(new SWRLObjectPropertyAtom(RDFVocabulary.RDF.TYPE, new RDFVariable("?C"), RDFVocabulary.OWL.INDIVIDUAL)))); | ||
|
||
OWLReasonerReport reasonerReport = await reasoner.ApplyToOntologyAsync(ontology); | ||
|
||
Assert.IsNotNull(reasonerReport); | ||
Assert.IsTrue(reasonerReport.EvidencesCount == 1); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
OWLSharp.Test/Extensions/TIME/Reasoner/TIMEReasonerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2014-2024 Marco De Salvo | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OWLSharp.Extensions.SWRL; | ||
using System.Collections.Generic; | ||
|
||
namespace OWLSharp.Extensions.TIME.Test | ||
{ | ||
[TestClass] | ||
public class TIMEReasonerTest | ||
{ | ||
[TestMethod] | ||
public void ShouldAddTIMERule() | ||
{ | ||
OWLReasoner reasoner = new OWLReasoner(); | ||
reasoner.AddTIMERule(TIMEEnums.TIMEReasonerRules.TIME_EqualsEntailment); | ||
reasoner.AddTIMERule(TIMEEnums.TIMEReasonerRules.TIME_EqualsEntailment); //Will be discarded, since duplicate standard rules are not allowed | ||
|
||
Assert.IsNotNull(reasoner); | ||
Assert.IsNotNull(reasoner.Rules); | ||
Assert.IsTrue(reasoner.Rules.Count == 3); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("STD")); | ||
Assert.IsTrue(reasoner.Rules["STD"] is List<OWLEnums.OWLReasonerRules> stdRules && stdRules.Count == 0); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("SWRL")); | ||
Assert.IsTrue(reasoner.Rules["SWRL"] is List<SWRLRule> swrlRules && swrlRules.Count == 0); | ||
Assert.IsTrue(reasoner.Rules.ContainsKey("TIME")); | ||
Assert.IsTrue(reasoner.Rules["TIME"] is List<TIMEEnums.TIMEReasonerRules> timeRules && timeRules.Count == 1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.