rdfopenrefine

OpenRefine + RDF: handling repeated occurrences


Converting XML to RDF using OpenRefine with the RDF-extension. Here's a sample record in OR.

enter image description here

I've been looking for a way to handle repeated occurrences, in this case two in animals - narrower. This is what I got to:

@prefix ex: <http://example.com/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .

ex:mammals a skos:Concept;
skos:narrower "ex:cats, ex:cows" .

enter image description here

In the RDF node pane, I'm mapping the narrowers to text, and use below GREL to get all the occurrence on one line with the ex: prefix.

forEach(row.record.cells['animals - narrower'].value,v,'ex:'+v).join(', ')

It's almost what I want. Ideally, there should be no quotes:

ex:mammals a skos:Concept;
skos:narrower ex:cats, ex:cows .

In other words, I want to map to a URI type, but for better legibility, I want to keep the ex: prefix, rather than the full URI. Also I want to keep them as a repeated objects to the one `skos:narrower' predicate, not a line with predicate + object for each occurrence.

I know how to get rid of the quotes using an editor. I'm just hoping there's a better way than the one I've found.

Also, I know how to spread repeated occurrences over individual new columns and map each new column, but in real life I would have to map over 100 columns to only a handful of target skos fields. That's not what automation is for.


Solution

  • Meanwhile, RDF-Transform emerged. It has the answer to this question. There is a slight difference in the way it works, exemplified by the highlighted mammals in this screenshot.

    RDF-Transform showing repeated prefLabels.

    One caveat: I am seeing this issue running the extension in Windows 10 with with the JRE. The workaround that I found is to run OpenRefine with RDF-Transform plugin from WSL.