Skip to content

Commit

Permalink
Merge #229 from branch 'WIP-metafacture-core-415-addSkosLookup' of ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed Feb 13, 2023
2 parents e944e27 + 3c09175 commit b5b8cc9
Show file tree
Hide file tree
Showing 34 changed files with 8,007 additions and 7 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ put_map("<mapName>",
)
```

##### `put_rdfmap`

Defines an external RDF map for lookup from a file or an HTTP(S) resource.
As the RDF map is reducing RDF triples to a key/value map it is mandatory to set the target.
The targeted RDF property can optionally be bound by an RDF language tag.

```perl
put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>")
put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>", select_language: "<rdfLanguageTag>")
```

##### `put_var`

Defines a single global variable that can be referenced with `$[<variableName>]`.
Expand Down Expand Up @@ -553,7 +564,7 @@ join_field("<sourceField>", "<separator>")

##### `lookup`

Looks up matching values in a map and replaces the field value with this match. [External files](#put_filemap) as well as [internal maps](#put_map) can be used.
Looks up matching values in a map and replaces the field value with this match. [External files](#put_filemap), [internal maps](#put_map) as well as [RDF resources](#put_rdfmap) can be used.

Parameters:

Expand Down Expand Up @@ -599,6 +610,10 @@ lookup("path.to.field", "path/to/file", sep_char: ";")
put_filemap("path/to/file", "file-map", sep_char: ";")
lookup("path.to.field", "file-map")

# RDF map (explicit)
put_rdfmap("path/to/file", "rdf-map", target: "<rdfProperty>")
lookup("path.to.field", "rdf-map")

# with default value
lookup("path.to.field", "map-name", __default: "NA")

Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ subprojects {
'ace': '1.3.3',
'antlr': '3.2',
'equalsverifier': '3.8.2',
'guava': '29.0-jre',
'jackson': '2.13.3',
'jena': '3.17.0',
'jetty': '9.4.14.v20181114',
'jquery': '3.3.1-1',
'junit_jupiter': '5.8.2',
Expand All @@ -45,8 +47,8 @@ subprojects {
'mockito': '2.27.0',
'requirejs': '2.3.6',
'slf4j': '1.7.21',
'xtext': '2.26.0',
'guava': '29.0-jre'
'wiremock': '2.33.2',
'xtext': '2.26.0'
]
}

Expand Down
11 changes: 9 additions & 2 deletions metafix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
implementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
implementation "com.google.guava:guava:${versions.guava}"
implementation "org.apache.jena:jena-arq:${versions.jena}"
implementation "org.apache.jena:jena-core:${versions.jena}"
implementation "org.eclipse.emf:org.eclipse.emf.ecore:${versions.xtext}" // Workaround for hbz/lobid-resources#1462
implementation "org.eclipse.xtext:org.eclipse.xtext.xbase:${versions.xtext}"
implementation "org.eclipse.xtext:org.eclipse.xtext:${versions.xtext}"
implementation "org.slf4j:slf4j-api:${versions.slf4j}"

testImplementation "org.junit.jupiter:junit-jupiter-api:${versions.junit_jupiter}"
testImplementation "org.junit.platform:junit-platform-launcher:${versions.junit_platform}"
testImplementation "com.github.tomakehurst:wiremock-jre8:${versions.wiremock}"
testImplementation "org.eclipse.xtext:org.eclipse.xtext.testing:${versions.xtext}"
testImplementation "org.eclipse.xtext:org.eclipse.xtext.xbase.testing:${versions.xtext}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${versions.junit_jupiter}"
testImplementation "org.junit.platform:junit-platform-launcher:${versions.junit_platform}"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${versions.junit_jupiter}"

Expand All @@ -43,6 +46,10 @@ dependencies {
configurations {
mwe2 {
extendsFrom implementation

dependencies {
implementation "org.slf4j:slf4j-simple:${versions.slf4j}"
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions metafix/src/main/java/org/metafacture/metafix/FixMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.metafacture.metafix;

import org.metafacture.metafix.api.FixFunction;
import org.metafacture.metafix.maps.RdfMap;
import org.metafacture.metamorph.api.Maps;
import org.metafacture.metamorph.functions.ISBN;
import org.metafacture.metamorph.functions.Timestamp;
Expand Down Expand Up @@ -92,6 +93,22 @@ public void apply(final Metafix metafix, final Record record, final List<String>
metafix.putMap(params.get(0), options);
}
},
put_rdfmap {
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
final String fileName = params.get(0);
final RdfMap rdfMap = new RdfMap();

rdfMap.setResource(fileName, metafix::resolvePath);

withOption(options, RdfMap.TARGET, rdfMap::setTarget);
withOption(options, RdfMap.TARGET_LANGUAGE, rdfMap::setTargetLanguage);
withOption(options, RdfMap.SELECT, rdfMap::setSelect);
withOption(options, Maps.DEFAULT_MAP_KEY, rdfMap::setDefault);

metafix.putMap(params.size() > 1 ? params.get(1) : fileName, rdfMap);
}
},
put_var {
@Override
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
Expand Down
Loading

0 comments on commit b5b8cc9

Please sign in to comment.