OpenRefine can retrieve data from URLs. This can be used in various ways, including looking up additional information from a remote service. Typically this is a two step process:
Edit column->Add column by fetching URLs
. This will prompt you for a GREL expression to create a url. The url uses values in your data to request a different data for each line. So you generally have the root of a url plus the value in a particular column.Two specific OpenRefine functions used for this are: parseHtml()
and parseJson()
Because retrieving data from external URLs takes time, this exercise targets a single line in the data. In reality you would want to run this over many rows (and probably go and do something else while it ran) Firstly we will will filter to a single row from the data set which contains an ISSN by:
ISSN
column use the dropdown menu to choose Edit column->Add column by fetching URLs
In this case we are going to use the CrossRef API https://github.com/CrossRef/rest-api-doc
API providers may impose rate limits or have other requirements for using their data, so it’s important to check the site’s documentation. CrossRef asks users to “specify a User-Agent header that properly identifies your script or tool and that provides a means of contacting you via email using ‘mailto:’.” User-agent headers provide administrators with user information that facilitates better administration and moderation of the API, and it is generally good etiquette to include a header with any API request.
To edit your User-Agent header:
Show
(next to HTTP headers to be used when fetching URLs
). Note that OpenRefine has already populated the User-Agent
fieldhttp://api.crossref.org/journals/{ISSN}
where {ISSN}
` is replaced with the ISSN of the journal"https://api.crossref.org/journals/"+value”
OK
You should see a message at the top on the OpenRefine screen indicating it is fetching some data, and how far it has got. Wait for this to complete. Fetching data for a single row should take only ten seconds or so, but fetching data for all rows will take longer. You can speed this up by modifying the Throttle Delay
setting in the Add column by fetching URLs
dialog which controls the delay between each URL request made by OpenRefine. This is defaulted to a rather large 5000 milliseconds (5 seconds).At this point you should have a new cell containing a long text string in a format called JSON (this stands for JavaScript Object Notation).
OpenRefine has a function for extracting data from JSON (sometimes referred to as parsing the JSON). The parseJson
function is explained in more detail at https://github.com/OpenRefine/OpenRefine/wiki/GREL-Other-Functions
Edit column->Add column based on this column
value.parseJson().message.title
Using Add column based on this column
is simply that this allows you to retain the full JSON and extract further data from it if you need to. If you only wanted the title and did not need any other information from the JSON you could use Edit cells->Transform…
with the same GREL expression.
Looking up data by url is really useful. For larger datasets it can be slow. There are other ways to connect to external resources or services.
A reconciliation service is a web service that, given some text which is a name or label for something, returns a ranked list of potential entities matching the criteria. The candidate text does not have to match each entity’s official name perfectly, and that’s the whole point of reconciliation–to get from ambiguous text name to precisely identified entities.
This is quicker and more advanced than the ‘by url’ method. But it requires the resource you are linking to to provide its data as a reconciliation service. You can find some examples here: https://github.com/OpenRefine/OpenRefine/wiki/Reconcilable-Data-Sources
These services can directly be added to OpenRefine using their URL by clicking Reconcile -> Add Standard Service
https://reconciliation-api.github.io/testbench/
In this exercise you are going to use the VIAF Reconciliation service written by Jeff Chiu. Jeff offers two ways of using the reconciliation service - either via a public service he runs at http://refine.codefork.com, or by installing and running the service locally using the instructions at https://github.com/codeforkjeff/conciliator.
Once you have chosen which service you are going to use:
Publisher
column use the dropdown menu to choose Reconcile->Start Reconciling
Add Standard Service…
and in the dialogue that appears enter:
https://refine.codefork.com/reconcile/viaf
for Jeff’s public serviceCorporate Name
(it seems like the VIAF Reconciliation Service is slightly intelligent about this and will only offer options that are relevant)Auto-match candidates with high confidence
. This can be a time saver, but in this case you are going to uncheck it so you can see the results before a match is madeStart Reconciling
Reconciliation is an operation that can take a little time if you have many values to look up. However, in this case there are only 6 publishers to check, so it should work quite quickly.
Once the reconciliation has completed two Facets should be created automatically:
Publisher: Judgement
Publisher: best candidate’s score
These are two of several specific reconciliation facets and actions that you can get from the Reconcile
menu (from the column drop down menu).
Publisher: best candidate’s score
facetIf you look at the Publisher column, you should see some cells have found one or more matches - the potential matches are shown in a list in each cell. Next to each potential match there is a ‘tick’ and a ‘double tick’. To accept a reconciliation match you can use the ‘tick’ options in cells. The ‘tick’ accepts the match for the single cell, the ‘double tick’ accepts the match for all identical cells.
text facet
on the Publisher
columnInternational Union of Crystallography
Publisher
column you should be able to see the various potential matches. Clicking on a match will take you to the VIAF page for that entity.Publisher column
cells for the option International Union of Crystallography
. This will accept this as a match for all cells - you should see the other options all disappearPublisher: Judgement
facet. This should now show that 858 items are ‘matched’ (if this does not update, try refreshing the facets)We could do these one by one, but if we are confident with the matches, there is an option to accept all:
Publisher
column use the dropdown menu to choose Reconcile->Actions->Match each cell to its best candidate
As well as these services, some data providers have gone further and written openrefine extensions. Whether you use these or which ones you use will depend a lot on your dataset and subject area and what you are trying to achieve. But for now it is really to know that you can do this with OpenRefine. A list of Extensions (not necessarily complete) is given on the OpenRefine downloads page at http://openrefine.org/download.html
One of these extensions tries to work around the limitation of Reconciliation services described above, by making it possible to use a reconciliation service against ‘linked data’ sources which have SPARQL endpoints . For more information on this see the ‘RDF Extension’ at http://refine.deri.ie. An example of how this works is given in more detail at http://refine.deri.ie/showcases.