New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix!: transform valueHasUri values from node to string type (DEV-1047) #2094
Merged
mpro7
merged 5 commits into
main
from
DEV-1047-dsp-api-value-has-uri-property-has-node-as-a-value
Jul 13, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f72433d
add test data
mpro7 729cbbb
add plugin and test
mpro7 d207db3
add plugin to Upgrade plan + increase knora-base version
mpro7 6570212
Merge branch 'main' into DEV-1047-dsp-api-value-has-uri-property-has-…
mpro7 c093ef8
cleanup
mpro7 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ sipi/test | |
*.bak | ||
*.rdb | ||
.sbtrc | ||
**/*.trig | ||
/*.trig | ||
|
||
dependencies.txt | ||
/client-test-data.zip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
@prefix knora-base: <http://www.knora.org/ontology/knora-base#> . | ||
|
||
# bad valueHasUri value and missing datatype | ||
<http://rdfh.ch/0103/5LE8P57nROClWUxEPJhiug/values/fEbt5NzaSe6GnCqKoF4Nhg/standoff/2> | ||
rdf:type knora-base:StandoffUriTag ; | ||
knora-base:standoffTagHasEnd 50 ; | ||
knora-base:standoffTagHasStart 20 ; | ||
knora-base:standoffTagHasStartIndex 2 ; | ||
knora-base:standoffTagHasStartParent <http://rdfh.ch/0103/5LE8P57nROClWUxEPJhiug/values/fEbt5NzaSe6GnCqKoF4Nhg/standoff/1> ; | ||
knora-base:standoffTagHasUUID "dd2e785b-041e-4bcb-a77d-570efe8a068c" ; | ||
knora-base:valueHasUri <http://www.maison-george-sand.fr/> . | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...c/main/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR2094.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.knora.webapi.store.triplestore.upgrade.plugins | ||
|
||
import com.typesafe.scalalogging.Logger | ||
import org.knora.webapi.messages.OntologyConstants | ||
import org.knora.webapi.messages.util.rdf._ | ||
import org.knora.webapi.store.triplestore.upgrade.UpgradePlugin | ||
|
||
/** | ||
* Transforms a repository for Knora PR 2094. | ||
* Transforms incorrect value of valueHasUri from node to string type adding also | ||
* missing datatype ^^<http://www.w3.org/2001/XMLSchema#anyURI> | ||
*/ | ||
class UpgradePluginPR2094(log: Logger) extends UpgradePlugin { | ||
private val nodeFactory: RdfNodeFactory = RdfFeatureFactory.getRdfNodeFactory() | ||
|
||
override def transform(model: RdfModel): Unit = { | ||
val statementsToRemove: collection.mutable.Set[Statement] = collection.mutable.Set.empty | ||
val statementsToAdd: collection.mutable.Set[Statement] = collection.mutable.Set.empty | ||
val newObjectValue: String => DatatypeLiteral = (value: String) => | ||
nodeFactory.makeDatatypeLiteral(value, OntologyConstants.Xsd.Uri) | ||
|
||
for (statement: Statement <- model) { | ||
if (statement.pred.iri == OntologyConstants.KnoraBase.ValueHasUri) { | ||
statement.obj match { | ||
case node: IriNode => | ||
statementsToRemove += statement | ||
|
||
statementsToAdd += nodeFactory.makeStatement( | ||
subj = statement.subj, | ||
pred = statement.pred, | ||
obj = newObjectValue(node.iri), | ||
context = statement.context | ||
) | ||
|
||
log.info( | ||
s"Transformed v23 valueHasIri $node to ${newObjectValue(node.iri)}." | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
case _ => () | ||
} | ||
} | ||
} | ||
|
||
model.removeStatements(statementsToRemove.toSet) | ||
model.addStatements(statementsToAdd.toSet) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...st/scala/org/knora/webapi/store/triplestore/upgrade/plugins/UpgradePluginPR2094Spec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.knora.webapi.store.triplestore.upgrade.plugins | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import dsp.errors.AssertionException | ||
import org.knora.webapi.messages.OntologyConstants | ||
import org.knora.webapi.messages.util.rdf._ | ||
|
||
class UpgradePluginPR2094Spec extends UpgradePluginSpec with LazyLogging { | ||
private val nodeFactory: RdfNodeFactory = RdfFeatureFactory.getRdfNodeFactory() | ||
|
||
"Upgrade plugin PR2094" should { | ||
"fix the missing valueHasUri datatype" in { | ||
// Parse the input file. | ||
val model: RdfModel = trigFileToModel("../test_data/upgrade/pr2094.trig") | ||
|
||
// Use the plugin to transform the input. | ||
val plugin = new UpgradePluginPR2094(log) | ||
plugin.transform(model) | ||
|
||
// Check that the datatype was fixed. | ||
val subj = | ||
nodeFactory.makeIriNode("http://rdfh.ch/0103/5LE8P57nROClWUxEPJhiug/values/fEbt5NzaSe6GnCqKoF4Nhg/standoff/2") | ||
val pred = nodeFactory.makeIriNode(OntologyConstants.KnoraBase.ValueHasUri) | ||
|
||
model | ||
.find( | ||
subj = Some(subj), | ||
pred = Some(pred), | ||
obj = None | ||
) | ||
.toSet | ||
.headOption match { | ||
case Some(statement: Statement) => | ||
println(111, statement) | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
statement.obj match { | ||
case datatypeLiteral: DatatypeLiteral => | ||
println(222, statement.obj) | ||
println(333, datatypeLiteral.datatype) | ||
mpro7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(datatypeLiteral.datatype == OntologyConstants.Xsd.Uri) | ||
|
||
case other => | ||
throw AssertionException(s"Unexpected object for $pred: $other") | ||
} | ||
|
||
case None => throw AssertionException(s"No statement found with subject $subj and predicate $pred") | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if that makes much sense... but you could consider testing also the case where a URI should not be converted to a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This plugin is very specific and picks only the node values in type
IriNode
. IMO as with the PR2079 plugin this is enough.