diff --git a/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRuleTest.cs b/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRuleTest.cs new file mode 100644 index 00000000..8770f71c --- /dev/null +++ b/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRuleTest.cs @@ -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 TIMEFinishedByEqualsEntailmentRuleTest : TIMEBaseEntailmentRuleTest + { + #region Tests + [TestMethod] + public async Task ShouldExecuteFinishedByEqualsEntailment() + { + 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_FINISHED_BY), + 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 inferences = await TIMEFinishedByEqualsEntailmentRule.ExecuteRuleAsync(ontology); + + Assert.IsNotNull(inferences); + Assert.IsTrue(inferences.Count == 1); + } + + [TestMethod] + public async Task ShouldExecuteFinishedByEqualsEntailmentViaReasoner() + { + 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_FINISHED_BY), + 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.FinishedByEqualsEntailment); + List inferences = await reasoner.ApplyToOntologyAsync(ontology); + + Assert.IsNotNull(inferences); + Assert.IsTrue(inferences.Count == 1); + } + #endregion + } +} \ No newline at end of file diff --git a/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRuleTest.cs b/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRuleTest.cs new file mode 100644 index 00000000..30f5584f --- /dev/null +++ b/OWLSharp.Test/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRuleTest.cs @@ -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 TIMEFinishesEqualsEntailmentRuleTest : TIMEBaseEntailmentRuleTest + { + #region Tests + [TestMethod] + public async Task ShouldExecuteFinishesEqualsEntailment() + { + 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_FINISHES), + 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 inferences = await TIMEFinishesEqualsEntailmentRule.ExecuteRuleAsync(ontology); + + Assert.IsNotNull(inferences); + Assert.IsTrue(inferences.Count == 1); + } + + [TestMethod] + public async Task ShouldExecuteFinishesEqualsEntailmentViaReasoner() + { + 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_FINISHES), + 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.FinishesEqualsEntailment); + List inferences = await reasoner.ApplyToOntologyAsync(ontology); + + Assert.IsNotNull(inferences); + Assert.IsTrue(inferences.Count == 1); + } + #endregion + } +} \ No newline at end of file diff --git a/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRule.cs b/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRule.cs new file mode 100644 index 00000000..e6a8f6e6 --- /dev/null +++ b/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishedByEqualsEntailmentRule.cs @@ -0,0 +1,58 @@ +/* + 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 TIMEFinishedByEqualsEntailmentRule + { + internal static async Task> ExecuteRuleAsync(OWLOntology ontology) + { + SWRLRule swrlRule = new SWRLRule( + new RDFPlainLiteral(nameof(TIMEFinishedByEqualsEntailmentRule)), + new RDFPlainLiteral("FINISHEDBY(?I1,?I2) ^ EQUALS(?I2,?I3) -> FINISHEDBY(?I1,?I3)"), + new SWRLAntecedent() + { + Atoms = new List() + { + 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 SWRLClassAtom(new OWLClass(RDFVocabulary.TIME.INTERVAL), new SWRLVariableArgument(new RDFVariable("?I3"))), + new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHED_BY), 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("?I3"))) + }, + BuiltIns = new List() + { + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))), + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I3"))), + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I2")), new SWRLVariableArgument(new RDFVariable("?I3"))) + } + }, + new SWRLConsequent() + { + Atoms = new List() + { + new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHED_BY), new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I3"))) + } + }); + + return await swrlRule.ApplyToOntologyAsync(ontology); + } + } +} \ No newline at end of file diff --git a/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRule.cs b/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRule.cs new file mode 100644 index 00000000..70204920 --- /dev/null +++ b/OWLSharp/Extensions/TIME/Reasoner/RuleSet/TIMEFinishesEqualsEntailmentRule.cs @@ -0,0 +1,58 @@ +/* + 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 TIMEFinishesEqualsEntailmentRule + { + internal static async Task> ExecuteRuleAsync(OWLOntology ontology) + { + SWRLRule swrlRule = new SWRLRule( + new RDFPlainLiteral(nameof(TIMEFinishesEqualsEntailmentRule)), + new RDFPlainLiteral("FINISHES(?I1,?I2) ^ EQUALS(?I2,?I3) -> FINISHES(?I1,?I3)"), + new SWRLAntecedent() + { + Atoms = new List() + { + 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 SWRLClassAtom(new OWLClass(RDFVocabulary.TIME.INTERVAL), new SWRLVariableArgument(new RDFVariable("?I3"))), + new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHES), 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("?I3"))) + }, + BuiltIns = new List() + { + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I2"))), + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I3"))), + SWRLBuiltIn.NotEqual(new SWRLVariableArgument(new RDFVariable("?I2")), new SWRLVariableArgument(new RDFVariable("?I3"))) + } + }, + new SWRLConsequent() + { + Atoms = new List() + { + new SWRLObjectPropertyAtom(new OWLObjectProperty(RDFVocabulary.TIME.INTERVAL_FINISHES), new SWRLVariableArgument(new RDFVariable("?I1")), new SWRLVariableArgument(new RDFVariable("?I3"))) + } + }); + + return await swrlRule.ApplyToOntologyAsync(ontology); + } + } +} \ No newline at end of file diff --git a/OWLSharp/Extensions/TIME/Reasoner/TIMEReasoner.cs b/OWLSharp/Extensions/TIME/Reasoner/TIMEReasoner.cs index f585ee99..fdb9bbef 100644 --- a/OWLSharp/Extensions/TIME/Reasoner/TIMEReasoner.cs +++ b/OWLSharp/Extensions/TIME/Reasoner/TIMEReasoner.cs @@ -103,13 +103,13 @@ await Rules.ParallelForEachAsync(async (rule) => case TIMEEnums.TIMEReasonerRules.EqualsTransitiveEntailment: inferenceRegistry[TIMEEnums.TIMEReasonerRules.EqualsTransitiveEntailment.ToString()] = await TIMEEqualsTransitiveEntailmentRule.ExecuteRuleAsync(ontology); break; - /*case TIMEEnums.TIMEReasonerRules.FinishedByEqualsEntailment: + case TIMEEnums.TIMEReasonerRules.FinishedByEqualsEntailment: inferenceRegistry[TIMEEnums.TIMEReasonerRules.FinishedByEqualsEntailment.ToString()] = await TIMEFinishedByEqualsEntailmentRule.ExecuteRuleAsync(ontology); break; case TIMEEnums.TIMEReasonerRules.FinishesEqualsEntailment: inferenceRegistry[TIMEEnums.TIMEReasonerRules.FinishesEqualsEntailment.ToString()] = await TIMEFinishesEqualsEntailmentRule.ExecuteRuleAsync(ontology); break; - case TIMEEnums.TIMEReasonerRules.MeetsEqualsEntailment: + /*case TIMEEnums.TIMEReasonerRules.MeetsEqualsEntailment: inferenceRegistry[TIMEEnums.TIMEReasonerRules.MeetsEqualsEntailment.ToString()] = await TIMEMeetsEqualsEntailmentRule.ExecuteRuleAsync(ontology); break; case TIMEEnums.TIMEReasonerRules.MeetsStartsEntailment: