From 6da566b134780a7769af5a709c771fbd679a4a0d Mon Sep 17 00:00:00 2001 From: Jose Labra Date: Sat, 18 Aug 2018 09:07:53 +0200 Subject: [PATCH] Repaired errors and added sh:severity and sh:message support --- .../es/weso/shex/converter/CountUsages.scala | 2 +- .../weso/shex/converter/CountUsagesTest.scala | 6 +-- .../weso/shacl/report/ValidationResult.scala | 40 +++++++++++-------- .../es/weso/shacl/validator/AttemptInfo.scala | 3 +- .../es/weso/shacl/AbstractSyntaxTest.scala | 3 +- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/modules/converter/src/main/scala/es/weso/shex/converter/CountUsages.scala b/modules/converter/src/main/scala/es/weso/shex/converter/CountUsages.scala index 556a8676..d531f1af 100644 --- a/modules/converter/src/main/scala/es/weso/shex/converter/CountUsages.scala +++ b/modules/converter/src/main/scala/es/weso/shex/converter/CountUsages.scala @@ -38,7 +38,7 @@ object CountUsages { } private def tripleExprBNodeLabels(schema: Schema): List[ShapeLabel] = - schema.tripleExprMap.getOrElse(Map()).keys.toList.filter(isBNode(_)) + schema.tripleExprMap.getOrElse(Map()).keys.toList // .filter(isBNode(_)) private def countUsagesSchema: Result[Map[ShapeLabel,Int]] = for { schema <- getSchema diff --git a/modules/converter/src/test/scala/es/weso/shex/converter/CountUsagesTest.scala b/modules/converter/src/test/scala/es/weso/shex/converter/CountUsagesTest.scala index 1abd6885..19a22be3 100644 --- a/modules/converter/src/test/scala/es/weso/shex/converter/CountUsagesTest.scala +++ b/modules/converter/src/test/scala/es/weso/shex/converter/CountUsagesTest.scala @@ -3,8 +3,8 @@ package es.weso.shex.converter import cats._ import es.weso._ import es.weso.rdf.jena.RDFAsJenaModel -import es.weso.rdf.nodes.BNode -import es.weso.shex.{BNodeLabel, Schema, ShapeLabel} +import es.weso.rdf.nodes._ +import es.weso.shex._ import es.weso.shex.implicits.eqShEx._ import org.scalatest._ @@ -25,7 +25,7 @@ class CountUsagesTest extends FunSpec with Matchers with EitherValues { |_:1 { | $:PS :p IRI |} - """.stripMargin, Map(BNodeLabel(BNode("PS")) -> 1)) + """.stripMargin, Map(IRILabel(IRI("http://example.org/PS")) -> 1)) } def shouldCount(shexStr: String, diff --git a/modules/shacl/src/main/scala/es/weso/shacl/report/ValidationResult.scala b/modules/shacl/src/main/scala/es/weso/shacl/report/ValidationResult.scala index f521074a..8f161032 100644 --- a/modules/shacl/src/main/scala/es/weso/shacl/report/ValidationResult.scala +++ b/modules/shacl/src/main/scala/es/weso/shacl/report/ValidationResult.scala @@ -11,26 +11,32 @@ import es.weso.shacl.validator.Attempt abstract class AbstractResult -class ValidationResult(val focusNode: RDFNode, - val resultSeverity: Severity, - val sourceConstraintComponent: IRI, - val focusPath: Option[SHACLPath], - val sourceShape: ShapeRef, - val values: Seq[RDFNode], - val message: Seq[LiteralValue], - val messageMap: MessageMap, - val details: Seq[AbstractResult] - ) { +case class ValidationResult(focusNode: RDFNode, + resultSeverity: Severity, + sourceConstraintComponent: IRI, + focusPath: Option[SHACLPath], + sourceShape: ShapeRef, + values: Seq[RDFNode], + message: Seq[LiteralValue], + messageMap: MessageMap, + details: Seq[AbstractResult] + ) extends AbstractResult { + + def setSeverity(s: Severity): ValidationResult = + this.copy(resultSeverity = s) + override def toString = s"Violation error on $focusNode: ${message.mkString(",")}" } object ValidationResult { - def basic(suffix: String, focusNode: RDFNode, attempt: Attempt, msg: String, - messageMap: MessageMap = MessageMap.empty + def basic(suffix: String, + focusNode: RDFNode, + attempt: Attempt, + msg: String ) = - new ValidationResult( + ValidationResult( sourceConstraintComponent = sh + suffix, focusNode = focusNode, resultSeverity = attempt.severity, @@ -38,18 +44,18 @@ object ValidationResult { values = Seq(), focusPath = attempt.path, message = Seq(LiteralValue(StringLiteral(msg))), - messageMap = messageMap, + messageMap = attempt.messageMap, details = Seq() ) def notFoundShapeRef(node: RDFNode, attempt: Attempt, msg: String) = - basic("NotFoundShapeRef", node, attempt, msg, MessageMap.fromString(msg)) + basic("NotFoundShapeRef", node, attempt, msg) def expectedPropertyShape(node: RDFNode, attempt: Attempt, msg: String) = - basic("ExpectedPropertyShape", node, attempt, msg, MessageMap.fromString(msg)) + basic("ExpectedPropertyShape", node, attempt, msg) def shapesFailed(node: RDFNode, shape: Shape, ps: Set[Shape], attempt: Attempt, msg: String) = - basic("ShapesFailed", node, attempt, msg, MessageMap.fromString(msg)) + basic("ShapesFailed", node, attempt, msg).setSeverity(InfoSeverity) def regexError(node: RDFNode, attempt: Attempt, msg: String) = basic("RegEx error", node, attempt, msg) diff --git a/modules/shacl/src/main/scala/es/weso/shacl/validator/AttemptInfo.scala b/modules/shacl/src/main/scala/es/weso/shacl/validator/AttemptInfo.scala index 59f6b757..978ad3ec 100644 --- a/modules/shacl/src/main/scala/es/weso/shacl/validator/AttemptInfo.scala +++ b/modules/shacl/src/main/scala/es/weso/shacl/validator/AttemptInfo.scala @@ -8,7 +8,8 @@ import es.weso.shacl.{MessageMap, ShapeRef} case class AttemptInfo(node: RDFNode, shape: ShapeRef, messageMap: MessageMap, - severity: Severity) { + severity: Severity + ) { override def toString = AttemptInfo.nodeShapeShow.show(this) diff --git a/modules/shacl/src/test/scala/es/weso/shacl/AbstractSyntaxTest.scala b/modules/shacl/src/test/scala/es/weso/shacl/AbstractSyntaxTest.scala index a76806f1..4cd9900d 100644 --- a/modules/shacl/src/test/scala/es/weso/shacl/AbstractSyntaxTest.scala +++ b/modules/shacl/src/test/scala/es/weso/shacl/AbstractSyntaxTest.scala @@ -17,7 +17,8 @@ class AbstractSyntaxTest extends FunSpec with Matchers { false, List(), false, - MessageMap.empty + MessageMap.empty, + None ) shape.id should be(id)