Skip to content

Commit

Permalink
0.5.0 add watchdog option, suitable to be used in a cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
carueda committed Sep 8, 2017
1 parent 4b43a7d commit 091dd49
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 204 deletions.
94 changes: 9 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,95 +23,19 @@ $ java -jar cf2rdf-x.y.z.jar generate-conf

Edit `cf2rdf.conf` as needed.

As command-line arguments for the regular execution, cf2rdf expects the desired steps to be performed.
The complete sequence, including registration looks like so:
As command-line arguments for the regular execution, cf2rdf expects either the
`watchdog` argument to check for current remote CF version and trigger conversion
and registration in case of new version (based on comparison with latest processed file):

```shell
$ java -jar cf2rdf-x.y.z.jar download convert register

Downloading https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/46/src/cf-standard-name-table.xml
-> ./cf2rdf_output/cf-standard-name-table.xml

Downloading http://vocab.nerc.ac.uk/collection/P07/current/
-> ./cf2rdf_output/nvs_P07.rdf


Replaced %20 for space in the following rdf:resource IRIs from ./cf2rdf_output/nvs_P07.rdf
<owl:sameAs rdf:resource="http://mmisw.org/ont/cf/parameter/mole_fraction_of_chlorine dioxide_in_air"/>
<owl:sameAs rdf:resource="http://mmisw.org/ont/cf/parameter/mole_fraction_of_chlorine monoxide_in_air"/>
<owl:sameAs rdf:resource="http://mmisw.org/ont/cf/parameter/mole_fraction_of_dichlorine peroxide_in_air"/>
<owl:sameAs rdf:resource="http://mmisw.org/ont/cf/parameter/mole_fraction_of_hypochlorous acid_in_air"/>
<owl:sameAs rdf:resource="http://mmisw.org/ont/cf/parameter/rate_of_ hydroxyl_radical_destruction_due_to_reaction_with_nmvoc"/>

[main] WARN org.apache.jena.riot - [line: 1, col: 121] {W119} A processing instruction is in RDF content. No processing was done.

Summary: (saved in ./cf2rdf_output/cf-standard-name-table.conv-stats.txt)
cf2rdf conversion
input: https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/46/src/cf-standard-name-table.xml
output: ./cf2rdf_output/cf-standard-name-table.rdf

vocabulary properties from input file:
version_number: 46; last_modified: 2017-07-25T09:41:29Z

conversion stats:
numConcepts = 2890
numEntries = 2889
numWithNoCanonicalUnits = 9
numWithNoDefinitions = 26

Mapping ontology:
mappingTermsAdded = 2889
mappingOutputFilename = ./cf2rdf_output/cfonmap.n3

$ java -jar cf2rdf-x.y.z.jar watchdog
```

Registering http://mmisw.org/ont/cf/parameter - Climate and Forecast (CF) Standard Names (v.46)
- uploading...
POST http://localhost:8081/api/v0/ont/upload
- registering...
PUT http://localhost:8081/api/v0/ont {
"orgName":"mmi",
"name":"Climate and Forecast (CF) Standard Names (v.46)",
"uploadedFilename":"1504822022386._guess",
"uploadedFormat":"rdf",
"iri":"http://mmisw.org/ont/cf/parameter",
"status":"stable",
"visibility":"public",
"log":"reflect version number 46",
"userName":"carueda"
}
Result:
{
"uri":"http://mmisw.org/ont/cf/parameter",
"version":"20170907T150702",
"visibility":"public",
"status":"stable",
"updated":"2017-09-07T15:07:02Z"
}
or the desired specific steps to be performed, for example:

```shell
$ java -jar cf2rdf-x.y.z.jar download convert register

Registering http://mmisw.org/ont/mmi/cfonmap - ORR-NVS CF standard name mapping (v.46)
- uploading...
POST http://localhost:8081/api/v0/ont/upload
- registering...
PUT http://localhost:8081/api/v0/ont {
"orgName":"mmi",
"name":"ORR-NVS CF standard name mapping (v.46)",
"uploadedFilename":"1504822022908._guess",
"uploadedFormat":"n3",
"iri":"http://mmisw.org/ont/mmi/cfonmap",
"status":"stable",
"visibility":"public",
"log":"reflect version number 46",
"userName":"carueda"
}
Result:
{
"uri":"http://mmisw.org/ont/mmi/cfonmap",
"version":"20170907T150703",
"visibility":"public",
"status":"stable",
"updated":"2017-09-07T15:07:03Z"
}
```

The latest conversion report is [here](cf2rdf_output/cf-standard-name-table.conv-stats.txt).
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lazy val cf2rdfVersion = setVersion("0.4.0")
lazy val cf2rdfVersion = setVersion("0.5.0")
val scalaV = "2.12.2"
val cfgV = "0.0.7"
val scalajHttpV = "2.3.0"
Expand Down
2 changes: 1 addition & 1 deletion cf2rdf_output/cf-standard-name-table.conv-stats.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cf2rdf conversion
input: https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/46/src/cf-standard-name-table.xml
input: https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/current/src/cf-standard-name-table.xml
output: ./cf2rdf_output/cf-standard-name-table.rdf

vocabulary properties from input file:
Expand Down
2 changes: 1 addition & 1 deletion cf2rdf_output/cf-standard-name-table.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<omvm:hasResourceType>http://mmisw.org/ont/mmi/resourcetype/parameter</omvm:hasResourceType>
<omv:description>Ontology representation of the Climate and Forecast (CF) standard names parameter vocabulary, which is intended for use with climate and forecast data in the atmosphere, surface and ocean domains. Every CF parameter is captured as a SKOS concept.</omv:description>
<omv:name>Climate and Forecast (CF) Standard Names (v.46)</omv:name>
<omvm:origVocUri>https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/current/src/cf-standard-name-table.xml</omvm:origVocUri>
<omv:reference>http://marinemetadata.org/orrcf</omv:reference>
<omv:acronym>CF-standard-name</omv:acronym>
<omv:keywords>NetCDF, CF, Climate and Forecast, self-describing, standard names, Canonical Units</omv:keywords>
<omvm:origVocUri>https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/46/src/cf-standard-name-table.xml</omvm:origVocUri>
<omv:documentation>http://cfconventions.org/standard-names.html</omv:documentation>
</owl:Ontology>
<rdfs:Class rdf:about="http://www.w3.org/2004/02/skos/core#Concept"/>
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2017-09-07 0.5.0

- add watchdog option, suitable to be used in a cronjob.
This checks for current remote CF version and triggers conversion/registration
in case of new version, based on comparison with latest processed file.

2017-09-07 0.4.0

- cf2rdf can now register the generated ontologies
Expand Down
14 changes: 5 additions & 9 deletions src/main/resources/params_template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
# cf2rdf execution parameters.
#
# You can adjust any of the entries in this file but only the following
# will typically need to be adjusted as needed:
# cfVersion
# will typically need to be adjusted:
# orr.userName
# orr.password
#

# The CF version number to process
cfVersion = 46

# The template for the URL to retrieve the XML file
xmlUrl = "https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/"${cfVersion}"/src/cf-standard-name-table.xml"
# URL of current XML file
xmlUrl = "https://raw.githubusercontent.com/cf-convention/cf-convention.github.io/master/Data/cf-standard-names/current/src/cf-standard-name-table.xml"

# Output directory for generated files
outDir = "cf2rdf_output"
outDir = "./cf2rdf_output"

# Name of local file for the download of xmlUrl
destXml = ${outDir}"/cf-standard-name-table.xml"
Expand Down Expand Up @@ -53,7 +49,7 @@ orr {
userName = ?
password = ?

# Organization that owns the entries at the ORR instance
# Organization that owns the rdf.iri and mapping.iri entries at the ORR instance
orgName = "mmi"

# Visibility for the registration
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cf2rdf.version = 0.4.0
cf2rdf.version = 0.5.0
16 changes: 6 additions & 10 deletions src/main/scala/org/mmisw/cf2rdf/Converter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@ import scala.xml.Node
*
* @param xmlIn Input XML
*/
class Converter(xmlIn: Node) {

/** some general properties from the input */
val props: Map[String,String] = {
val keys = List("version_number", "last_modified") //, "institution", "contact")
(keys map (k k -> (xmlIn \ k).text.trim)).toMap
}
class Converter(xmlIn: Node, xmlProps: Map[String,String]) {

/**
* Does the conversion
*
* @return Resulting Jena model
*/
def convert: Model = {
val lastModifiedOpt = props.get("last_modified")
val lastModifiedOpt = xmlProps.get("last_modified")

val namespace = cfg.rdf.iri + "/"

val M = new ModelConstructor(namespace, lastModifiedOpt)
val cfVersionOpt = xmlProps.get("version_number")

val M = new ModelConstructor(namespace, cfVersionOpt, lastModifiedOpt)

val mapper = new OrrNvsMapper(lastModifiedOpt)
val mapper = new OrrNvsMapper(cfVersionOpt, lastModifiedOpt)

for (entry xmlIn \\ "entry") {
stats.numEntries += 1
Expand Down
15 changes: 12 additions & 3 deletions src/main/scala/org/mmisw/cf2rdf/ModelConstructor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.apache.jena.vocabulary._
import org.mmisw.orr.ont.vocabulary.{Omv, OmvMmi}

class ModelConstructor(namespace: String,
cfVersionOpt: Option[String],
lastModifiedOpt: Option[String]
) {

Expand All @@ -32,8 +33,17 @@ class ModelConstructor(namespace: String,

private val ontology = model.createOntology(cfg.rdf.iri)

ontology.addProperty(Omv.name,
s"Climate and Forecast (CF) Standard Names (v.${cfg.cfVersion})")
cfVersionOpt match {
case Some(cfVersion)
ontology.addProperty(Omv.name,
s"Climate and Forecast (CF) Standard Names (v.$cfVersion)")

ontology.addProperty(OmvMmi.origVocVersionId, cfVersion)

case None
ontology.addProperty(Omv.name,
s"Climate and Forecast (CF) Standard Names")
}

ontology.addProperty(Omv.description,
"Ontology representation of the Climate and Forecast (CF) standard names parameter vocabulary," +
Expand Down Expand Up @@ -61,7 +71,6 @@ class ModelConstructor(namespace: String,
ontology.addProperty(Omv.creationDate, lm)
}

ontology.addProperty(OmvMmi.origVocVersionId, cfg.cfVersion)
ontology.addProperty(OmvMmi.origVocUri, cfg.xmlUrl)

ontology.addProperty(OmvMmi.hasResourceType,
Expand Down
13 changes: 10 additions & 3 deletions src/main/scala/org/mmisw/cf2rdf/OrrNvsMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.mmisw.orr.ont.vocabulary.{Omv, OmvMmi}
import scala.collection.JavaConverters._


class OrrNvsMapper(lastModifiedOpt: Option[String]) {
class OrrNvsMapper(cfVersionOpt: Option[String], lastModifiedOpt: Option[String]) {

private val mapNamespace = cfg.mapping.iri + "/"
private val orrCfNamespace = cfg.rdf.iri + "/"
Expand All @@ -30,8 +30,15 @@ class OrrNvsMapper(lastModifiedOpt: Option[String]) {

private val ontology = model.createOntology(cfg.mapping.iri)

ontology.addProperty(Omv.name,
s"ORR-NVS CF standard name mapping (v.${cfg.cfVersion})")
cfVersionOpt match {
case Some(cfVersion)
ontology.addProperty(Omv.name,
s"ORR-NVS CF standard name mapping (v.$cfVersion)")

case None
ontology.addProperty(Omv.name,
s"ORR-NVS CF standard name mapping")
}

ontology.addProperty(Omv.description,
"Uses skos:exactMatch to link the IRIs of the CF standard names between the" +
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/org/mmisw/cf2rdf/Registerer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.json4s.native.Serialization.writePretty
import scalaj.http.{Http, HttpResponse, MultiPart}


class Registerer(orr: OrrCfg) {
class Registerer(orr: OrrCfg, cfVersion: String) {
private implicit val jsonFormats: Formats = DefaultFormats ++ JodaTimeSerializers.all

def registerOntologies(): Unit = {
Expand All @@ -22,16 +22,16 @@ class Registerer(orr: OrrCfg) {

def registerRdf(): Unit = {
register(cfg.rdf.iri,
s"Climate and Forecast (CF) Standard Names (v.${cfg.cfVersion})",
log = s"reflect version number ${cfg.cfVersion}",
s"Climate and Forecast (CF) Standard Names (v.$cfVersion)",
log = s"reflect version number $cfVersion",
cfg.rdf.filename
)
}

def registerMapping(): Unit = {
register(cfg.mapping.iri,
s"ORR-NVS CF standard name mapping (v.${cfg.cfVersion})",
log = s"reflect version number ${cfg.cfVersion}",
s"ORR-NVS CF standard name mapping (v.$cfVersion)",
log = s"reflect version number $cfVersion",
cfg.mapping.filename
)
}
Expand Down
Loading

0 comments on commit 091dd49

Please sign in to comment.