Skip to content

Commit

Permalink
Repaired errors and added sh:severity and sh:message support
Browse files Browse the repository at this point in the history
  • Loading branch information
labra committed Aug 18, 2018
1 parent dff5856 commit 6da566b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,51 @@ 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,
sourceShape = attempt.shapeRef,
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class AbstractSyntaxTest extends FunSpec with Matchers {
false,
List(),
false,
MessageMap.empty
MessageMap.empty,
None
)

shape.id should be(id)
Expand Down

0 comments on commit 6da566b

Please sign in to comment.