Skip to content

Commit

Permalink
Merge pull request #85 from labra/issue83
Browse files Browse the repository at this point in the history
Issue83
  • Loading branch information
labra authored Mar 11, 2018
2 parents b46e669 + 4a6cc74 commit 87eb02c
Show file tree
Hide file tree
Showing 53 changed files with 1,129 additions and 134 deletions.
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Guide for contributors

This project follows a standard [fork and pull][fork-and-pull] model for accepting contributions via
GitHub pull requests:

0. [Pick (or report) an issue](#pick-or-report-an-issue)
1. [Write code](#write-code)
2. [Write tests](#write-tests)
3. [Submit a pull request](#submit-a-pull-request)

## Pick or report an issue

We always welcome bug reports and feature requests—please don't feel like you need to have time to
contribute a fix or implementation for your issue to be appreciated.

## Write code

We prefer functional programming for the code.

* Code and comments should be formatted to a width no greater than 100 columns.
* Files should not contain trailing spaces.
* Imports should be sorted alphabetically.

When in doubt, please run `sbt scalastyle` and let us know if you have any questions.

## Write tests

Shaclex uses [ScalaTest][scalatest] for testing.

## Submit a pull request

* Pull requests should be submitted from a separate branch (e.g. using
`git checkout -b "username/fix-123"`).
* In general we discourage force pushing to an active pull-request branch that other people are
commenting on or contributing to, and suggest using `git merge master` during development.
Once development is complete, use `git rebase master` and force push to [clean up the history][squash].
* The first line of a commit message should be no more than 72 characters long (to accommodate
formatting in various environments).
* Commit messages should general use the present tense, normal sentence capitalization, and no final
punctuation.
* If a pull request decreases code coverage more than by 2%, please file an issue to make sure that
tests get added.

This guide for contributors is inspired by [circe's guide](https://github.com/circe/circe/blob/master/CONTRIBUTING.md).
56 changes: 48 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ lazy val http4sVersion = "0.18.0-M8"
lazy val scalatagsVersion = "0.6.7"
lazy val scallopVersion = "3.1.1"
lazy val jenaVersion = "3.6.0"
lazy val rdf4jVersion = "2.2.4"
lazy val jgraphtVersion = "1.1.0"
lazy val diffsonVersion = "2.2.5"
lazy val xercesVersion = "2.11.0"
Expand All @@ -59,6 +60,9 @@ lazy val jgraphtCore = "org.jgrapht" % "jgrapht-core"
lazy val antlr4 = "org.antlr" % "antlr4" % antlrVersion
lazy val xercesImpl = "xerces" % "xercesImpl" % xercesVersion
lazy val jenaArq = "org.apache.jena" % "jena-arq" % jenaVersion
lazy val rdf4j = "org.eclipse.rdf4j" % "rdf4j" % rdf4jVersion
lazy val rdf4jModel = "org.eclipse.rdf4j" % "rdf4j-model" % rdf4jVersion
lazy val rdf4j_rioTurtle = "org.eclipse.rdf4j" % "rdf4j-rio-turtle" % rdf4jVersion
lazy val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % loggingVersion
lazy val scallop = "org.rogach" %% "scallop" % scallopVersion
lazy val scalactic = "org.scalactic" %% "scalactic" % scalacticVersion
Expand Down Expand Up @@ -94,8 +98,8 @@ lazy val shaclex = project
// buildInfoPackage := "es.weso.shaclex.buildinfo"
// )
.settings(commonSettings, packagingSettings, publishSettings, ghPagesSettings, wixSettings)
.aggregate(schema, shacl, shex, manifest, srdfJena, srdf, utils, converter, rbe, typing, validating, server, shapeMaps, depGraphs)
.dependsOn(schema, shacl, shex, manifest, srdfJena, srdf, utils, converter, rbe, typing, validating, server, shapeMaps, depGraphs)
.aggregate(schema, shacl, shex, manifest, srdfJena, srdf4j, srdf, utils, converter, rbe, typing, validating, server, shapeMaps, depGraphs)
.dependsOn(schema, shacl, shex, manifest, srdfJena, srdf4j, srdf, utils, converter, rbe, typing, validating, server, shapeMaps, depGraphs)
.settings(
unidocProjectFilter in (ScalaUnidoc, unidoc) := inAnyProject -- inProjects(noDocProjects: _*),
libraryDependencies ++= Seq(
Expand Down Expand Up @@ -132,7 +136,12 @@ lazy val shacl = project
.in(file("modules/shacl"))
.disablePlugins(RevolverPlugin)
.settings(commonSettings, publishSettings)
.dependsOn(srdfJena, manifest, utils, typing, validating)
.dependsOn(srdf,
manifest,
utils,
typing,
validating,
srdfJena % Test)
.settings(
logBuffered in Test := false,
parallelExecution in Test := false,
Expand Down Expand Up @@ -164,7 +173,18 @@ lazy val shex = project
testOptions in Test := Seq(Tests.Filter(testFilter)),
testOptions in CompatTest := Seq(Tests.Filter(compatFilter)),
)
.dependsOn(srdfJena, srdf, typing, utils % "test -> test; compile -> compile", validating, shapeMaps, rbe, manifest, depGraphs)
.dependsOn(
srdf,
typing,
utils % "test -> test; compile -> compile",
validating,
shapeMaps,
rbe,
manifest,
depGraphs,
srdfJena % Test,
srdf4j % Test
)
.settings(
libraryDependencies ++= Seq(
typesafeConfig % Test,
Expand All @@ -181,10 +201,13 @@ lazy val shapeMaps = project
.enablePlugins(Antlr4Plugin)
.disablePlugins(RevolverPlugin)
.settings(commonSettings, publishSettings, antlrSettings("es.weso.shapeMaps.parser"))
.dependsOn(srdfJena)
.dependsOn(
srdf,
utils,
srdfJena % Test)
.settings(
libraryDependencies ++= Seq(
sext,
sext % Test,
scalaLogging,
catsCore,
catsKernel,
Expand Down Expand Up @@ -221,7 +244,7 @@ lazy val manifest = project
.in(file("modules/manifest"))
.disablePlugins(RevolverPlugin)
.settings(commonSettings, publishSettings)
.dependsOn(srdfJena, utils)
.dependsOn(srdf, utils, srdfJena)
.settings(
libraryDependencies ++= Seq(
typesafeConfig % Test,
Expand Down Expand Up @@ -278,6 +301,23 @@ lazy val srdfJena = project
)
)

lazy val srdf4j = project
.in(file("modules/srdf4j"))
.disablePlugins(RevolverPlugin)
.dependsOn(srdf, utils)
.settings(commonSettings, publishSettings)
.settings(
libraryDependencies ++= Seq(
logbackClassic,
scalaLogging,
typesafeConfig % Test,
rdf4j, rdf4jModel, rdf4j_rioTurtle,
catsCore,
catsKernel,
catsMacros
)
)

lazy val typing = project
.in(file("modules/typing"))
.disablePlugins(RevolverPlugin)
Expand Down Expand Up @@ -312,7 +352,7 @@ lazy val utils = project
lazy val validating = project
.in(file("modules/validating"))
.disablePlugins(RevolverPlugin)
.dependsOn(srdfJena, utils % "test -> test; compile -> compile")
.dependsOn(srdf, srdfJena % Test, utils % "test -> test; compile -> compile")
.settings(commonSettings, publishSettings)
.settings(
libraryDependencies ++= Seq(
Expand Down
3 changes: 3 additions & 0 deletions modules/converter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Converter module

Converts between ShEx and SHACL
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ object Shacl2ShEx extends Converter {
shex.IRILabel(iri)

def mkBNodeLabel(n: Int): shex.ShapeLabel =
shex.BNodeLabel(BNodeId(n.toString))
shex.BNodeLabel(BNode(n.toString))

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object ShEx2Shacl extends Converter {

def newBNode: RDFNode = {
bNodeCounter += 1
BNodeId("shape" + (bNodeCounter))
BNode("shape" + (bNodeCounter))
}

var shapesMap: Map[shacl.ShapeRef, shacl.Shape] = Map()
Expand Down
3 changes: 3 additions & 0 deletions modules/depGraphs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dependency Graphs module

Checks if there are cycles in dependency graphs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ case class RDF2Manifest(base: Option[IRI],
case iri: IRI =>
if (noType(iri, rdf)) Right(IRIResult(iri))
else compoundResult(iri, rdf)
case bNode: BNodeId => compoundResult(bNode, rdf)
case bNode: BNode => compoundResult(bNode, rdf)
case _ => parseFail("Unexpected type of result " + n)
}
}
Expand Down
3 changes: 3 additions & 0 deletions modules/rbe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RBE (Regular Bag Expressions) implementation

This module implements Regular Bag Expressions
4 changes: 4 additions & 0 deletions modules/schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Schema

This module defines a generic Schema interface which can be used to validate elements.
We provide two implementations of this interface, for ShEx and for SHACL.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ case class ShaclexSchema(schema: ShaclSchema) extends Schema {
private def cnvShape(s: Shape): ShapeMapLabel = {
s.id match {
case iri: IRI => IRILabel(iri)
case bnode: BNodeId => BNodeLabel(bnode)
case bnode: BNode => BNodeLabel(bnode)
case _ => throw new Exception(s"cnvShape: unexpected ${s.id}")
}
}
Expand Down
11 changes: 11 additions & 0 deletions modules/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Server module

This module implements a simple server based on the [http4s](http://http4s.org/) library.

The server contains a simple REST API defined [here](https://github.com/labra/shaclex/blob/master/modules/server/src/main/scala/es/weso/server/APIService.scala) and a web service that calls the REST API.
The web service has been implemented using [Twirl templates](https://www.playframework.com/documentation/2.6.x/ScalaTemplates)
which are defined [in this folder](https://github.com/labra/shaclex/tree/master/modules/server/src/main/twirl/es/weso).
Some parts of the web service are implemennted in plain Javascript [here](https://github.com/labra/shaclex/tree/master/modules/server/src/main/resources/staticviews/js).
In the future, it would be better to replace that Javascript code by ScalaJs.

The server is deployed at [shaclex](http://shaclex.validatingrdf.com).
3 changes: 3 additions & 0 deletions modules/shacl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SHACL implementation

This module implements [SHACL](https://www.w3.org/TR/shacl/) on top of the [SRDF] interface so it can be used by [Apache Jena](https://jena.apache.org/) or [RDF4j](http://rdf4j.org/).
2 changes: 1 addition & 1 deletion modules/shacl/src/main/scala/es/weso/shacl/Shacl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ sealed abstract class Shape {
def showId: String =
id match {
case iri: IRI => iri.str
case bnode: BNodeId => bnode.toString
case bnode: BNode => bnode.toString
}

def targetNodes: Seq[RDFNode] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ object RDF2Shacl extends RDFParser with LazyLogging {
def parsePath: RDFParser[SHACLPath] = (n, rdf) => {
n match {
case iri: IRI => Right(PredicatePath(iri))
case bnode: BNodeId => someOf(
case bnode: BNode => someOf(
inversePath,
oneOrMorePath,
zeroOrMorePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ case class Validator(schema: Schema) extends LazyLogging {
private def equalsNode(n1: RDFNode, n2: RDFNode): Boolean = (n1, n2) match {
case (l1: Literal, l2: Literal) => l1 == l2
case (i1: IRI, i2: IRI) => i1 == i2
case (b1: BNodeId, b2: BNodeId) => b1 == b2
case (b1: BNode, b2: BNode) => b1 == b2
case (_, _) => false
}

Expand All @@ -796,7 +796,7 @@ case class Validator(schema: Schema) extends LazyLogging {
case (DatatypeLiteral(n1, d1), DatatypeLiteral(n2, d2)) => d1 == d2 && n1 < n2
case (LangLiteral(n1, l1), LangLiteral(n2, l2)) => n1 < n2
case (i1: IRI, i2: IRI) => i1.str < i2.str
case (b1: BNodeId, b2: BNodeId) => b1.id < b2.id
case (b1: BNode, b2: BNode) => b1.id < b2.id
case (_, _) => false
}
private def lessThanOrEqualNode(n1: RDFNode, n2: RDFNode): Boolean = (n1, n2) match {
Expand All @@ -807,7 +807,7 @@ case class Validator(schema: Schema) extends LazyLogging {
case (DatatypeLiteral(n1, d1), DatatypeLiteral(n2, d2)) => d1 == d2 && n1 <= n2
case (LangLiteral(n1, l1), LangLiteral(n2, l2)) => n1 <= n2
case (i1: IRI, i2: IRI) => i1.str <= i2.str
case (b1: BNodeId, b2: BNodeId) => b1.id <= b2.id
case (b1: BNode, b2: BNode) => b1.id <= b2.id
case (_, _) => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AbstractSyntaxTest extends FunSpec with Matchers {

describe("Abstract Syntax") {
it("should be able to create a shape") {
val x = BNodeId("x")
val x = BNode("x")
val c: PropertyShape =
PropertyShape(
id = x,
Expand Down
3 changes: 3 additions & 0 deletions modules/shapeMaps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Shape maps implementation

Implementation of [shape maps](http://shex.io/shape-map/) which can be used to trigger validation. Although shape maps were defined by the ShEx community group they can also be used in SHACL.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.circe.syntax._
import NodeSelector._
import ShapeMapLabel._
import es.weso.json.DecoderUtils._
import es.weso.rdf.nodes.{ BNodeId, IRI, RDFNode }
import es.weso.rdf.nodes.{ BNode, IRI, RDFNode }

case class Association(node: NodeSelector, shape: ShapeMapLabel, info: Info = Info()) {

Expand Down Expand Up @@ -44,7 +44,7 @@ object Association {
s => Left(DecodingFailure(s, Nil)),
node => node match {
case iri: IRI => Right(IRILabel(iri))
case bnode: BNodeId => Right(BNodeLabel(bnode))
case bnode: BNode => Right(BNodeLabel(bnode))
case _ => Left(DecodingFailure(s"Cannot parse shapeMapLabel $node", Nil))
}))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package es.weso.shapeMaps
import es.weso.rdf.nodes.{ BNodeId, IRI }
import es.weso.rdf.nodes.{ BNode, IRI }
import io.circe.{ Encoder, Json }

abstract class ShapeMapLabel {
Expand All @@ -14,7 +14,7 @@ abstract class ShapeMapLabel {
}

case class IRILabel(iri: IRI) extends ShapeMapLabel
case class BNodeLabel(bnode: BNodeId) extends ShapeMapLabel
case class BNodeLabel(bnode: BNode) extends ShapeMapLabel
case object Start extends ShapeMapLabel

object ShapeMapLabel {
Expand Down
5 changes: 5 additions & 0 deletions modules/shex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ShEx library

ShEx 2.0 implementation.

The implementation is defined in terms of the [SRDF](https://github.com/labra/shaclex/tree/master/modules/srdf) interface so it can work with both [Apache Jena](https://jena.apache.org/) and [RDF4j](http://rdf4j.org/).
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,8 @@ class SchemaMaker extends ShExDocBaseVisitor[Any] with LazyLogging {
}
}

override def visitBlankNode(ctx: BlankNodeContext): Builder[BNodeId] = {
ok(BNodeId(removeUnderscore(ctx.BLANK_NODE_LABEL().getText())))
override def visitBlankNode(ctx: BlankNodeContext): Builder[BNode] = {
ok(BNode(removeUnderscore(ctx.BLANK_NODE_LABEL().getText())))
}

def removeUnderscore(str: String): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ object decoderShEx {
/* implicit lazy val keyDecoderShapeLabel: KeyDecoder[ShapeLabel] =
KeyDecoder.instance { str => parseShapeLabel(str).toOption } */

implicit lazy val decodeBNodeId: Decoder[BNodeId] =
Decoder[String].map(BNodeId(_))
implicit lazy val decodeBNodeId: Decoder[BNode] =
Decoder[String].map(BNode(_))

implicit lazy val decodeIRI: Decoder[IRI] =
Decoder[String].emap(parseIRI(_))
Expand Down Expand Up @@ -412,7 +412,7 @@ object decoderShEx {
def parseShapeLabel(str: String): Either[String, ShapeLabel] = {
str match {
// Be careful with the order...
case bNodeRegex(bNodeId) => Either.right(BNodeLabel(BNodeId(bNodeId)))
case bNodeRegex(bNodeId) => Either.right(BNodeLabel(BNode(bNodeId)))
case iriRegex(i) => parseIRI(i).map(iri => IRILabel(iri))
case _ => Either.left(s"$str doesn't match IRI or BNode")
}
Expand Down
2 changes: 1 addition & 1 deletion modules/shex/src/main/scala/es/weso/shex/shex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ abstract sealed trait ShapeLabel {
}
}
case class IRILabel(iri: IRI) extends ShapeLabel
case class BNodeLabel(bnode: BNodeId) extends ShapeLabel
case class BNodeLabel(bnode: BNode) extends ShapeLabel

object Schema {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait RDF2ShEx extends RDFParser with LazyLogging {

private def mkId(n: RDFNode): Option[ShapeLabel] = n match {
case iri: IRI => Some(IRILabel(iri))
case bnode: BNodeId => Some(BNodeLabel(bnode))
case bnode: BNode => Some(BNodeLabel(bnode))
case _ => None // TODO: Raise an exception?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class ShapeTyping(t: Typing[RDFNode, ShapeType, ViolationError, String]) ex
case None => Left(s"Can't create Result shape map for a shape expression without label. ShapeExpr: ${s.shape}")
case Some(lbl) => lbl.toRDFNode match {
case i: IRI => Either.right(IRIMapLabel(i))
case b: BNodeId => Either.right(BNodeLabel(b))
case b: BNode => Either.right(BNodeLabel(b))
case _ => Left(s"Can't create Result shape map for a shape expression with label: $lbl")
}
}
Expand Down
Loading

0 comments on commit 87eb02c

Please sign in to comment.