Skip to content

A tool to enrich any OCDM compliant Knowledge Graph, finding new identifiers and deduplicating entities.

License

Notifications You must be signed in to change notification settings

opencitations/oc_graphenricher

Repository files navigation

GraphEnricher

A tool to enrich any OCDM compliant Knowledge Graph, finding new identifiers and deduplicating entities.

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact
  6. Acknowledgements

About The Project

This tool is divided in two part: an Enricher component responsible for finding new identifiers and adding them to the graph set, and an InstanceMatching component responsible for deduplicating any entity that share the same identifier.

Enricher

The enricher iterates each Bibliographic Resources (BRs) contained in the graph set. For each Bibliographic Resources (BRs) (avoiding issues and journals), get the list of the identifiers already contained in the graph set and check if it already has a DOI, an ISSN, a Wikidata ID and an OpenAlex ID:

  • If an ISSN is specified, query Crossref to extract other ISSNs
  • If there's no DOI, query Crossref to get one by means of all the other data extracted
  • If there's no Wikidata ID, query Wikidata to get one by means of all the other identifiers
  • If there's no OpenAlex ID, query OpenAlex to get one by means of all the other identifiers

Any new identifier found will be added to the Bibliographic Resource (BR).

Then, for each Agent Role (AR) related to the Bibliographic Resource (BR), get the list of all the identifier already contained in its linked Responsible Agent (RA) and:

  • If it doesn't have an ORCID, query ORCID to get it
  • If it doesn't have a VIAF, query VIAF to get it
  • If it doesn't have a Wikidata ID, query Wikidata by means of all the other identifier to get one
  • If the Responsible Agent (RA) is related to a publisher, query Crossref to get its ID by means of its DOI

Any new identifier found will be added to the RA related to the AR.

In the end it will store a new graph set and its provenance.

NB: even if it's not possible to have an identifier duplicated for the same entity, it's possible that in the whole graph set you could find different identifiers that share the same schema and literal. For this purpose, you should use the instancematching module after you've enriched the graph set.

APIs and identifiers

Currently, there are 5 external API involved:

  • Crossref
  • ORCID
  • VIAF
  • WikiData
  • OpenAlex

and we can discover the following identifiers:

  • DOI
  • ISSN
  • Crossref's publisher ID
  • ORCID
  • VIAF
  • Wikidata ID (by means of any other identifier, e.g.: PMID, VIAF, DOI, ...)
  • OpenAlex Work ID and Source ID (only for bibliographic resources and by means of other identifiers, e.g.: PMID, DOI, ...)

It's possible, anyway, to extend the class QueryInterface to add any other useful API.

Instance Matching

The instance matching process is articulated in three sequential step:

  • match the Responsible Agents (RAs)
  • match the Bibliographic Resources (BRs)
  • match the IDs

Matching the Responsible Agents (RAs)

Discover all the Responsible Agents (RAs) that share the same identifier's literal, creating a graph of them. Then merge each connected component (cluster of Responsible Agents (RAs) linked by the same identifier) into one. For each couple of Responsible Agent (RA) that are going to be merged, substitute the references of the Responsible Agent (RA) that will no longer exist, by removing the Responsible Agent (RA) from each of its referred Agent Role (AR) and add, instead, the merged one)

If the Responsible Agent (RA) linked by the Agent Role (AR) that will no longer exist is not linked by any other Agent Role (AR), then it will be marked as to be deleted, otherwise not.

In the end, generate the provenance and commit pending changes in the graph set

Matching the Bibliographic Resources (BRs)

Discover all the Bibliographic Resources (BRs) that share the same identifier's literal, creating a graph of them. Then merge each connected component (cluster of Bibliographic Resources (BR) linked by the same identifier) into one. For each couple of Bibliographic Resources (BRs) that are going to be merged, merge also:

  • their containers by matching the proper type (issue of BR1 -> issue of BR2)
  • their publisher

In the end, generate the provenance and commit pending changes in the graph set

Matching the IDs

Discover all the IDs that share the same schema and literal, then merge all into one and substitute all the reference with the merged one.

In the end, generate the provenance and commit pending changes in the graph set

Getting Started

To get a local copy up and running follow these simple steps:

  1. install python >= 3.8:

sudo apt install python3

  1. Install oc_graphenricher via pip:
pip install oc-graphenricher

Installing from the sources

  1. Having already installed python, you can also install GraphEnricher via cloning this repository:
git clone https://github.com/opencitations/oc_graphenricher`
cd ./oc_graphenricher
  1. install poetry:

pip install poetry

  1. install all the dependencies:

poetry install

  1. build the package:

poetry build

  1. install the package:

pip install ./dist/oc_graphenricher-<VERSION>.tar.gz

  1. run the tests (from the root of the project):
poetry run test

Usage

It's supposed to accept only graph set objects. To create one:

g = Graph()
g = g.parse('../data/test_dump.ttl', format='nt11')

reader = Reader()
g_set = GraphSet(base_iri='https://w3id.org/oc/meta/')
entities = reader.import_entities_from_graph(g_set, g, enable_validation=False, resp_agent='https://w3id.org/oc/meta/prov/pa/2')

Enrichment

At this point, to run the enrichment phase:

from oc_graphenricher.enricher import Enricher

enricher = GraphEnricher(g_set)
enricher.enrich()

You'll see the progress bar with an estimate of the time needed and the average time spent for each Bibliographic Resource (BR) enriched.

Deduplication

Then, having serialized the enriched graph set, and having read it again as the g_set object, to run the deduplication step do:

from oc_graphenricher.instancematching import InstanceMatching

matcher = InstanceMatching(g_set)
matcher.match()

The match method will run sequentially:

  • deduplication of Responsible Agents (RAs)
  • deduplication of Bibliographic Resources (BRs)
  • deduplication of Identifiers (IDs)
  • save to file

If you need to, you can also deduplicate one of those independently of each other.

To deduplicate Responsible Agents (RAs):

from oc_graphenricher.instancematching import InstanceMatching

matcher = InstanceMatching(g_set)
matcher.instance_matching_ra()
matcher.save()

To deduplicate Bibliographic Resources (BRs):

from oc_graphenricher.instancematching import InstanceMatching

matcher = InstanceMatching(g_set)
matcher.instance_matching_br()
matcher.save()

To deduplicate Identifiers (IDs):

from oc_graphenricher.instancematching import InstanceMatching

matcher = InstanceMatching(g_set)
matcher.instance_matching_id()
matcher.save()

License

Distributed under the ISC License. See LICENSE for more information.

Contact

Current maintainers of the repository

Author of the repository and original code:

Project Link: https://github.com/opencitations/oc_graphenricher

Acknowledgements

This project has been developed as part of the Wikipedia Citations in Wikidata research project, under the supervision of prof. Silvio Peroni.

About

A tool to enrich any OCDM compliant Knowledge Graph, finding new identifiers and deduplicating entities.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages