-
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.
Implemented TIMEEquals* reasoner rules
- Loading branch information
Marco De Salvo
committed
Jan 8, 2025
1 parent
3e198b6
commit 7b10564
Showing
19 changed files
with
409 additions
and
14 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEEqualsEntailmentRuleTest.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,74 @@ | ||
/* | ||
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 System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OWLSharp.Extensions.TIME; | ||
using OWLSharp.Ontology; | ||
using OWLSharp.Reasoner; | ||
using RDFSharp.Model; | ||
|
||
namespace OWLSharp.Test.Extensions.TIME | ||
{ | ||
[TestClass] | ||
public class TIMEEqualsEntailmentRuleTest : TIMEBaseEntailmentRuleTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
public async Task ShouldExecuteEqualsEntailment() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_STARTS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHES), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
List<OWLInference> inferences = await TIMEEqualsEntailmentRule.ExecuteRuleAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ShouldExecuteEqualsEntailmentViaReasoner() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_STARTS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHES), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
|
||
TIMEReasoner reasoner = new TIMEReasoner().AddRule(TIMEEnums.TIMEReasonerRules.EqualsEntailment); | ||
List<OWLInference> inferences = await reasoner.ApplyToOntologyAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
#endregion | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEEqualsInverseEntailmentRuleTest.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,74 @@ | ||
/* | ||
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 System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OWLSharp.Extensions.TIME; | ||
using OWLSharp.Ontology; | ||
using OWLSharp.Reasoner; | ||
using RDFSharp.Model; | ||
|
||
namespace OWLSharp.Test.Extensions.TIME | ||
{ | ||
[TestClass] | ||
public class TIMEEqualsInverseEntailmentRuleTest : TIMEBaseEntailmentRuleTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
public async Task ShouldExecuteEqualsInverseEntailment() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_STARTED_BY), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHED_BY), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
List<OWLInference> inferences = await TIMEEqualsInverseEntailmentRule.ExecuteRuleAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ShouldExecuteEqualsInverseEntailmentViaReasoner() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_STARTED_BY), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHED_BY), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
|
||
TIMEReasoner reasoner = new TIMEReasoner().AddRule(TIMEEnums.TIMEReasonerRules.EqualsInverseEntailment); | ||
List<OWLInference> inferences = await reasoner.ApplyToOntologyAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
#endregion | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEEqualsTransitiveEntailmentRuleTest.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,76 @@ | ||
/* | ||
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 System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using OWLSharp.Extensions.TIME; | ||
using OWLSharp.Ontology; | ||
using OWLSharp.Reasoner; | ||
using RDFSharp.Model; | ||
|
||
namespace OWLSharp.Test.Extensions.TIME | ||
{ | ||
[TestClass] | ||
public class TIMEEqualsTransitiveEntailmentRuleTest : TIMEBaseEntailmentRuleTest | ||
{ | ||
#region Tests | ||
[TestMethod] | ||
public async Task ShouldExecuteEqualsTransitiveEntailment() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature3"), new TIMEInterval(new RDFResource("ex:Interval3"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval3")))); | ||
List<OWLInference> inferences = await TIMEEqualsTransitiveEntailmentRule.ExecuteRuleAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
|
||
[TestMethod] | ||
public async Task ShouldExecuteEqualsTransitiveEntailmentViaReasoner() | ||
{ | ||
OWLOntology ontology = new OWLOntology(TestOntology); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature1"), new TIMEInterval(new RDFResource("ex:Interval1"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature2"), new TIMEInterval(new RDFResource("ex:Interval2"))); | ||
ontology.DeclareIntervalFeature(new RDFResource("ex:Feature3"), new TIMEInterval(new RDFResource("ex:Interval3"))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval1")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")))); | ||
ontology.DeclareAssertionAxiom(new OWLObjectPropertyAssertion( | ||
new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval2")), | ||
new OWLNamedIndividual(new RDFResource("ex:Interval3")))); | ||
|
||
TIMEReasoner reasoner = new TIMEReasoner().AddRule(TIMEEnums.TIMEReasonerRules.EqualsTransitiveEntailment); | ||
List<OWLInference> inferences = await reasoner.ApplyToOntologyAsync(ontology); | ||
|
||
Assert.IsNotNull(inferences); | ||
Assert.IsTrue(inferences.Count == 2); | ||
} | ||
#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
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
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
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
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
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
56 changes: 56 additions & 0 deletions
56
OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEEqualsEntailmentRule.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,56 @@ | ||
/* | ||
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 System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using OWLSharp.Ontology; | ||
using OWLSharp.Reasoner; | ||
using RDFSharp.Model; | ||
using RDFSharp.Query; | ||
|
||
namespace OWLSharp.Extensions.TIME | ||
{ | ||
internal static class TIMEEqualsEntailmentRule | ||
{ | ||
internal static async Task<List<OWLInference>> ExecuteRuleAsync(OWLOntology ontology) | ||
{ | ||
SWRLRule swrlRule = new SWRLRule( | ||
new RDFPlainLiteral(nameof(TIMEEqualsEntailmentRule)), | ||
new RDFPlainLiteral("STARTS(?I1,?I2) ^ FINISHES(?I1,?I2) -> EQUALS(?I1,?I2)"), | ||
new SWRLAntecedent() | ||
{ | ||
Atoms = new List<SWRLAtom>() | ||
{ | ||
new SWRLClassAtom(new OWLClass(RDFVocabulary.TIME.INTERVAL), new SWRLVariableArgument(new RDFVariable("?I1"))), | ||
new SWRLClassAtom(new OWLClass(RDFVocabulary.TIME.INTERVAL), new SWRLVariableArgument(new RDFVariable("?I2"))), | ||
new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_STARTS), new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))), | ||
new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHES), new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))) | ||
}, | ||
BuiltIns = new List<SWRLBuiltIn>() | ||
{ | ||
SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))) | ||
} | ||
}, | ||
new SWRLConsequent() | ||
{ | ||
Atoms = new List<SWRLAtom>() | ||
{ | ||
new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))), | ||
new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_EQUALS), new SWRLVariableArgument(new RDFVariable("?I2")), new SWRLVariableArgument(new RDFVariable("?I1"))) | ||
} | ||
}); | ||
|
||
return await swrlRule.ApplyToOntologyAsync(ontology); | ||
} | ||
} | ||
} |
Oops, something went wrong.