From 418996179c790aa19a9913e39d5b9f9cafb4a2ce Mon Sep 17 00:00:00 2001 From: Jose Labra Date: Mon, 20 Aug 2018 10:13:39 +0200 Subject: [PATCH] Release 0.1.04 --- .../es/weso/shacl/validator/Validator.scala | 2 +- .../test/resources/shacl/imports/import.ttl | 2 + .../shacl/imports/importWithLoop.ttl | 18 ++++++ .../src/test/resources/shacl/imports/loop.ttl | 14 +++++ .../test/scala/es/weso/shacl/ImportTest.scala | 60 +++++++++++++++++++ notes/0.1.04.md | 16 +++++ version.sbt | 2 +- 7 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 modules/shacl/src/test/resources/shacl/imports/importWithLoop.ttl create mode 100644 modules/shacl/src/test/resources/shacl/imports/loop.ttl create mode 100644 modules/shacl/src/test/scala/es/weso/shacl/ImportTest.scala create mode 100644 notes/0.1.04.md diff --git a/modules/shacl/src/main/scala/es/weso/shacl/validator/Validator.scala b/modules/shacl/src/main/scala/es/weso/shacl/validator/Validator.scala index 853639a7..a71730ee 100644 --- a/modules/shacl/src/main/scala/es/weso/shacl/validator/Validator.scala +++ b/modules/shacl/src/main/scala/es/weso/shacl/validator/Validator.scala @@ -19,7 +19,7 @@ import es.weso.rdf.operations.Comparisons._ * This validator is implemented directly in Scala using cats library */ -case class Validator(schema: Schema) extends MyLogging { +case class Validator(schema: Schema) extends LazyLogging { /** * Return all targetNode declarations which are pairs (n,s) where diff --git a/modules/shacl/src/test/resources/shacl/imports/import.ttl b/modules/shacl/src/test/resources/shacl/imports/import.ttl index a8e6b840..05d16c87 100644 --- a/modules/shacl/src/test/resources/shacl/imports/import.ttl +++ b/modules/shacl/src/test/resources/shacl/imports/import.ttl @@ -12,5 +12,7 @@ prefix owl: sh:property :hasName . :Person sh:targetNode :alice . +:Person sh:targetNode :bob . :alice :name "Alice" . +:bob :age 23 . # Has no name \ No newline at end of file diff --git a/modules/shacl/src/test/resources/shacl/imports/importWithLoop.ttl b/modules/shacl/src/test/resources/shacl/imports/importWithLoop.ttl new file mode 100644 index 00000000..bf95a7c2 --- /dev/null +++ b/modules/shacl/src/test/resources/shacl/imports/importWithLoop.ttl @@ -0,0 +1,18 @@ +prefix : +prefix foaf: +prefix rdfs: +prefix schema: +prefix sh: +prefix xsd: +prefix owl: + +<> owl:imports . + +:Person a sh:NodeShape ; + sh:property :hasName . + +:Person sh:targetNode :alice . +:Person sh:targetNode :bob . + +:alice :name "Alice" . +:bob :age 23 . # Has no name \ No newline at end of file diff --git a/modules/shacl/src/test/resources/shacl/imports/loop.ttl b/modules/shacl/src/test/resources/shacl/imports/loop.ttl new file mode 100644 index 00000000..efee439d --- /dev/null +++ b/modules/shacl/src/test/resources/shacl/imports/loop.ttl @@ -0,0 +1,14 @@ +prefix : +prefix foaf: +prefix rdfs: +prefix schema: +prefix sh: +prefix xsd: +prefix owl: + +# An infinite loop as it imports itself... +<> owl:imports . + +:hasName a sh:PropertyShape ; + sh:path :name ; + sh:minCount 1 . diff --git a/modules/shacl/src/test/scala/es/weso/shacl/ImportTest.scala b/modules/shacl/src/test/scala/es/weso/shacl/ImportTest.scala new file mode 100644 index 00000000..17930b55 --- /dev/null +++ b/modules/shacl/src/test/scala/es/weso/shacl/ImportTest.scala @@ -0,0 +1,60 @@ +package es.weso.shacl + +import java.nio.file.Paths + +import com.typesafe.config.{Config, ConfigFactory} +import es.weso.rdf.jena.RDFAsJenaModel +import es.weso.rdf.nodes.IRI +import es.weso.shacl.converter.RDF2Shacl +import es.weso.shacl.validator.Validator +import org.scalatest._ + +class ImportTest extends FunSpec with Matchers with TryValues with OptionValues + with SchemaMatchers { + + val conf: Config = ConfigFactory.load() + val shaclFolderStr = conf.getString("shaclTests") + val shaclFolder = IRI(Paths.get(shaclFolderStr).normalize.toUri.toString) + + describe("import") { + it(s"Validates a shape that imports another one") { + val r = for { + rdf <- RDFAsJenaModel.fromIRI(shaclFolder + "imports/import.ttl") + schema <- RDF2Shacl.getShacl(rdf) + result <- Validator.validate(schema, rdf) + } yield result + + r.fold( + e => fail(s"Error reading: $e"), + pair => { + val (typing, ok) = pair + val alice = IRI("http://example.org/alice") + val bob = IRI("http://example.org/bob") + val person = IRI("http://example.org/Person") + val hasName = IRI("http://example.org/hasName") + typing.getFailedValues(alice).map(_.id) should contain theSameElementsAs(List()) + typing.getFailedValues(bob).map(_.id) should contain theSameElementsAs(List(person,hasName)) + }) + } + + it(s"Validates a shape that imports another one with a loop") { + val r = for { + rdf <- RDFAsJenaModel.fromIRI(shaclFolder + "imports/importWithLoop.ttl") + schema <- RDF2Shacl.getShacl(rdf) + result <- Validator.validate(schema, rdf) + } yield result + + r.fold( + e => fail(s"Error reading: $e"), + pair => { + val (typing, ok) = pair + val alice = IRI("http://example.org/alice") + val bob = IRI("http://example.org/bob") + val person = IRI("http://example.org/Person") + val hasName = IRI("http://example.org/hasName") + typing.getFailedValues(alice).map(_.id) should contain theSameElementsAs(List()) + typing.getFailedValues(bob).map(_.id) should contain theSameElementsAs(List(person,hasName)) + }) + } + } +} diff --git a/notes/0.1.04.md b/notes/0.1.04.md new file mode 100644 index 00000000..594af6fe --- /dev/null +++ b/notes/0.1.04.md @@ -0,0 +1,16 @@ +# New features + +- Added support for owl:imports in SHACL + +TODOs +----- + +- ShEx: Complete semantic actions implementation [Issue 116](https://github.com/labra/shaclex/issues/116) + +- ShEx: test-suite with shape maps and update report [Issue 115](https://github.com/labra/shaclex/issues/115) + +- Shaclex: Conversion from ShEx to SHACL [Issue 114](https://github.com/labra/shaclex/issues/114) + +- Shaclex: Conversion from SHACL to ShEx [Issue 113](https://github.com/labra/shaclex/issues/113) + +- Shacl: Implement SHACL-Sparql [Issue 112](https://github.com/labra/shaclex/issues/112) diff --git a/version.sbt b/version.sbt index 6928edf8..435508a2 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.1.03" +version in ThisBuild := "0.1.04"