Skip to content

Commit 0695bc9

Browse files
committed
Enhanced wikibase validation
1 parent 8442116 commit 0695bc9

12 files changed

Lines changed: 59 additions & 605 deletions

File tree

build.sbt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ lazy val resolverSettings = Seq(
183183
Resolver.sonatypeRepo("snapshots")
184184
)
185185
)
186-
// "sbt-github-actions" plugin settings
187-
val JavaCIVersion = "adopt@1.11"
188-
val ScalaCIVersion = "2.13.6"
189-
ThisBuild / githubWorkflowJavaVersions := Seq(JavaCIVersion)
190-
ThisBuild / githubWorkflowScalaVersions := Seq(ScalaCIVersion)
191-
192186
// Shared settings for the BuildInfo Plugin
193187
// See https://github.com/sbt/sbt-buildinfo
194188
lazy val buildInfoSettings = Seq(
@@ -275,6 +269,8 @@ lazy val server = project
275269
mongodb
276270
)
277271
)
272+
ThisBuild / githubWorkflowJavaVersions := Seq(JavaCIVersion)
273+
ThisBuild / githubWorkflowScalaVersions := Seq(ScalaCIVersion)
278274
/* ------------------------------------------------------------------------- */
279275
// Documentation project, for MDoc + Docusaurus documentation
280276
lazy val docs = project
@@ -299,8 +295,8 @@ lazy val mongodbVersion = "4.4.0"
299295
lazy val any23Version = "2.4"
300296
lazy val rdf4jVersion = "3.7.4"
301297
lazy val graphvizJavaVersion = "0.18.1"
302-
lazy val logbackVersion = "1.2.10"
303-
lazy val loggingVersion = "3.9.4"
298+
lazy val logbackVersion = "1.2.8"
299+
lazy val scalaLoggingVersion = "3.9.4"
304300
lazy val groovyVersion = "3.0.8"
305301
lazy val munitVersion = "0.7.27"
306302
lazy val munitEffectVersion = "1.0.7"
@@ -333,7 +329,7 @@ lazy val graphvizJava = "guru.nidi" % "graphviz-java" % graphvizJavaVer
333329
lazy val plantuml = "net.sourceforge.plantuml" % "plantuml" % plantumlVersion
334330
lazy val logbackClassic = "ch.qos.logback" % "logback-classic" % logbackVersion
335331
lazy val scalaLogging =
336-
"com.typesafe.scala-logging" %% "scala-logging" % loggingVersion
332+
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion
337333
lazy val groovy = "org.codehaus.groovy" % "groovy" % groovyVersion
338334
lazy val munit = "org.scalameta" %% "munit" % munitVersion
339335
lazy val munitEffect =
@@ -344,3 +340,6 @@ lazy val shexs = "es.weso" %% "shexs" % shexsVersion
344340
lazy val shaclex = "es.weso" %% "shaclex" % shaclexVersion
345341
lazy val umlShaclex = "es.weso" %% "umlshaclex" % umlShaclexVersion
346342
lazy val wesoUtils = "es.weso" %% "utilstest" % wesoUtilsVersion
343+
// "sbt-github-actions" plugin settings
344+
val JavaCIVersion = "adopt@1.11"
345+
val ScalaCIVersion = "2.13.6"

modules/server/src/main/scala/es/weso/rdfshape/server/api/routes/data/service/DataService.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class DataService(client: Client[IO])
192192
case errorMessage: String =>
193193
errorResponseJson(errorMessage, InternalServerError)
194194
case _ => // null exception message, return a general error message
195-
err.printStackTrace()
196195
errorResponseJson(
197196
DataServiceError.couldNotParseData,
198197
InternalServerError

modules/server/src/main/scala/es/weso/rdfshape/server/api/routes/schema/logic/operations/SchemaValidate.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ private[api] object SchemaValidate extends LazyLogging {
5959
for {
6060
innerSchema <- schema.getSchema
6161
result = innerSchema.flatMap(s => {
62-
trigger.getValidationTrigger.map(vt => {
63-
s.validate(rdf, vt, builder)
62+
trigger.getValidationTrigger.map(trigger => {
63+
s.validate(rdf, trigger, builder)
6464
})
6565
})
6666
validation <- result match {

modules/server/src/main/scala/es/weso/rdfshape/server/api/routes/shapemap/logic/ShapeMap.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ sealed case class ShapeMap private (
5858
case None | Some("") =>
5959
Left("Cannot extract the ShapeMap from an empty instance")
6060
case Some(shapeMapStr) =>
61-
println(nodesPrefixMap.pm)
6261
ShapeMapW
6362
.fromString(
6463
shapeMapStr,

modules/server/src/main/scala/es/weso/rdfshape/server/api/routes/wikibase/logic/operations/WikibaseOperationDetails.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.http4s.implicits.http4sLiteralsSyntax
2323
* (empty list returns all available languages).
2424
* Each language must be represented by its language code.
2525
* @param limit Maximum amount of results queried in search operations
26+
* In SPARQL queries, the limit is embedded in the query text
2627
* @param continue Offset where to continue a search operation
2728
* @param format Format in which results are requested
2829
* @see [[https://www.mediawiki.org/wiki/Wikibase/API#API_documentation_and_Wikibase_modules]]

modules/server/src/main/scala/es/weso/rdfshape/server/api/routes/wikibase/logic/operations/schema/WikibaseSchemaValidate.scala

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package es.weso.rdfshape.server.api.routes.wikibase.logic.operations.schema
22

33
import cats.effect.IO
4+
import cats.implicits.catsSyntaxEitherId
45
import com.typesafe.scalalogging.LazyLogging
56
import es.weso.rdf.NONE
67
import es.weso.rdf.nodes.IRI
78
import es.weso.rdfshape.server.api.format.dataFormats.{Compact, Turtle}
89
import es.weso.rdfshape.server.api.routes.data.logic.DataSource
910
import es.weso.rdfshape.server.api.routes.data.logic.types.DataSingle
11+
import es.weso.rdfshape.server.api.routes.data.logic.types.merged.DataCompound
1012
import es.weso.rdfshape.server.api.routes.schema.logic.operations.SchemaValidate
1113
import es.weso.rdfshape.server.api.routes.schema.logic.trigger.TriggerShapeMap
1214
import es.weso.rdfshape.server.api.routes.schema.logic.types.Schema
@@ -53,25 +55,37 @@ private[wikibase] case class WikibaseSchemaValidate(
5355

5456
override lazy val targetUri: Uri = uri"" // unused
5557

58+
private val entitiesSeparator = '|'
59+
5660
override def performOperation: IO[WikibaseOperationResult] = {
57-
val entityUri = operationData.payload
61+
62+
val entityUris = operationData.payload.split(entitiesSeparator)
5863

5964
// Raise error if target is not Wikidata
6065
if(targetWikibase != Wikidata)
6166
IO.raiseError(WikibaseServiceException(wikidataOnlyMessage))
6267
else {
6368
val tryResult = for {
64-
// Get the Wikidata item info from the URI submitted as payload
65-
wdEntity <- Try {
66-
WikidataEntity(Uri.unsafeFromString(entityUri))
69+
// Get the Wikidata items info from the URI submitted as payload
70+
wdEntities <- Try {
71+
entityUris.map(it => WikidataEntity(Uri.unsafeFromString(it)))
6772
}
6873
// Create the data to be validated, using Wikidata to get the URL
6974
// to the Turtle contents
70-
inputData = DataSingle(
71-
dataPre = Some(wdEntity.contentUri.renderString),
72-
dataFormat = Turtle,
73-
inference = NONE,
74-
dataSource = DataSource.URL
75+
/* Data will be a compound of several simple data fetched from each
76+
* entity */
77+
78+
inputData = DataCompound(
79+
wdEntities
80+
.map(entity =>
81+
DataSingle(
82+
dataPre = Some(entity.contentUri.renderString),
83+
dataFormat = Turtle,
84+
inference = NONE,
85+
dataSource = DataSource.URL
86+
)
87+
)
88+
.toList
7589
)
7690

7791
/* Get the schema model needed for validation: already passed to the
@@ -80,9 +94,12 @@ private[wikibase] case class WikibaseSchemaValidate(
8094
// Perform validation
8195
eitherValidationResults = for {
8296
// Create your trigger mode: ShEx with basic Shapemap
83-
shapeMapModel <- ShapeMapW.empty.add(
84-
IRI(wdEntity.entityUri.renderString),
85-
Start
97+
// For each entity, add a start point
98+
shapeMapModel <- wdEntities.foldLeft(ShapeMapW.empty.asRight[String])(
99+
(sm, entity) => {
100+
val entityUri = IRI(entity.entityUri.renderString)
101+
sm.flatMap(_.add(entityUri, Start))
102+
}
86103
)
87104
shapeMapFinalModel <- shapeMapModel.serialize(Compact.name)
88105
trigger = TriggerShapeMap(
@@ -122,7 +139,7 @@ private[wikibase] case class WikibaseSchemaValidate(
122139
wikibase = targetWikibase,
123140
result = Json.fromFields(
124141
List(
125-
("entity", Json.fromString(entityUri)),
142+
("entity", entityUris.asJson),
126143
("result", validationResults.asJson)
127144
)
128145
)

modules/server/src/test/scala/es/weso/rdfshape/server/api/DataServiceTest.pending

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)