Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 191bc6e

Browse files
committed
Update dependencies
1 parent 5e80e8f commit 191bc6e

File tree

8 files changed

+181
-110
lines changed

8 files changed

+181
-110
lines changed

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,46 @@
1+
# viaf-jskos
2+
3+
[![Latest Version](https://img.shields.io/packagist/v/gbv/viaf-jskos.svg?style=flat-square)](https://packagist.org/packages/gbv/viaf-jskos)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
5+
[![Build Status](https://img.shields.io/travis/gbv/viaf-jskos.svg?style=flat-square)](https://travis-ci.org/gbv/viaf-jskos)
6+
[![Coverage Status](https://img.shields.io/coveralls/gbv/viaf-jskos/master.svg?style=flat-square)](https://coveralls.io/r/gbv/viaf-jskos)
7+
[![Quality Score](https://img.shields.io/scrutinizer/g/gbv/viaf-jskos.svg?style=flat-square)](https://scrutinizer-ci.com/g/gbv/viaf-jskos)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/gbv/viaf-jskos.svg?style=flat-square)](https://packagist.org/packages/gbv/jskos)
9+
110
This repository contains a wrapper to access the [Virtual International Authority File (VIAF)](http://viaf.org) in [JSKOS format](https://gbv.github.io/jskos/) via [Entity Lookup Microservice API (ELMA)](http://gbv.github.io/elma/).
211

312
# Requirements
413

5-
Requires PHP 7 and the [jskos-rdf](https://packagist.org/packages/gbv/jskos-rdf) PHP library.
14+
Requires PHP 7, [jskos-rdf](https://packagist.org/packages/gbv/jskos-rdf) package and a
15+
[HTTP client-implementation](https://packagist.org/packages/php-http/client-implementation) package.
616

717
# Installation
818

19+
Install a HTTP client implementation package, e.g. [curl-client](https://packagist.org/packages/php-http/curl-client) and this package:
20+
921
~~~bash
10-
composer require gbv/viaf-jskos
22+
composer require php-http/curl-client gbv/viaf-jskos
1123
~~~
1224

1325
This will automatically create `composer.json` for your project (unless it already exists) and add viaf-jskos as dependency. Composer also generates `vendor/autoload.php` to get autoloading of all dependencies.
1426

1527
# Usage
1628

17-
The wrapper can be used as instance of class `\VIAF\JSKOS\Service`, a subclass of `\JSKOS\Service`:
29+
The wrapper can be used as instance of class `\JSKOS\Service\VIAF`, a subclass of `\JSKOS\Service`:
1830

1931
~~~php
2032
require 'vendor/autoload.php';
2133

22-
$service = new \VIAF\JSKOS\Service();
34+
$service = new \JSKOS\Service\VIAF();
2335

24-
$jskos = $service->queryURI("http://viaf.org/viaf/102333412/");
25-
$jskos = $service->query(["uri" => "http://viaf.org/viaf/102333412/"]);
36+
$jskos = $service->queryURI("http://viaf.org/viaf/102333412");
37+
$jskos = $service->query(["uri" => "http://viaf.org/viaf/102333412"]);
2638
$jskos = $service->query(["notation" => "102333412"]);
2739
~~~
2840

29-
See [jskos-php-examples](https://github.com/gbv/jskos-php-examples/) for an example how to use the wrapper as part of a larger PHP application.
41+
This repository contains a command line script to query VIAF in JSKOS format:
3042

31-
This repository also contains a command line script to query VIAF in JSKOS format:
32-
33-
php examples/viaf2jskos.php http://viaf.org/viaf/102333412/
43+
php examples/viaf2jskos.php http://viaf.org/viaf/102333412
3444
php examples/viaf2jskos.php 102333412
3545
php examples/viaf2jskos.php Jane Austen
3646

@@ -44,9 +54,4 @@ See `CONTRIBUTING.md` of repository [jskos-php](https://packagist.org/packages/g
4454

4555
Jakob Voß <[email protected]>
4656

47-
viaf-jskos is licensed under the LGPL license (see `LICENSE` for details).
48-
49-
[![Latest Stable Version](https://poser.pugx.org/gbv/viaf-jskos/v/stable)](https://packagist.org/packages/gbv/viaf-jskos)
50-
[![License](https://poser.pugx.org/gbv/jskos/license)](https://packagist.org/packages/gbv/viaf-jskos)
51-
[![Build Status](https://img.shields.io/travis/gbv/viaf-jskos.svg)](https://travis-ci.org/gbv/viaf-jskos)
52-
[![Coverage Status](https://coveralls.io/repos/gbv/viaf-jskos/badge.svg?branch=master)](https://coveralls.io/r/gbv/viaf-jskos)
57+
This package is licensed under the LGPL license (see `LICENSE` for details).

composer.json

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
{
2-
"authors": [
3-
{
4-
"email": "[email protected]",
5-
"name": "Jakob Voss"
2+
"name": "gbv/viaf-jskos",
3+
"description": "JSKOS wrapper to Virtual International Authority File (VIAF)",
4+
"keywords": [ "VIAF", "JSKOS" ],
5+
"type": "library",
6+
"license": "LGPL",
7+
"authors": [
8+
{
9+
"email": "[email protected]",
10+
"name": "Jakob Voss"
11+
}
12+
],
13+
"require": {
14+
"php": ">=7.0",
15+
"gbv/jskos": "^0.3.4",
16+
"gbv/jskos-rdf": "^0.3",
17+
"gbv/jskos-http": "^0.2.1"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^6.1",
21+
"php-http/curl-client": "^1.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"JSKOS\\Service\\": "src"
26+
}
27+
},
28+
"scripts": {
29+
"test": [
30+
"vendor/bin/phpunit tests --coverage-clover build/logs/clover.xml"
31+
]
632
}
7-
],
8-
"autoload": {
9-
"psr-4": {
10-
"": "src"
11-
}
12-
},
13-
"description": "JSKOS wrapper to Virtual International Authority File (VIAF)",
14-
"keywords": [
15-
"VIAF",
16-
"JSKOS"
17-
],
18-
"license": "LGPL",
19-
"name": "gbv/viaf-jskos",
20-
"require": {
21-
"gbv/jskos": ">=0.1.6",
22-
"gbv/jskos-rdf": ">=0.1.2",
23-
"php": ">=7.0"
24-
},
25-
"require-dev": {
26-
"phpunit/phpunit": ">=6.0.0"
27-
},
28-
"scripts": {
29-
"test": [
30-
"vendor/bin/phpunit tests --verbose"
31-
]
32-
},
33-
"type": "library"
3433
}

examples/viaf2jskos.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
} elseif (preg_match('/^\d+$/', $arg)) {
1717
$query = ['uri' => "http://viaf.org/viaf/$arg"];
1818
} else {
19-
array_shift($argv);
19+
array_shift($argv); # FIXME
2020
$query = ['search' => implode(' ', $argv)];
2121
}
2222

2323
require __DIR__ . '/../vendor/autoload.php';
2424

25-
$service = new \VIAF\JSKOS\Service();
25+
$service = new \JSKOS\Service\VIAF();
2626
$jskos = $service->query($query);
2727
if ($jskos) {
2828
print "$jskos\n";

src/VIAF.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"_ns": {
3+
"dct": "http://purl.org/dc/terms/",
4+
"schema": "http://schema.org/",
5+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6+
},
7+
"_uriSpace": {
8+
"Concept": {
9+
"uriSpace": "http://viaf.org/viaf/",
10+
"notationPattern": "/^[0-9]+$/"
11+
}
12+
},
13+
"type": {
14+
"type": "URI",
15+
"properties": [
16+
"rdf:type"
17+
]
18+
},
19+
"identifier": {
20+
"type": "URI",
21+
"properties": [
22+
"schema:sameAs"
23+
]
24+
},
25+
"notation": {
26+
"type": "plain",
27+
"properties": [
28+
"dct:identifier"
29+
]
30+
},
31+
"prefLabel": {
32+
"type": "literal",
33+
"unique": true,
34+
"properties": [
35+
"schema:name"
36+
]
37+
},
38+
"startDate": {
39+
"type": "plain",
40+
"unique": true,
41+
"properties": [
42+
"schema:birthDate"
43+
]
44+
},
45+
"endDate": {
46+
"type": "plain",
47+
"unique": true,
48+
"properties": [
49+
"schema:deathDate"
50+
]
51+
}
52+
}

src/VIAF.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace JSKOS\Service;
4+
5+
use JSKOS\Concept;
6+
use JSKOS\Resource;
7+
use JSKOS\Result;
8+
use JSKOS\RDF\Mapper;
9+
use JSKOS\ConfiguredService;
10+
use JSKOS\URISpaceService;
11+
12+
/**
13+
* This wrapper converts VIAF Linked Open Data to JSKOS.
14+
*/
15+
class VIAF extends ConfiguredService
16+
{
17+
protected $supportedParameters = ['notation','search'];
18+
19+
private $mapper;
20+
21+
public function __construct(array $config=[]) {
22+
$config = json_decode(file_get_contents(__DIR__."/VIAF.json"), true);
23+
$this->configure($config);
24+
$this->mapper = new Mapper($config);
25+
$this->urispace = new URISpaceService($config['_uriSpace']);
26+
}
27+
28+
public function query(array $query=[], string $path = ''): Result
29+
{
30+
$jskos = $this->urispace->query($query, $path);
31+
if (count($jskos)) {
32+
$concept = $this->queryUri($jskos[0]->uri);
33+
return new Result( $concept ? [$concept] : [] );
34+
} elseif (isset($query['search'])) {
35+
return $this->search($query['search']);
36+
} else {
37+
return new Result();
38+
}
39+
}
40+
41+
public function queryUri($uri) {
42+
$rdf = Mapper::loadRDF("$uri/rdf.xml", $uri);
43+
if (!$rdf || empty($rdf->getGraph()->propertyUris($uri))) return;
44+
45+
$jskos = new Concept([ 'uri' => $uri ]);
46+
$this->mapper->applyAtResource($rdf, $jskos);
47+
48+
return $jskos;
49+
}
50+
51+
# TODO
52+
private function search($search): Result {
53+
$url = 'http://www.viaf.org/viaf/AutoSuggest?' . http_build_query(['query'=>$search]);
54+
try {
55+
# TODO: Add http-client implementation
56+
$json = @json_decode( @file_get_contents($url) );
57+
$result = new Result();
58+
foreach ( ($json->result ?? []) as $hit ) {
59+
$result[] = new Concept([
60+
'prefLabel' => [ 'en' => $hit->term ],
61+
'uri' => "http://viaf.org/viaf/".$hit->viafid,
62+
]);
63+
}
64+
return $result;
65+
} catch (Exception $e) {
66+
error_log($e);
67+
return [];
68+
}
69+
}
70+
}
File renamed without changes.

src/VIAF/JSKOS/Service.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

tests/ServiceTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<?php
22

3-
namespace VIAF\JSKOS;
3+
namespace JSKOS\Service;
44

55
use JSKOS\ConceptScheme;
6-
use Helmich\JsonAssert\JsonAssertions;
76

8-
class VIAFServiceTest extends \PHPUnit\Framework\TestCase
7+
class VIAFTest extends \PHPUnit\Framework\TestCase
98
{
109
public function testExamples()
1110
{
12-
$service = new Service();
11+
$service = new VIAF();
1312

1413
$uri = "http://viaf.org/viaf/87772061";
15-
$jskos = $service->query(['uri'=>$uri]);
14+
$result = $service->query(['uri'=>$uri]);
1615

17-
$this->assertEquals($jskos->uri, $uri);
18-
$this->assertEquals($jskos->type[0], 'http://schema.org/Person');
16+
$this->assertEquals($result[0]->uri, $uri);
17+
$this->assertTrue($result[0]->type->contains('http://schema.org/Person'));
1918
}
2019
}

0 commit comments

Comments
 (0)