Skip to content

Commit

Permalink
BARTOC: Fix #13 and #9
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Nov 1, 2016
1 parent bbf33c6 commit bfcf9db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
24 changes: 0 additions & 24 deletions src/lib/BARTOCCrawler.php

This file was deleted.

32 changes: 24 additions & 8 deletions src/lib/BARTOCService.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,25 @@ public function entityLookup($uri) {
}
}

$jskos = new ConceptScheme(['uri' => $uri]);

$this->applyRDFMapping($rdf, $jskos);
error_log($rdf->getGraph()->dump('text'));
// neither concept schemes nor registry
$uris = RDFMapping::getURIs($rdf, 'rdf:type');
if (!in_array("http://schema.org/Dataset", $uris)) {
return;
}

# TODO: Extend registry-specific fields
if ( empty(RDFMapping::getURIs($rdf, 'dct:subject')) ) {
$jskos = new Registry($jskos);
$jskos = new Registry(['uri' => $uri ]);
} else {
$jskos = new ConceptScheme(['uri' => $uri]);
}

$this->applyRDFMapping($rdf, $jskos);

# Remove Wikidata link from URL field
$urls = RDFMapping::getURIs($rdf, 'schema:url');
$urls = preg_grep("/^http:\/\/www\.wikidata\.org\/entity/", $urls, PREG_GREP_INVERT);
if (!empty($urls)) $jskos->url = $urls[0];

# map licenses
foreach ( RDFMapping::getURIs($rdf, 'schema:license') as $license ) {
if (isset($this->licenses[$license])) {
Expand Down Expand Up @@ -163,10 +172,17 @@ public function entityLookup($uri) {

# try to detect language
if (isset($jskos->prefLabel['und'])) {
$guess = $this->detectLanguage( $jskos->prefLabel['und'], $jskos->languages );
$label = $jskos->prefLabel['und'];
$guess = $this->detectLanguage( $label, $jskos->languages );
if ($guess) {
$jskos->prefLabel[$guess] = $jskos->prefLabel['und'];
$jskos->prefLabel[$guess] = $label;
unset($jskos->prefLabel['und']);
} else {
# remove if same label in known language exists
unset($jskos->prefLabel['und']);
if (!in_array($label, $jskos->prefLabel)) {
$jskos->prefLabel['und'] = $label;
}
}
}

Expand Down

0 comments on commit bfcf9db

Please sign in to comment.