This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
532 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
web: vendor/bin/heroku-php-apache2 wrappers/ | ||
web: vendor/bin/heroku-php-apache2 src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/** | ||
* Implements a basic JSKOS concepts endpoint for GND. | ||
* | ||
* This wrapper converts GND RDF/XML to JSKOS. | ||
* | ||
* @package JSKOS | ||
*/ | ||
|
||
include realpath(__DIR__) . '/lib/GNDService.php'; | ||
|
||
\JSKOS\Server::runService(new GNDService()); | ||
|
||
/* | ||
$concept = new Concept(["uri" => "$uri"]); | ||
foreach (getResources($xml, 'foaf:page') as $page) { | ||
$concept->subjectOf = [ "uri" => $page ]; | ||
} | ||
foreach (getResources($xml, 'gndo:broaderTermGeneral') as $uri) { | ||
$concept->broader[] = [ "uri" => $uri ]; | ||
} | ||
foreach (getLiterals($xml, 'gndo:preferredNameForTheSubjectHeading') as $label) { | ||
$concept->prefLabel["de"] = $label; | ||
} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
include realpath(__DIR__) . '/lib/OpenSKOSService.php'; | ||
|
||
\JSKOS\Server::runService(new OpenSKOSService()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
include realpath(__DIR__) . '/lib/WikidataService.php'; | ||
|
||
\JSKOS\Server::runService(new WikidataService()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>JSKOS-PHP Examples</title> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> | ||
|
||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> | ||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | ||
<!--[if lt IE 9]> | ||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | ||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | ||
<![endif]--> | ||
|
||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> | ||
</head> | ||
<body> | ||
<a href="https://github.com/gbv/jskos-php-examples"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a> | ||
<div class="container"> | ||
|
||
<h1>JSKOS-PHP Examples</h1> | ||
<p> | ||
This page provides sample applications and services that make use of | ||
<a href="http://gbv.github.io/jskos">JSKOS data format for Knowledge Organization Systems</a>. | ||
All examples are written in PHP, based on | ||
<a href="https://packagist.org/packages/gbv/jskos">JSKOS PHP library</a>, and available | ||
as Open Source <a href="https://github.com/gbv/jskos-php-examples">at GitHub</a>. Please use | ||
<a href="https://github.com/gbv/jskos-php-examples/issues">the issue tracker</a> for feedback! | ||
</p> | ||
<h2>Terminology Services</h2> | ||
<p> | ||
The following web services wrap existing terminology databases to provide | ||
access via <a href="https://gbv.github.io/jskos-api">JSKOS-API</a>. | ||
JSKOS-API is far from being finally specified, so this is a preview. | ||
</p> | ||
<?php | ||
|
||
include '../vendor/autoload.php'; | ||
|
||
use Symfony\Component\Yaml\Yaml; | ||
$services = Yaml::parse(file_get_contents('services.yaml')); | ||
|
||
foreach ($services as $name => $service) { | ||
$source = "src/lib/${name}Service.php"; | ||
?> | ||
<h3><?= $name ?><small> | ||
| ||
<a href='https://github.com/gbv/jskos-php-examples/blob/master/<?= $source ?>'> | ||
<i class="fa fa-github"></i> source</a> | ||
</small> | ||
</h2> | ||
<?php if ($service['about'] or $service['url']) { ?> | ||
<p> | ||
<span class="glyphicon glyphicon-arrow-right"></span> | ||
<?php if ($service['url']) echo "<a href='".$service['url']."'>"; ?> | ||
<?= htmlspecialchars($service['about'] ? $service['about'] : $service['url']); ?> | ||
<?php if ($service['url']) echo "</a>"; ?> | ||
</p> | ||
<?php } | ||
$queryExamples= $service['examples']; | ||
if ($queryExamples) { | ||
echo "<table class='table table-condensed'>"; | ||
echo "<thead><tr><th>sample queries to <a href='$name.php'>JSKOS-API endpoint</a></th></tr></thead>"; | ||
echo "<tr>"; | ||
foreach ($queryExamples as $query) { | ||
$query = http_build_query($query); | ||
echo "<td>"; | ||
echo "<a href='".htmlentities("$name.php?$query")."'>"; | ||
echo "?".htmlentities(urldecode($query)); | ||
echo "</a></td></tr>"; | ||
} | ||
echo "</table>"; | ||
} else { | ||
echo "<a href='$name.php'>service endpoint</a>"; | ||
} | ||
echo "</p>"; | ||
} | ||
?> | ||
|
||
<hr> | ||
<a href="https://travis-ci.org/gbv/jskos-php-examples"> | ||
<img src="https://travis-ci.org/gbv/jskos-php-examples.svg?branch=master"> | ||
</a> | ||
<a href="https://coveralls.io/r/gbv/jskos-php-examples"> | ||
<img src="https://coveralls.io/repos/github/gbv/jskos-php-examples/badge.svg?branch=master"> | ||
</a> | ||
|
||
</div> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
<?php | ||
|
||
/** | ||
* JSKOS-API Wrapper to GND via LOD access via URI. | ||
*/ | ||
|
||
include realpath(__DIR__.'/../..') . '/vendor/autoload.php'; | ||
|
||
use JSKOS\Service; | ||
use JSKOS\Concept; | ||
use JSKOS\Page; | ||
use JSKOS\Error; | ||
|
||
EasyRdf_Namespace::set('gnd','http://d-nb.info/standards/elementset/gnd#'); | ||
|
||
class GNDService extends Service { | ||
|
||
static $GNDOntology2JSKOS = [ | ||
'broader' => [ | ||
'type' => 'URI', | ||
'properties' => [ | ||
'gnd:broaderTermPartitive' | ||
] | ||
], | ||
'related' => [ | ||
'type' => 'URI', | ||
'properties' => [ | ||
'gnd:accordingWork', | ||
'gnd:acquaintanceshipOrFriendship', | ||
] | ||
], | ||
'relatedPlace' => [ | ||
'type' => 'URI', | ||
'properties' => [ | ||
'gnd:associatedPlace', | ||
'gnd:characteristicPlace', | ||
'gnd:otherPlace', | ||
'gnd:spatialAreaOfActivity', | ||
'gnd:relatedPlaceOrGeographicName', | ||
'gnd:place' | ||
], | ||
], | ||
'prefLabel' => [ | ||
'type' => 'literal', | ||
'unique' => true, | ||
'properties' => [ | ||
'gnd:preferredName', | ||
'gnd:preferredNameForThePerson', | ||
'gnd:preferredNameForTheConferenceOrEvent', | ||
'gnd:preferredNameForThePlaceOrGeographicName', | ||
'gnd:preferredNameForTheFamily', | ||
'gnd:preferredNameForTheSubjectHeading', | ||
'gnd:preferredNameForTheCorporateBody', | ||
'gnd:preferredNameForTheWork', | ||
], | ||
], | ||
'scopeNote' => [ | ||
'type' => 'literal', | ||
'properties' => [ | ||
'gnd:biographicalOrHistoricalInformation' | ||
] | ||
], | ||
'definition' => [ | ||
'type' => 'literal', | ||
'properties' => ['gnd:definition'] | ||
], | ||
'relatedDate' => [ | ||
'type' => 'datatype', | ||
'properties' => [ | ||
'gnd:associatedDate', | ||
'gnd:dateOfDiscovery', | ||
'gnd:periodOfActivity', | ||
] | ||
] | ||
|
||
]; | ||
|
||
|
||
protected $supportedParameters = ['notation']; | ||
|
||
public function query($query) { | ||
|
||
if (isset($query['uri'])) { | ||
if (preg_match('/^http:\/\/d-nb\.info\/gnd\/([0-9X-]+)$/', $query['uri'], $match)) { | ||
$id = $match[1]; | ||
} | ||
} | ||
|
||
if (isset($query['notation'])) { | ||
if (preg_match('/^[0-9X-]+$/', $query['notation'])) { | ||
$notation = strtoupper($query['notation']); | ||
if (isset($id) and $id != $notation) { | ||
unset($id); | ||
} else { | ||
$id = $notation; | ||
} | ||
} | ||
} | ||
|
||
if (!isset($id)) { | ||
return null; | ||
} | ||
|
||
$uri = "http://d-nb.info/gnd/$id"; | ||
|
||
$rdf = new EasyRdf_Graph(); | ||
try { | ||
// TODO: use newAndLoad($uri); | ||
$rdf->load("$uri/about/lds","rdfxml"); | ||
$gnd = $rdf->resource($uri); | ||
} catch (Exception $e){ | ||
// not found or some error at DNB | ||
return null; | ||
} | ||
|
||
if ($rdf->isEmpty() or !$gnd) { | ||
return null; | ||
} | ||
|
||
$jskos = new Concept(['uri'=>$uri, 'notation' => [$id]]); | ||
|
||
foreach ( $gnd->allResources('owl:sameAs') as $id ) { | ||
$jskos->identifier[] = "$id"; | ||
} | ||
|
||
foreach ( $gnd->typesAsResources() as $type ) { | ||
$jskos->type[] = (string)$type; | ||
} | ||
#error_log($rdf->serialise('turtle')); | ||
|
||
|
||
foreach (static::$GNDOntology2JSKOS as $property => $mapping) | ||
{ | ||
$type = $mapping['type']; | ||
|
||
foreach ( $mapping['properties'] as $gndProperty ) { | ||
|
||
if ($type == 'URI') | ||
{ | ||
foreach ( $gnd->allResources($gndProperty) as $resource ) { | ||
if (!isset($jskos->$property)) { | ||
$jskos->$property = []; | ||
} | ||
array_push( $jskos->$property, ['uri' => (string)$resource] ); | ||
} | ||
|
||
} elseif ($type == 'literal') | ||
{ | ||
foreach ( $gnd->allLiterals($gndProperty) as $literal ) { | ||
$value = (string)$literal; | ||
$language = $literal->getLang() ? $literal->getLang() : "de"; | ||
|
||
$languageMap = isset($jskos->$property) ? $jskos->$property : []; | ||
|
||
if (isset($mapping['unique'])) { | ||
$languageMap[$language] = $value; | ||
} else { | ||
$languageMap[$language][] = $value; | ||
} | ||
|
||
$jskos->$property = $languageMap; | ||
} | ||
} elseif ($type == 'datatype') { | ||
foreach ( $gnd->allLiterals($gndProperty) as $literal ) { | ||
$value = (string)$literal; | ||
if (!isset($jskos->$property)) { | ||
$jskos->$property = []; | ||
} | ||
array_push( $jskos->$property, $value ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $jskos; | ||
} | ||
} |
Oops, something went wrong.