Skip to content

Commit

Permalink
Merge pull request #94 from labra/issue60
Browse files Browse the repository at this point in the history
Solve issue60
  • Loading branch information
labra authored Apr 2, 2018
2 parents 779cd77 + 5310b12 commit eef2d83
Show file tree
Hide file tree
Showing 58 changed files with 1,235 additions and 1,025 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ It is possible to run the program inside `sbt` as:

### Validating RDF data with SHACL

Example:
Example with conformant RDF data:

```
sbt "run -d examples/shacl/good1.ttl --engine ShaClex"
```

Example with non-conformant RDF generating SHACL validation report:

```
sbt "run -d examples/shacl/bad1.ttl --engine ShaClex --showValidationReport --validationReportFormat TURTLE"
```


### Validating RDF with ShEx

Example:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ lazy val shaclex = project
.settings(
unidocProjectFilter in (ScalaUnidoc, unidoc) := inAnyProject -- inProjects(noDocProjects: _*),
libraryDependencies ++= Seq(
logbackClassic % Test,
logbackClassic,
scalaLogging,
scallop
),
Expand Down
30 changes: 30 additions & 0 deletions examples/shacl/tests/and-001.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://datashapes.org/sh/tests/core/node/and-001.test#> .
@prefix : <http://example.org/> .
@prefix mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix sht: <http://www.w3.org/ns/shacl-test#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:InvalidRectangle1
rdf:type ex:Rectangle ;
ex:height 3 ;
.

:c1 sh:property :p1 .
:p1 sh:path ex:width ;
sh:minCount 1 .

:c2 sh:property :p2 .
:p2 sh:path ex:height ;
sh:minCount 1 .

ex:Rectangle
rdf:type rdfs:Class ;
rdf:type sh:NodeShape ;
rdfs:subClassOf rdfs:Resource ;
sh:and ( :c1 :c2 ) ;
.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ManifestPrefixes._
import es.weso.rdf.parser.RDFParser
import es.weso.rdf.jena.RDFAsJenaModel
import es.weso.utils.FileUtils._
import cats._
import cats.implicits._
import com.typesafe.scalalogging.LazyLogging

Expand Down

This file was deleted.

120 changes: 0 additions & 120 deletions modules/schema/src/main/scala/es/weso/schema/InfoNode.toDelete

This file was deleted.

15 changes: 8 additions & 7 deletions modules/schema/src/main/scala/es/weso/schema/Result.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package es.weso.schema

import cats.Show
import com.typesafe.scalalogging.LazyLogging
import es.weso.rdf.PrefixMap
import es.weso.rdf.nodes.{ IRI, RDFNode }
import io.circe.JsonObject._
import es.weso.rdf.{PrefixMap, RDFReader}
import es.weso.rdf.nodes.{IRI, RDFNode}
import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._
import cats.syntax.either._
import cats.instances.either._
import es.weso.shapeMaps._
import es.weso.utils.MapUtils._

case class Result(
isValid: Boolean,
message: String,
shapeMaps: Seq[ResultShapeMap],
validationReport: Either[String,RDFReader],
errors: Seq[ErrorInfo],
trigger: Option[ValidationTrigger],
nodesPrefixMap: PrefixMap,
Expand Down Expand Up @@ -145,6 +144,7 @@ object Result extends LazyLogging {
isValid = true,
message = "",
shapeMaps = Seq(),
validationReport = Left("No report"),
errors = Seq(),
None,
PrefixMap.empty,
Expand Down Expand Up @@ -195,17 +195,18 @@ object Result extends LazyLogging {
solutions <- if (isValid) {
for {
ls <- c.downField("shapeMap").as[List[ResultShapeMap]]
} yield ls.toSeq
} yield ls
} else Right(Seq())
errors <- if (isValid) {
Right(Seq())
} else for {
ls <- c.downField("shapeMap").as[List[ErrorInfo]]
} yield ls.toSeq
} yield ls
} yield Result(
isValid,
message,
solutions,
Left("Not implemented ValidationReport Json decoder yet"),
errors,
trigger,
nodesPrefixMap,
Expand Down
4 changes: 1 addition & 3 deletions modules/schema/src/main/scala/es/weso/schema/Schemas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import util._
import es.weso.rdf.RDFReader
import es.weso.utils.FileUtils

import scala.io._
import scala.util.{ Failure, Success, Try }

object Schemas {

type SchemaParser = (CharSequence, String, Option[String]) => Either[String, Schema]
Expand All @@ -27,6 +24,7 @@ object Schemas {
availableSchemas.map(_.formats).flatten.distinct
}


val availableTriggerModes: List[String] = {
ValidationTrigger.triggerValues.map(_._1)
}
Expand Down
28 changes: 21 additions & 7 deletions modules/schema/src/main/scala/es/weso/schema/ShExSchema.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.weso.schema

import cats._
import com.typesafe.scalalogging.LazyLogging
import data._
import implicits._
import es.weso.rdf._
import es.weso.rdf.nodes._
Expand All @@ -10,11 +10,8 @@ import es.weso.shapeMaps._
import es.weso.shex.{ Schema => Schema_, _ }
import es.weso.shex.validator._
import es.weso.shex._
import es.weso.typing._
import es.weso.shex.shexR._

import scala.util._
import es.weso.shex.implicits.showShEx.showShapeLabel

case class ShExSchema(schema: Schema_) extends Schema with LazyLogging {
override def name = "ShEx"
Expand Down Expand Up @@ -52,10 +49,12 @@ case class ShExSchema(schema: Schema_) extends Schema with LazyLogging {
false,
message = "Error validating",
shapeMaps = Seq(),
validationReport = Left("No validation report in ShEx"),
errors = Seq(ErrorInfo(msg)), None, rdf.getPrefixMap(), schema.prefixMap)
case Right(resultShapeMap) =>
Result(true, "Validated",
shapeMaps = Seq(resultShapeMap),
validationReport = Left(s"No validaton report in ShEx"),
errors = Seq(), None, rdf.getPrefixMap(), schema.prefixMap)
}

Expand All @@ -80,10 +79,24 @@ case class ShExSchema(schema: Schema_) extends Schema with LazyLogging {
rdf: RDFReader): Result = {
Validator.validate(schema, shapeMap, rdf) match {
case Left(error) =>
Result(false, "Error validating", Seq(), Seq(ErrorInfo(error)), None, rdf.getPrefixMap(), schema.prefixMap)
Result(false,
"Error validating",
Seq(),
Left("No validation report yet"),
Seq(ErrorInfo(error)),
None,
rdf.getPrefixMap(),
schema.prefixMap)
case Right(resultShapeMap) => {
// println(s"Validated, result=$resultShapeMap")
Result(true, "Validated", Seq(resultShapeMap), Seq(), None, rdf.getPrefixMap(), schema.prefixMap)
Result(true,
"Validated",
Seq(resultShapeMap),
Left(s"No validation report for ShEx"),
Seq(),
None,
rdf.getPrefixMap(),
schema.prefixMap)
}
}
}
Expand Down Expand Up @@ -148,8 +161,9 @@ case class ShExSchema(schema: Schema_) extends Schema with LazyLogging {
RDF2ShEx.rdf2Schema(rdf).map(ShExSchema(_))

override def serialize(format: String): Either[String, String] = {
val builder: RDFBuilder = RDFAsJenaModel.empty
if (formatsUpperCase.contains(format.toUpperCase()))
Schema_.serialize(schema, format)
Schema_.serialize(schema, format, builder)
else
Left(s"Can't serialize to format $format. Supported formats=$formats")
}
Expand Down
Loading

0 comments on commit eef2d83

Please sign in to comment.