Skip to content

Commit

Permalink
Fix bug in sha1() function + update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
frmichel committed Jul 30, 2021
1 parent 65ef1fe commit 5501c3c
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 22 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

## [1.3-SNAPSHOT] 2020-04-27
- Add mixed syntax path sha1
## [CURRENT] 2021-07-30
- fix bug in sha1() mixed path
- document the sha1() mixed path

## [1.3.1] 2021-01-06
- fix bug in management of empty values
- document the variable language tag

## [1.3] 2020-04-27
- Add mixed syntax path sha1() to compute sha hash in template

## [1.2] 2020-04-22
- Add config property output.file.max_triples (and parameter --outputMaxTriples) to generate files with a maximum number of triples
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ See a detailed [description of the project code and architecture](doc/README_cod
Pre-requisite: have **Java SDK 10** installed

You can download the last release or snapshot published in [this repository](https://www.dropbox.com/sh/djnztipsclvcskw/AABT1JagzD4K4aCALDNVj-yra?dl=0).
The latest on-going version is the 1.3.2 snapshot.

Alternatively, you can build the application using [Maven](http://maven.apache.org/): in a shell, CD to the root directory morph-xr2rml, then run the command: `mvn clean package`. A jar with all dependencies is generated in `morph-xr2rml-dist/target`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ <h2>Document history</h2>
<td>2019-06-19</td>
<td>Add property xrr:languageReference to handle varialbe language tag</td>
</tr>
<tr>
<td>5.2</td>
<td>2021-07-30</td>
<td>Add extended function sha1()</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -172,6 +177,10 @@ <h2>Table of Contents</h2>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.3.2 <a href="#_Toc466307477">Generating RDF ollection/container with a referencing object map</a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.3.3 <a href="#_Toc466307478">Generating RDF ollection/container with a referencing object map in the relational case</a><br/>

&nbsp;&nbsp;&nbsp;&nbsp;3.4 <a href="#_Toc_Extension_functions">Extension functions</a><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.4.1 <a href="#_Toc_sha">Computing a hash from data source values</a><br/>


<h3>Appendix</h3>

A <b><a href="#_Toc466307479">References</a></b><br/>
Expand Down Expand Up @@ -374,7 +383,6 @@ <h2 id="_Toc466307452">2.2 Mapping JSON data</h2>
&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "2046".
&lt;http://example.org/director/Wong%20Kar-wai&gt; ex:directed "In the Mood for Love".</pre></td>
</tr>

</tbody>
</table>

Expand Down Expand Up @@ -2350,6 +2358,44 @@ <h3 id="_Toc466307478">3.3.3 Generating RDF collection/container with a referenc



<h2 id="_Toc_Extension_functions">3.4 Extension functions</h2>

<h3 id="_Toc_sha">3.4.1 Computing a hash from data source values</h3>

<p>Function <b>sha1()</b> can be used in the context of a template-valued term map (property rr:template)
to calculate the SHA1 digest of components of the data source, where each reference to a data element is enclosed in curly braces ("{" and "}"). Templating still works inside the parentheses of the sha1() function.
</p>
<p>A typical use case is to build unique resource IRIs using multiple data elements while keeping those elements obfuscated in the IRI. Example:
</p>

<table><tbody>
<tr>
<td>Input data</td>
<td><pre>
{ "name":"John", "birthdate":"1996-05-23" }
</pre></td>
</tr>
<tr>
<td>Mapping graph</td>
<td><pre>
&lt;#HashSubTriplesMap&gt;
rr:subjectMap [ rr:template "http://example.org/person/<span class="red">sha1</span>({$.name}_{$.birthdate})" ];
rr:predicateObjectMap [
rr:predicate schema:name;
rr:objectMap [ xrr:reference "$.name" ];
].</pre></td>
</tr>
<tr>
<td>RDF triples produced</td>
<td><pre>
&lt;http://example.org/person/1f83650790e2cee21218078f96d9ac88dbdc5621&gt; schema:name "John".
</tr>
</tbody></table>






<h1 id="_Toc466307479">A References</h1>

Expand Down
4 changes: 2 additions & 2 deletions morph-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<parent>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml-lang</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion morph-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ object Constants {
val xR2RML_PATH_JSONPATH_REGEX = (xR2RML_PATH_CONSTR_JSONPATH + """\(""" + xR2RML_PATH_EXPR_CHARS + """\)""").r
val xR2RML_PATH_CSV_REGEX = (xR2RML_PATH_CONSTR_CSV + """\(""" + xR2RML_PATH_EXPR_CHARS + """\)""").r
val xR2RML_PATH_TSV_REGEX = (xR2RML_PATH_CONSTR_TSV + """\(""" + xR2RML_PATH_EXPR_CHARS + """\)""").r
val xR2RML_PATH_SHA1_REGEX = (xR2RML_PATH_CONSTR_SHA1 + """\((.+)\)$""").r
val xR2RML_PATH_SHA1_REGEX = (xR2RML_PATH_CONSTR_SHA1 + """\((.+)\)""").r

/**
* Return the enclosed character depending on the type of database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TemplateUtilityTest {

@Test def TestGetTemplateColumns1() {
println("------------------ TestGetTemplateColumns1 ------------------")
val tpl = "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/{ar}/{nr}";
val tpl = "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/{ar}/{nr}/";
val colRefs = TemplateUtility.getTemplateColumns(tpl);
println("Found columns " + colRefs + " in template " + tpl)
assertEquals("ar", colRefs(0))
Expand Down Expand Up @@ -74,9 +74,9 @@ class TemplateUtilityTest {
val xPath = """XPath(\/\/root\/node[1]\(\)\/@id)"""
val jsonPath = """JSONPath($['store'].book[\(@.length-1\)].title)"""
val mixedPath = "Column(NAME)/CSV(3)/" + xPath + "/" + jsonPath + "/TSV(name)"
var tpl = "http://example.org/student/{ID1}/{" + mixedPath + "}/{ID2}"
var tpl = "http://example.org/student/{ID1}/{" + mixedPath + "}/{ID2}/"

groups = TemplateUtility.getTemplateMatching(tpl, "http://example.org/student/id1/mixedPath1/id2")
groups = TemplateUtility.getTemplateMatching(tpl, "http://example.org/student/id1/mixedPath1/id2/")
println("groups: " + groups)

}
Expand Down Expand Up @@ -178,9 +178,32 @@ class TemplateUtilityTest {
println("------------------ TestSha1 ------------------")

var tpl = "http://example.org/student/sha1({field1}_{field2})"
val replacements: List[List[Object]] = List(List("A"), List("B"))
val values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
var replacements: List[List[Object]] = List(List("A"), List("B"))
var values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
println(values)
assertEquals(values, List("http://example.org/student/" + org.apache.commons.codec.digest.DigestUtils.sha1Hex("A_B")))

tpl = "http://example.org/student_sha1({field1}_{field2})"
values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
println(values)
assertEquals(values, List("http://example.org/student_" + org.apache.commons.codec.digest.DigestUtils.sha1Hex("A_B")))

tpl = "http://example.org/student_sha1({field1}_{field2})/"
replacements = List(List("A"), List("B"))
values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
println(values)
assertEquals(values, List("http://example.org/student_" + org.apache.commons.codec.digest.DigestUtils.sha1Hex("A_B") + "/"))

tpl = "http://example.org/student/{field0}/sha1({field1}_{field2})"
replacements = List(List("a"), List("A"), List("B"))
values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
println(values)
assertEquals(values, List("http://example.org/student/a/" + org.apache.commons.codec.digest.DigestUtils.sha1Hex("A_B")))

tpl = "http://example.org/person/sha1({field1}_{field2})"
replacements = List(List("John"), List("1996-05-23"))
values = TemplateUtility.replaceTemplateGroups(tpl, replacements)
println(values)

}
}
6 changes: 3 additions & 3 deletions morph-xr2rml-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>morph-xr2rml</artifactId>
<groupId>fr.unice.i3s</groupId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<properties>
Expand All @@ -22,13 +22,13 @@
<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml-rdb</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml-mongo</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions morph-xr2rml-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<parent>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-core</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions morph-xr2rml-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<parent>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-base</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions morph-xr2rml-rdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<parent>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>fr.unice.i3s</groupId>
<artifactId>morph-base</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>fr.unice.i3s</groupId>
<artifactId>morph-xr2rml</artifactId>
<version>1.3.1</version>
<version>1.3.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>morph-xr2rml parent project</name>

Expand Down

0 comments on commit 5501c3c

Please sign in to comment.