Skip to content

Commit

Permalink
Add support for dcat:version property
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostrzyciel committed Sep 19, 2024
1 parent 95fa89e commit 94721dc
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/main/scala/commands/CategoryDocGenCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ object CategoryDocGenCommand extends Command:
customValueFormatters = {
case (_, res: Resource) if {
val props = res.listProperties().asScala.map(_.getPredicate).toSeq
res.hasProperty(RDF.`type`, RdfUtil.SystemUnderTest) &&
props.contains(RDFS.label) &&
(props.contains(RdfUtil.hasVersion) && props.size == 3 || props.size == 2)
res.hasProperty(RDF.`type`, RdfUtil.SystemUnderTest) && props.contains(RDFS.label)
} =>
val name = res.getProperty(RDFS.label).getObject.asLiteral().getString
val version = res.listProperties(RdfUtil.hasVersion).asScala.toSeq.headOption
// rb:hasVersion was used until 2.2.0, from 2.2.0 onwards dcat:version is used
// Read both to support older versions!
val version = (res.listProperties(RdfUtil.hasVersion).asScala ++
res.listProperties(RdfUtil.dcatVersion).asScala)
.toSeq.headOption
.map(_.getObject.asLiteral().getString)
DocValueSut(name, version)
},
Expand All @@ -74,7 +76,7 @@ object CategoryDocGenCommand extends Command:

val catM = RdfIoUtil.loadModelWithStableBNodeIds(packageOutDir.resolve("category/metadata.ttl"))
val catRes = catM.listSubjectsWithProperty(RDF.`type`, RdfUtil.Category).next.asResource
val version = RdfUtil.getString(catRes, RdfUtil.hasVersion).get
val version = RdfUtil.getString(catRes, RdfUtil.dcatVersion).get

outDir.resolve("category").toFile.mkdirs()

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/commands/DatasetDocGenCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object DatasetDocGenCommand extends Command:
val mi = MetadataReader.fromModel(metadata)
val landingPage = mi.datasetRes.listProperties(RdfUtil.dcatLandingPage)
.asScala.toSeq.head.getResource.getURI
val version = mi.datasetRes.listProperties(RdfUtil.hasVersion)
val version = mi.datasetRes.listProperties(RdfUtil.dcatVersion)
.asScala.toSeq.head.getLiteral.getString

val readableVersion = version match
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/commands/GenerateRedirectCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object GenerateRedirectCommand extends Command:
val m = RDFDataMgr.loadModel(
s"https://github.com/RiverBench/dataset-$name/releases/latest/download/metadata.ttl"
)
RdfUtil.getString(null, RdfUtil.hasVersion, Some(m)).get
RdfUtil.getString(null, RdfUtil.dcatVersion, Some(m)).get
else
val m = RDFDataMgr.loadModel(
"https://github.com/RiverBench/schema/releases/latest/download/metadata.ttl"
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/commands/MainDocGenCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ object MainDocGenCommand extends Command:
(1, RDF.`type`),
// List of all profiles, categories, and tasks... very verbose
(1, RdfUtil.dcatResource),
) ++ (if version == "dev" then Seq(
// TODO: remove in 2.3.0
(1, RdfUtil.hasVersion),
) ++ (if version == "dev" then Seq(
(1, RdfUtil.dcatVersion),
) else Seq.empty)
)

Expand All @@ -68,6 +70,8 @@ object MainDocGenCommand extends Command:
if version == "dev" then
println("Generating README...")
val readmeDocOpt = mainDocOpt.copy(hidePropsInLevel = mainDocOpt.hidePropsInLevel ++ Seq(
(1, RdfUtil.dcatVersion),
// TODO: remove in 2.3.0
(1, RdfUtil.hasVersion),
))
val readmeDocBuilder = new DocBuilder(ontologies, readmeDocOpt)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/commands/MergeMetadataCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ object MergeMetadataCommand extends Command:
(repoMetadata, newDatasetRes)

private def addVersionMetadata(m: Model, datasetRes: Resource, version: String): Unit =
datasetRes.addProperty(RdfUtil.dcatVersion, version)
// TODO: Remove in 2.3.0
datasetRes.addProperty(RdfUtil.hasVersion, version)
val baseUrl = datasetRes.getURI
datasetRes.addProperty(RdfUtil.dcatLandingPage, m.createResource(baseUrl))
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/commands/PackageCategoryCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ object PackageCategoryCommand extends Command:
val newRes = categoryM.createResource(PurlMaker.category(id, version))
RdfUtil.renameResource(categoryRootRes, newRes, categoryM)
// Version metadata
categoryM.add(newRes, RdfUtil.dcatVersion, version)
// TODO: Remove in 2.3.0
categoryM.add(newRes, RdfUtil.hasVersion, version)
// Link to main
categoryM.add(newRes, RdfUtil.dcatInCatalog, mainRes)
Expand Down Expand Up @@ -110,6 +112,8 @@ object PackageCategoryCommand extends Command:
val newRes = taskM.createResource(PurlMaker.task(name, version))
RdfUtil.renameResource(taskRootRes, newRes, taskM)
// Version metadata
taskM.add(newRes, RdfUtil.dcatVersion, version)
// TODO: Remove in 2.3.0
taskM.add(newRes, RdfUtil.hasVersion, version)
// Link to category
taskM.add(newRes, RdfUtil.inCategory, categoryRes)
Expand Down Expand Up @@ -182,6 +186,8 @@ object PackageCategoryCommand extends Command:
profileModel.removeAll(res, RdfUtil.isSupersetOfProfile, null)
profileModel.add(subSupModel.listStatements(res, null, null))
// Version metadata
profileModel.add(res, RdfUtil.dcatVersion, version)
// TODO: Remove in 2.3.0
profileModel.add(res, RdfUtil.hasVersion, version)
profileModel.add(res, RdfUtil.dcatInCatalog, mainRes)
profileModel.add(res, RdfUtil.inCategory, categoryRes)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/commands/PackageMainCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object PackageMainCommand extends Command:
println("Processing main metadata...")
RdfUtil.renameResource(oldMainRes, newMainRes, mainModel)
newMainRes.addProperty(RdfUtil.foafHomepage, newMainRes)
newMainRes.addProperty(RdfUtil.dcatVersion, version)
// TODO: remove in 2.3.0
newMainRes.addProperty(RdfUtil.hasVersion, version)

// Add links to datasets, categories, profiles, and tasks
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/util/RdfUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ object RdfUtil:
val dcatLandingPage = m.createProperty(pDcat, "landingPage")
val dcatInCatalog = m.createProperty(pDcat, "inCatalog")
val dcatInSeries = m.createProperty(pDcat, "inSeries")
// DCAT 3 property
val dcatSeriesMember = m.createProperty(pDcat, "seriesMember")
val dcatDataset = m.createProperty(pDcat, "dataset")
val dcatResource = m.createProperty(pDcat, "resource")
// DCAT 3 property
val dcatIsDistributionOf = m.createProperty(pDcat, "isDistributionOf")
val dcatVersion = m.createProperty(pDcat, "version")

val dctermsCreated = m.createProperty(pDcterms, "created")
val dctermsCreator = m.createProperty(pDcterms, "creator")
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/util/doc/DocSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class DocSection(val level: Int, defaultPropGroup: Option[String] = None, isRoot

def addEntry(prop: DocProp, value: DocValue): Unit =
val group = prop.group.orElse(defaultPropGroup)
if prop.prop.getURI == RdfUtil.hasDocWeight.getURI then
if prop.hidden then ()
else if prop.prop.getURI == RdfUtil.hasDocWeight.getURI then
value match
case DocValue.Literal(l) =>
l.getLexicalForm.toIntOption match
Expand Down

0 comments on commit 94721dc

Please sign in to comment.