-
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.
v3.8.1 - Added OWLThingNothing validator rule
- Loading branch information
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
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
116 changes: 116 additions & 0 deletions
116
OWLSharp.Test/Validator/Rules/OWLThingNothingRuleTest.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,116 @@ | ||
/* | ||
Copyright 2012-2023 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 RDFSharp.Model; | ||
namespace OWLSharp.Validator.Test | ||
{ | ||
[TestClass] | ||
public class OWLThingNothingRuleTest | ||
{ | ||
#region Tests | ||
|
||
[TestMethod] | ||
public void ShouldValidateThing() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.TBoxGraph.AddTriple(new RDFTriple(RDFVocabulary.OWL.THING, RDFVocabulary.RDFS.SUB_CLASS_OF, new RDFResource("ex:SuperThing"))); | ||
|
||
OWLValidatorReport validatorReport = OWLThingNothingRule.ExecuteRule(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldValidateThing_ViaValidator() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.TBoxGraph.AddTriple(new RDFTriple(RDFVocabulary.OWL.THING, RDFVocabulary.RDFS.SUB_CLASS_OF, new RDFResource("ex:SuperThing"))); | ||
|
||
OWLValidator validator = new OWLValidator().AddStandardRule(OWLEnums.OWLValidatorStandardRules.ThingNothing); | ||
OWLValidatorReport validatorReport = validator.ApplyToOntology(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldValidateNothing() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.TBoxGraph.AddTriple(new RDFTriple(new RDFResource("ex:SubNothing"), RDFVocabulary.RDFS.SUB_CLASS_OF, RDFVocabulary.OWL.NOTHING)); | ||
|
||
OWLValidatorReport validatorReport = OWLThingNothingRule.ExecuteRule(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldValidateNothing_ViaValidator() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.TBoxGraph.AddTriple(new RDFTriple(new RDFResource("ex:SubNothing"), RDFVocabulary.RDFS.SUB_CLASS_OF, RDFVocabulary.OWL.NOTHING)); | ||
|
||
OWLValidator validator = new OWLValidator().AddStandardRule(OWLEnums.OWLValidatorStandardRules.ThingNothing); | ||
OWLValidatorReport validatorReport = validator.ApplyToOntology(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldValidateNothingIndividual() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.Classes.Add(RDFVocabulary.OWL.NOTHING.PatternMemberID, RDFVocabulary.OWL.NOTHING); | ||
ontology.Data.ABoxGraph.AddTriple(new RDFTriple(new RDFResource("ex:NothingIDV"), RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.NOTHING)); | ||
|
||
OWLValidatorReport validatorReport = OWLThingNothingRule.ExecuteRule(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldValidateNothingIndividual_ViaValidator() | ||
{ | ||
OWLOntology ontology = new OWLOntology("ex:ont"); | ||
ontology.Model.ClassModel.Classes.Add(RDFVocabulary.OWL.NOTHING.PatternMemberID, RDFVocabulary.OWL.NOTHING); | ||
ontology.Data.ABoxGraph.AddTriple(new RDFTriple(new RDFResource("ex:NothingIDV"), RDFVocabulary.RDF.TYPE, RDFVocabulary.OWL.NOTHING)); | ||
|
||
OWLValidator validator = new OWLValidator().AddStandardRule(OWLEnums.OWLValidatorStandardRules.ThingNothing); | ||
OWLValidatorReport validatorReport = validator.ApplyToOntology(ontology); | ||
|
||
Assert.IsNotNull(validatorReport); | ||
Assert.IsTrue(validatorReport.EvidencesCount == 1); | ||
Assert.IsTrue(validatorReport.SelectErrors().Count == 1); | ||
Assert.IsTrue(validatorReport.SelectWarnings().Count == 0); | ||
} | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2012-2023 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 RDFSharp.Model; | ||
|
||
namespace OWLSharp | ||
{ | ||
/// <summary> | ||
/// OWL-DL rule checking for consistency of owl:Thing (as root) and owl:Nothing (as bottom) | ||
/// </summary> | ||
internal static class OWLThingNothingRule | ||
{ | ||
internal static OWLValidatorReport ExecuteRule(OWLOntology ontology) | ||
{ | ||
OWLValidatorReport validatorRuleReport = new OWLValidatorReport(); | ||
|
||
//owl:Thing | ||
foreach (RDFResource thingSuperClass in ontology.Model.ClassModel.GetSuperClassesOf(RDFVocabulary.OWL.THING)) | ||
validatorRuleReport.AddEvidence(new OWLValidatorEvidence( | ||
OWLEnums.OWLValidatorEvidenceCategory.Error, | ||
nameof(OWLThingNothingRule), | ||
$"Violation of OWL-DL integrity caused by '{thingSuperClass}' being superClass of 'owl:Thing'", | ||
"Revise your class model: it is not allowed the use of superClasses of reserved top class 'owl:Thing'")); | ||
|
||
//owl:Nothing | ||
foreach (RDFResource nothingSubClass in ontology.Model.ClassModel.GetSubClassesOf(RDFVocabulary.OWL.NOTHING)) | ||
validatorRuleReport.AddEvidence(new OWLValidatorEvidence( | ||
OWLEnums.OWLValidatorEvidenceCategory.Error, | ||
nameof(OWLThingNothingRule), | ||
$"Violation of OWL-DL integrity caused by '{nothingSubClass}' being subClass of 'owl:Nothing'", | ||
"Revise your class model: it is not allowed the use of subClasses of reserved bottom class 'owl:Nothing'")); | ||
foreach (RDFResource nothingIndividual in ontology.Data.GetIndividualsOf(ontology.Model, RDFVocabulary.OWL.NOTHING)) | ||
validatorRuleReport.AddEvidence(new OWLValidatorEvidence( | ||
OWLEnums.OWLValidatorEvidenceCategory.Error, | ||
nameof(OWLThingNothingRule), | ||
$"Violation of OWL-DL integrity caused by '{nothingIndividual}' being individual of 'owl:Nothing'", | ||
"Revise your data: it is not allowed the use of individuals of reserved bottom class 'owl:Nothing'")); | ||
|
||
return validatorRuleReport; | ||
} | ||
} | ||
} |