Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add experimental DDC wrapper
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
include __DIR__.'/../vendor/autoload.php'; | ||
\JSKOS\Server::runService(new DDCService()); |
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,66 @@ | ||
<?php | ||
|
||
/** | ||
* Implements a basic JSKOS concepts endpoint for DDC | ||
* by wrapping Norsk WebDewey (Skosmos instance). | ||
*/ | ||
|
||
include_once __DIR__.'/../../vendor/autoload.php'; | ||
|
||
use JSKOS\RDFMapping; | ||
|
||
class DDCService extends JSKOS\RDFBasedService { | ||
public static $CONFIG_DIR = __DIR__; | ||
|
||
protected $supportedParameters = ['notation']; | ||
|
||
public function query($query) { | ||
|
||
$jskos = $this->queryUriSpace($query); | ||
if (!$jskos) return; | ||
|
||
// clean up notation and URI | ||
// FIXME: what if both uri and notation are queried? | ||
$notation = $jskos->notation[0]; | ||
if ( substr($jskos->uri,-5) == '/e23/') { | ||
if ( strpos($jskos->uri, 'T') ) { | ||
return; | ||
} | ||
# $notation = preg_replace('!/e23/$!','',$notation); | ||
# if ( strpos($notation,'--') ) $notation = 'T'.$notation; | ||
# $jskos->notation[0] = $notation; | ||
} else { | ||
$jskos->uri = preg_replace('/T/','',$jskos->uri); | ||
$jskos->uri .= '/e23/'; | ||
} | ||
|
||
$jskos->notation = []; // get via LOD | ||
|
||
$url = "http://data.ub.uio.no/skosmos/rest/v1/ddc/data?" | ||
. http_build_query([ | ||
'uri' => $jskos->uri, | ||
'format' => 'text/turtle' | ||
]); | ||
error_log($url); | ||
|
||
# FIXME: timeouts | ||
$rdf = RDFMapping::loadRDF($url, $jskos->uri, 'turtle'); | ||
if (!$rdf or $rdf->getGraph()->countTriples() < 3) return; | ||
|
||
|
||
$this->applyRdfMapping($rdf, $jskos); | ||
|
||
// add DDC specific types | ||
$notation = $jskos->notation[0]; | ||
if ( preg_match('/T([1-6A-C]+)--/', $notation) ) { | ||
$jskos->type[] = 'http://dewey.info/type/TableEntry'; | ||
} | ||
if ( preg_match('/-[^-]/', $notation) ) { | ||
$jskos->type[] = 'http://dewey.info/type/NumberSpan'; | ||
} | ||
|
||
$jskos->inScheme[] = ['uri'=>'http://dewey.info/scheme/ddc/']; | ||
|
||
return $jskos; | ||
} | ||
} |
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,37 @@ | ||
_ns: | ||
skos: http://www.w3.org/2004/02/skos/core# | ||
|
||
_uriSpace: | ||
Concept: | ||
uriSpace: http://dewey.info/class/ | ||
notationPattern: '/^( \d{1,3}(-\d{1,3})? | \d{3}\.\d+(-\d{3}\.\d+)? | T?([12456]|3[ABC]?)--\d+(-\d+)?) (\/e23\/)? $/x' | ||
|
||
notation: | ||
type: plain | ||
properties: | ||
- skos:notation | ||
|
||
prefLabel: | ||
type: literal | ||
unique: true | ||
properties: | ||
- skos:prefLabel | ||
|
||
broader: | ||
type: URI | ||
jskos: Concept | ||
properties: | ||
- skos:broader | ||
|
||
narrower: | ||
type: URI | ||
jskos: Concept | ||
properties: | ||
- skos:narrower | ||
|
||
inScheme: | ||
type: URI | ||
jskos: Concept | ||
properties: | ||
- skos:inScheme | ||
|
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