Gitlab Premium Edition

Skip to content
Snippets Groups Projects
Commit 49c1a601 authored by msuhr1's avatar msuhr1
Browse files

Merge branch '7.x-1.0-dev' into '7.x-1.x'

Version 1.0

See merge request !1
parents 52cef669 05bad057
Branches
Tags 1.0
1 merge request!1Version 1.0
......@@ -9,11 +9,25 @@ abstract class RDPWikidataCommons {
const MODULE_NAME = 'rdp_wikidata';
private static $module_path = '';
/**
* Return file system path to rdp_wikidata module
*
* @return string file system path
*/
public static function module_path() {
if (empty(self::$module_path)) {
self::$module_path = drupal_get_path('module', self::MODULE_NAME);
}
return self::$module_path;
}
/**
* Trigger autoloading for composer-installed dependencies.
*/
public static function autoload() {
include_once(drupal_get_path('module', self::MODULE_NAME)
include_once(self::module_path()
. '/vendor/autoload.php');
}
......@@ -24,12 +38,13 @@ abstract class RDPWikidataCommons {
* @return string
*/
public static function path_resources($type = '') {
$path = base_path() . drupal_get_path('module', 'rdp_wikidata')
$path = base_path() . self::module_path()
. '/resources/';
if ($type == 'icon') {
$path .= 'wikidata_logo.svg';
}elseif ($type == 'icon_scholia'){
}
elseif ($type == 'icon_scholia') {
$path .= 'scholia_logo.png';
}
......@@ -79,4 +94,63 @@ abstract class RDPWikidataCommons {
],
];
}
/**
* Returns internal ID of the Subject defined by the External-ID module. @return int
*
* @see \ExternalIDSubject
*
*/
public static function rdp_external_id_wikidata_id_type() {
return "Wikidata ID";
}
/**
* Check if a Wikidata ID exists for a \Publication based on PubMed-ID and/or DOI
*
* @param int $publication_id
*
* @return bool|string
*/
public static function publication_fetch_wikidata_id($publication_id) {
$type = RDPWikidataCommons::rdp_external_id_wikidata_id_type();
$subject = PublicationExternalIdentifier::EX_ID_SUBJECT;
$exid = ExternalIDRepository::findByTypeSubjectId($type, $subject, $publication_id);
/**
* @var \ExternalID $exid
*/
if ($exid) {
$wikidata_id = $exid->getValue();
}
else {
/**
* Try to find Wikidata ID for the publication by DOI, then PMID.
*/
$publication = PublicationRepository::findById($publication_id);
$client = new WikidataClient();
$wikidata_id = $client->findByDoi($publication->getDOI());
if (!$wikidata_id) {
$wikidata_id = $client->findByPMID($publication->getPMID());
}
if ($wikidata_id) {
/**
* Store \ExternalIdentifier for future use.
*/
$exid = new ExternalID();
$exid->setSubject(ExternalIDSubjectRepository::findBySubject(PublicationExternalIdentifier::EX_ID_SUBJECT)
->getId());
$exid->setSubjectId($publication_id);
$exid->setType(ExternalIDTypeRepository::findByLabel(RDPWikidataCommons::rdp_external_id_wikidata_id_type())
->getId());
$exid->setValue($wikidata_id);
$exid->save();
$pub_exid = new PublicationExternalIdentifier();
$pub_exid->setExternalId($exid->getId());
$pub_exid->setDescription("Wikidata ID");
$pub_exid->save();
}
}
return $wikidata_id;
}
}
\ No newline at end of file
name = RDP Wikidata
package = Research Data Platform
description = Integration of Wikidata linking into Research Data Platform
version = 0.1
version = 1.0
core = 7.x
; Literature module 1.2 introduces rdp_external_id module dependency
dependencies[] = sfb_literature (>=1.2)
files[] = classes/RDPWikidataCommons.php
files[] = classes/WikidataClient.php
\ No newline at end of file
......@@ -3,24 +3,35 @@
* @file Integration of Wikidata linking into Research Data Platform
*/
define('RDP_WIKIDATA_URL_REPORTS_PUBLICATION_OVERVIEW', 'admin/reports/rdp_wikidata_publications');
/**
* Implements @see \hook_rdp_publication_display_table_alter()
* Implements @see \hook_menu()
*/
function rdp_wikidata_rdp_publication_display_table_alter(
$publication_id,
$rows
) {
function rdp_wikidata_menu() {
$items = [];
$items[RDP_WIKIDATA_URL_REPORTS_PUBLICATION_OVERVIEW] = [
'title' => 'RDP Wikidata Publications Overview',
'description' => 'Overview of all publications and assigned Wikidata IDs. (Loading the report may
take a while initially depending on the number of registered publications)',
'page callback' => 'rdp_wikidata_reports_publications_overview',
'access arguments' => ['administer site configuration'],
'type' => MENU_NORMAL_ITEM,
];
return $items;
}
$publication = PublicationRepository::findById($publication_id);
/**
* Implements @see \hook_rdp_publication_display_table_alter()
*/
function rdp_wikidata_rdp_publication_display_table_alter($publication_id, $rows) {
/**
* Try to find Wikidata ID for the publication by DOI, then PMID.
* Fetch and/or register the Wikidata ID of the current publication
*/
$client = new WikidataClient();
$wikidata_id = $client->findByDoi($publication->getDOI());
if (!$wikidata_id) {
$wikidata_id = $client->findByPMID($publication->getPMID());
}
$wikidata_id = RDPWikidataCommons::publication_fetch_wikidata_id($publication_id);
/**
* Display Wikidata link if ID was found.
......@@ -35,16 +46,6 @@ function rdp_wikidata_rdp_publication_display_table_alter(
WikidataClient::idToUrl($wikidata_id), $l_parameters);
$rows['title']['value'] .= ' ' . $link;
/**
* Add a designated Wikidata ID row at the bottom of the table.
*/
$link = l(RDPWikidataCommons::icon_wikidata_inline() . ' ' . $wikidata_id,
WikidataClient::idToUrl($wikidata_id), $l_parameters);
$rows['wikidata'] = [
'title' => t("Wikidata Identifier"),
'value' => $link,
];
/**
* Add a designated Scholia-link row at the bottom of the table.
*/
......@@ -58,4 +59,45 @@ function rdp_wikidata_rdp_publication_display_table_alter(
];
}
return $rows;
}
/**
* Page callback: list all registered publications and indicate whether a Wikidata ID could be matched or not
*
* @return string HTML markup
*/
function rdp_wikidata_reports_publications_overview() {
$publications = PublicationRepository::findAll();
$rows = [];
$count_wikidata = 0;
$count_total = count($publications);
foreach ($publications as $publication) {
$wikidata_id = RDPWikidataCommons::publication_fetch_wikidata_id($publication->id);
$link = '';
$l_parameters = ['attributes' => ['target' => '_blank']];
if ($wikidata_id) {
$link = l($wikidata_id, WikidataClient::idToUrl($wikidata_id), $l_parameters);
$count_wikidata++;
}
$rows[] = [l($publication->title, Publication::url_by_id($publication->id)), $publication->publication_year, $link];
}
$header = ['Publication', 'Year', 'Wikidata ID'];
/**
* Print basic statistical info
*/
$coverage = round($count_wikidata / $count_total * 100, 2);
$display = "<div><p>Total number of <strong>$count_total</strong> publications registered,
<strong>$count_wikidata</strong> of which could be automatically identified
as Wikidata items. (<strong>$coverage%</strong>)</p></div>";
try {
$display .= theme('table', ['header' => $header, 'rows' => $rows]);
} catch (Exception $exception) {
// do nothing
}
return $display;
}
\ No newline at end of file
# Research Data Platform Wikidata Integration Module
## What it does
Queries the public collaborative knowledge base
[Wikidata](https://wikidata.org) for items describing scholarly articles
that are registered in an instance of the
[Research Data Platform](https://gitlab.gwdg.de/research-data-platform)
* Checks for each publication item registered through the "Literature"
module of the Research Data Platform whether a Wikidata ID can be
assigned based on PubMed ID or DOI
* If Wikidata ID can be assigned, it is stored as an "External ID" object
* If Wikidata ID is available, it is added to the literature module's
publication display page using the Drupal hook
`hook_rdp_publication_display_table_alter`
## Requirements
Since this is a Drupal module, a working base instance
of [Drupal](https://drupal.org/) 7.x including all subsequent depencies is required.
For third party library installation, [Composer](https://getcomposer.org/)
must be installed.
This Drupal module requires the following custom Drupal modules
installed and enabled to work:
* [RDP Commons](https://gitlab.gwdg.de/research-data-platform/sfb-commons)
* [RDP Literature](https://gitlab.gwdg.de/research-data-platform/sfb-literature)
* RDP External ID (part of RDP Literature module distribution
since version `7.x-1.2`)
## Installation
1. Make sure all the dependencies are installed/copied to the Drupal modules
directory.
2. Run `composer install` in RDP_Wikidata module folder
3. Go to the Drupal modules administration page of your Drupal instance
(`$BASE_PATH/admin/modules`) to install and enable the module.
## Libraries
* [PHP Wikidata API client](https://github.com/freearhey/wikidata)
by Aleksandr Statciuk, MIT license
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment