Skip to content

Commit

Permalink
Added ontology-must-have-only-one-dc-contributor and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
de-husk committed Jul 11, 2014
1 parent d474371 commit f8ee99c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/scala/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ object OwLintStarter {
"ontology-must-have-dc-title" -> true,
"ontology-must-have-dc-creator" -> true,
"ontology-must-have-only-one-dc-creator" -> true,
"ontology-must-have-only-one-dc-contributor" -> true,

This comment has been minimized.

Copy link
@de-husk

de-husk Sep 28, 2016

Author Owner

This is a thread in a different commit.

This comment has been minimized.

Copy link
@de-husk

de-husk Sep 28, 2016

Author Owner

Yup I agree. 🍺

This comment has been minimized.

Copy link
@de-husk

de-husk Sep 28, 2016

Author Owner

🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹 🐹

This comment has been minimized.

Copy link
@de-husk

de-husk Sep 28, 2016

Author Owner

😸 😸 😸 😸 😸 😸 😸 😸 😸 😸 😸 😸 😸 😸 😸

"entities-must-have-rdfs-comment" -> true
)
}
Expand Down
36 changes: 35 additions & 1 deletion src/main/scala/owLint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class OwLint (config: Map[String, Boolean]) {
"ontology-must-have-version-info" -> LintFunctionDef(ontologyMustHaveVersionInfo, "The ontology must have a version info annotation."),
"ontology-must-have-dc-title" -> LintFunctionDef(ontologyMustHaveDCTitle, "The ontology must have a DC title annotation"),
"ontology-must-have-dc-creator" -> LintFunctionDef(ontologyMustHaveDCCreator, "The ontology must have a DC creator annotation"),
"ontology-must-have-only-one-dc-creator" -> LintFunctionDef(ontologyMustHaveOneDCCreator, "The ontology cannot have more than one DC creator listed in the dc:creator attribute.")
"ontology-must-have-only-one-dc-creator" -> LintFunctionDef(ontologyMustHaveOneDCCreator, "The ontology cannot have more than one DC creator listed in the dc:creator annotation."),
"ontology-must-have-only-one-dc-contributor" -> LintFunctionDef(ontologyMustHaveOneDCContributor, "The ontology cannot have more than one DC contributor in each dc:contributor annotation")
)

case class LintResult (
Expand Down Expand Up @@ -154,6 +155,39 @@ class OwLint (config: Map[String, Boolean]) {
return (true, List())
}

//ontology-must-have-only-one-dc-contributor
def ontologyMustHaveOneDCContributor (ontology: OWLOntology): (Boolean, List[OffendingInstance]) = {
val dcContributor: Option[OWLAnnotation] = ontology
.getAnnotations
.toList
.find(a => a.getProperty.getIRI.toString == "http://purl.org/dc/elements/1.1/contributor")

val hasDCContributor = dcContributor match {
case Some(t) => true
case None => false
}

if (hasDCContributor) {
//TODO: DRY BELOW
val contributorNames = dcContributor.get.getValue

val invalidCreatorReg = """(?i) and |\/|\n|_|\||\r\|\t|\v""".r

val matches = invalidCreatorReg.findFirstMatchIn(contributorNames.toString) match {
case Some(m) => true
case None => false
}

if (matches)
return (false, List(OffendingInstance("AnnotationProperty", "http://purl.org/dc/elements/1.1/contributor")))

}
(true, List())
}




// entities-must-have-rdfs-comment
def entitiesMustHaveRDFSComment (ontology: OWLOntology): (Boolean, List[OffendingInstance]) = {
val classes: List[OWLEntity] = ontology.getClassesInSignature.toList
Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/LintingTestsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ class LintingTestsSpec extends FlatSpec with Matchers{
assert(result._1 == false)
assert(result._2.length != 0)
}

"ontology-must-have-only-one-dc-contributor" should "return true on valid test owl file" in {
val result = owLintRunner.ontologyMustHaveOneDCContributor(passingOntology)
assert(result._1 == true)
assert(result._2.length == 0)
}

it should "return false on mutlple dc contributor failing test owl file" in {
val result = owLintRunner.ontologyMustHaveOneDCContributor(creatorFailingOntology)
assert(result._1 == false)
assert(result._2.length != 0)
}
}
9 changes: 5 additions & 4 deletions test/.owlint
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ontology-must-have-version-info" : false,
"ontology-must-have-dc-title" : false,
"ontology-must-have-dc-creator" : false,
"ontology-must-have-only-one-dc-creator" : false,
"ontology-must-have-version-info" : true,
"ontology-must-have-dc-title" : true,
"ontology-must-have-dc-creator" : true,
"ontology-must-have-only-one-dc-creator" : true,
"ontology-must-have-only-one-dc-contributor": true,
"entities-must-have-rdfs-comment" : true
}
1 change: 1 addition & 0 deletions test/pizza-more-than-one-creator-fails.owl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<dc:title>The Pizza Ontology</dc:title>
<dc:creator>Chef Hungry
Chef More Hungry</dc:creator>
<dc:contributor>Chef Starving and Chef Hungry III</dc:contributor>
<rdfs:comment xml:lang="en">An example ontology that contains all constructs required for the various versions of the Pizza Tutorial run by Manchester University (see http://www.co-ode.org/resources/tutorials/)</rdfs:comment>
<owl:imports rdf:resource="http://protege.stanford.edu/plugins/owl/protege"/>
<protege:defaultLanguage rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
Expand Down
1 change: 1 addition & 0 deletions test/pizza.owl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<dc:title>The Pizza Ontology</dc:title>
<rdfs:comment xml:lang="en">An example ontology that contains all constructs required for the various versions of the Pizza Tutorial run by Manchester University (see http://www.co-ode.org/resources/tutorials/)</rdfs:comment>
<dc:creator>Chef Hungry</dc:creator>
<dc:contributor>Chef Starving</dc:contributor>
<owl:imports rdf:resource="http://protege.stanford.edu/plugins/owl/protege"/>
</owl:Ontology>

Expand Down

0 comments on commit f8ee99c

Please sign in to comment.