Skip to content

Commit

Permalink
Merge pull request #4 from rsinger/null_examples_and_languages
Browse files Browse the repository at this point in the history
Bug fixes around language support and works not found
  • Loading branch information
rsinger authored Sep 19, 2017
2 parents e42daf2 + e5f384d commit b4b744a
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,24 @@ protected function hydrateProperty($name)
$values[] = $this->hydratePropertyValue($value);
}
}

if (!empty($langVals)) {
foreach ($languages as $language) {
if (isset($langVals[$language])) {
$values = array_merge($values, $langVals[$language]);
break;
}
}
if (empty($values)) {
foreach ($langVals as $language => $vals) {
if (!empty($vals)) {
$values = $vals;
break;
}
}
}
}

if (count($values) === 1) {
return $values[0];
}
Expand Down
7 changes: 4 additions & 3 deletions src/Manifestation.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ public function getExampleOfWork()
{
if (!isset($this->work)) {
$workId = $this->getWorkId();
$this->work = $this->createWork();
$this->work->findById($workId);
$this->work->addExample($this);
$work = $this->createWork();
$work->findById($workId);
$work->addExample($this);
$this->work = $work;
}
return $this->work;
}
Expand Down
29 changes: 24 additions & 5 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Promise;
use WorldCatLD\exceptions\ResourceNotFoundException;
use GuzzleHttp\Pool;

/**
* Class Resource
Expand Down Expand Up @@ -75,11 +76,29 @@ protected function getRedirectLocation($url)
private function fetchConcurrentResources(array $ids)
{
$client = $this->getHttpClient();
$promises = [];
foreach ($ids as $id) {
$promises[$id] = $client->getAsync($id . '.jsonld', ['Accept' => 'application/ld+json']);
}
return Promise\settle($promises)->wait();

$requests = function () use ($client, $ids) {
foreach ($ids as $id) {
yield function () use ($client, $id) {
return $client->getAsync($id . '.jsonld', ['Accept' => 'application/ld+json']);
};
}
};

$results = [];

$pool = new Pool(
$client,
$requests(),
[
'concurrency' => 5,
'fulfilled' => function ($response, $index) use ($ids, &$results) {
$results[$ids[$index]] = ['state' => 'fulfilled', 'value' => $response];
}
]
);
$pool->promise()->wait(true);
return $results;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
require_once __DIR__ . '/../vendor/autoload.php';

\VCR\VCR::turnOn();
\VCR\VCR::configure()->setMode('once');
\VCR\VCR::configure()->setMode('new_episodes');
47 changes: 47 additions & 0 deletions tests/fixtures/defaultLanguageNotAvailableForProperty
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

-
request:
method: GET
url: 'http://www.worldcat.org/oclc/54014437.jsonld'
headers:
Host: www.worldcat.org
Accept-Encoding: null
User-Agent: worldcat-linkeddata-php/0.1
Accept: null
response:
status:
http_version: '1.1'
code: '307'
message: 'Temporary Redirect'
headers:
Date: 'Tue, 19 Sep 2017 16:29:44 GMT'
Server: Apache
Location: 'http://experiment.worldcat.org/oclc/54014437.jsonld'
Content-Length: '0'
P3P: 'CP="OCLC"'
Content-Type: text/plain
-
request:
method: GET
url: 'http://experiment.worldcat.org/oclc/54014437.jsonld'
headers:
Host: experiment.worldcat.org
Accept-Encoding: null
User-Agent: worldcat-linkeddata-php/0.1
Accept: null
response:
status:
http_version: '1.1'
code: '200'
message: OK
headers:
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: '*'
Pragma: no-cache
Cache-Control: 'no-cache, no-store, max-age=0'
Expires: 'Thu, 01 Jan 1970 00:00:00 GMT'
Content-Type: application/ld+json;charset=UTF-8
Content-Language: en-US
Transfer-Encoding: chunked
Date: 'Tue, 19 Sep 2017 16:29:44 GMT'
body: "{\n \"@graph\" : [ {\n \"@id\" : \"http://dewey.info/class/792/e21/\",\n \"@type\" : \"schema:Intangible\"\n }, {\n \"@id\" : \"http://experiment.worldcat.org/entity/work/data/183829#Agent/lian_jing_chu_ban_shi_ye_gu_fen_you_xian_gong_si\",\n \"@type\" : \"bgn:Agent\",\n \"name\" : \"Lian jing chu ban shi ye gu fen you xian gong si\"\n }, {\n \"@id\" : \"http://experiment.worldcat.org/entity/work/data/183829#Person/liu_li\",\n \"@type\" : \"schema:Person\",\n \"familyName\" : \"Liu\",\n \"givenName\" : \"Li\",\n \"name\" : [ {\n \"@language\" : \"en\",\n \"@value\" : \"Li Liu\"\n }, {\n \"@language\" : \"zh\",\n \"@value\" : \"劉俐.\"\n } ]\n }, {\n \"@id\" : \"http://experiment.worldcat.org/entity/work/data/183829#Place/taibei_shi\",\n \"@type\" : \"schema:Place\",\n \"name\" : \"Taibei Shi\"\n }, {\n \"@id\" : \"http://experiment.worldcat.org/entity/work/data/183829#Series/lian_jing_jing_dian\",\n \"@type\" : \"bgn:PublicationSeries\",\n \"hasPart\" : \"http://www.worldcat.org/oclc/54014437\",\n \"name\" : {\n \"@language\" : \"zh\",\n \"@value\" : \"聯經經典.\"\n },\n \"label\" : \"Lian jing jing dian.\"\n }, {\n \"@id\" : \"http://id.loc.gov/vocabulary/countries/ch\",\n \"@type\" : \"schema:Place\",\n \"identifier\" : \"ch\"\n }, {\n \"@id\" : \"http://id.worldcat.org/fast/1149217\",\n \"@type\" : \"schema:Intangible\",\n \"name\" : \"Theater\"\n }, {\n \"@id\" : \"http://viaf.org/viaf/71386527\",\n \"@type\" : \"schema:Person\",\n \"birthDate\" : \"1896\",\n \"deathDate\" : \"1948\",\n \"familyName\" : \"Artaud\",\n \"givenName\" : \"Antonin\",\n \"name\" : \"Antonin Artaud\"\n }, {\n \"@id\" : \"http://worldcat.org/entity/work/id/183829\",\n \"name\" : \"Théâtre et son double.\"\n }, {\n \"@id\" : \"http://worldcat.org/isbn/9789570825466\",\n \"@type\" : \"schema:ProductModel\",\n \"isbn\" : [ \"9789570825466\", \"9570825464\" ]\n }, {\n \"@id\" : \"http://www.worldcat.org/oclc/54014437\",\n \"@type\" : [ \"schema:CreativeWork\", \"schema:Book\" ],\n \"translationOfWork\" : \"http://www.worldcat.org/title/-/oclc/54014437#CreativeWork/unidentifiedOriginalWork\",\n \"oclcnum\" : \"54014437\",\n \"placeOfPublication\" : [ \"http://id.loc.gov/vocabulary/countries/ch\", \"http://experiment.worldcat.org/entity/work/data/183829#Place/taibei_shi\" ],\n \"about\" : [ \"http://dewey.info/class/792/e21/\", \"http://id.worldcat.org/fast/1149217\" ],\n \"bookEdition\" : \"Chu ban.\",\n \"bookFormat\" : \"bgn:PrintBook\",\n \"contributor\" : \"http://experiment.worldcat.org/entity/work/data/183829#Person/liu_li\",\n \"creator\" : \"http://viaf.org/viaf/71386527\",\n \"datePublished\" : [ \"2003\", \"2002\" ],\n \"exampleOfWork\" : \"http://worldcat.org/entity/work/id/183829\",\n \"inLanguage\" : \"zh\",\n \"isPartOf\" : \"http://experiment.worldcat.org/entity/work/data/183829#Series/lian_jing_jing_dian\",\n \"name\" : [ {\n \"@language\" : \"zh\",\n \"@value\" : \"阿鐸戲劇文集\"\n }, {\n \"@language\" : \"zh\",\n \"@value\" : \"劇場及其複象 : 阿鐸戲劇文集 = Le théâtre et son double\"\n } ],\n \"productID\" : \"54014437\",\n \"publication\" : \"http://www.worldcat.org/title/-/oclc/54014437#PublicationEvent/880_04taibei_shi_lian_jing_chu_ban_shi_ye_gu_fen_you_xian_gong_si_2003\",\n \"publisher\" : \"http://experiment.worldcat.org/entity/work/data/183829#Agent/lian_jing_chu_ban_shi_ye_gu_fen_you_xian_gong_si\",\n \"workExample\" : \"http://worldcat.org/isbn/9789570825466\",\n \"label\" : [ \"Aduo xi ju wen ji\", \"Ju chang ji qi fu xiang : Aduo xi ju wen ji = Le théâtre et son double\" ],\n \"describedby\" : \"http://www.worldcat.org/title/-/oclc/54014437\"\n }, {\n \"@id\" : \"http://www.worldcat.org/title/-/oclc/54014437\",\n \"@type\" : [ \"genont:ContentTypeGenericResource\", \"genont:InformationResource\" ],\n \"inDataset\" : \"http://purl.oclc.org/dataset/WorldCat\",\n \"about\" : \"http://www.worldcat.org/oclc/54014437\",\n \"dateModified\" : \"2017-09-03\"\n }, {\n \"@id\" : \"http://www.worldcat.org/title/-/oclc/54014437#CreativeWork/unidentifiedOriginalWork\",\n \"@type\" : \"schema:CreativeWork\",\n \"inLanguage\" : \"fr\",\n \"name\" : \"Théâtre et son double.\"\n }, {\n \"@id\" : \"http://www.worldcat.org/title/-/oclc/54014437#PublicationEvent/880_04taibei_shi_lian_jing_chu_ban_shi_ye_gu_fen_you_xian_gong_si_2003\",\n \"@type\" : \"schema:PublicationEvent\",\n \"location\" : \"http://experiment.worldcat.org/entity/work/data/183829#Place/taibei_shi\",\n \"organizer\" : \"http://experiment.worldcat.org/entity/work/data/183829#Agent/lian_jing_chu_ban_shi_ye_gu_fen_you_xian_gong_si\",\n \"startDate\" : \"2003\"\n } ],\n \"@context\" : {\n \"name\" : \"http://schema.org/name\",\n \"familyName\" : \"http://schema.org/familyName\",\n \"givenName\" : \"http://schema.org/givenName\",\n \"isbn\" : \"http://schema.org/isbn\",\n \"hasPart\" : {\n \"@id\" : \"http://schema.org/hasPart\",\n \"@type\" : \"@id\"\n },\n \"label\" : \"http://www.w3.org/2000/01/rdf-schema#label\",\n \"identifier\" : \"http://purl.org/dc/terms/identifier\",\n \"inLanguage\" : \"http://schema.org/inLanguage\",\n \"bookEdition\" : \"http://schema.org/bookEdition\",\n \"placeOfPublication\" : {\n \"@id\" : \"http://purl.org/library/placeOfPublication\",\n \"@type\" : \"@id\"\n },\n \"datePublished\" : \"http://schema.org/datePublished\",\n \"creator\" : {\n \"@id\" : \"http://schema.org/creator\",\n \"@type\" : \"@id\"\n },\n \"isPartOf\" : {\n \"@id\" : \"http://schema.org/isPartOf\",\n \"@type\" : \"@id\"\n },\n \"exampleOfWork\" : {\n \"@id\" : \"http://schema.org/exampleOfWork\",\n \"@type\" : \"@id\"\n },\n \"contributor\" : {\n \"@id\" : \"http://schema.org/contributor\",\n \"@type\" : \"@id\"\n },\n \"bookFormat\" : {\n \"@id\" : \"http://schema.org/bookFormat\",\n \"@type\" : \"@id\"\n },\n \"publisher\" : {\n \"@id\" : \"http://schema.org/publisher\",\n \"@type\" : \"@id\"\n },\n \"publication\" : {\n \"@id\" : \"http://schema.org/publication\",\n \"@type\" : \"@id\"\n },\n \"translationOfWork\" : {\n \"@id\" : \"http://bibliograph.net/translationOfWork\",\n \"@type\" : \"@id\"\n },\n \"about\" : {\n \"@id\" : \"http://schema.org/about\",\n \"@type\" : \"@id\"\n },\n \"oclcnum\" : \"http://purl.org/library/oclcnum\",\n \"describedby\" : {\n \"@id\" : \"http://www.w3.org/2007/05/powder-s#describedby\",\n \"@type\" : \"@id\"\n },\n \"productID\" : \"http://schema.org/productID\",\n \"workExample\" : {\n \"@id\" : \"http://schema.org/workExample\",\n \"@type\" : \"@id\"\n },\n \"birthDate\" : \"http://schema.org/birthDate\",\n \"deathDate\" : \"http://schema.org/deathDate\",\n \"location\" : {\n \"@id\" : \"http://schema.org/location\",\n \"@type\" : \"@id\"\n },\n \"organizer\" : {\n \"@id\" : \"http://schema.org/organizer\",\n \"@type\" : \"@id\"\n },\n \"startDate\" : \"http://schema.org/startDate\",\n \"dateModified\" : \"http://schema.org/dateModified\",\n \"inDataset\" : {\n \"@id\" : \"http://rdfs.org/ns/void#inDataset\",\n \"@type\" : \"@id\"\n },\n \"schema\" : \"http://schema.org/\",\n \"rdfs\" : \"http://www.w3.org/2000/01/rdf-schema#\",\n \"genont\" : \"http://www.w3.org/2006/gen/ont#\",\n \"wdrs\" : \"http://www.w3.org/2007/05/powder-s#\",\n \"xsd\" : \"http://www.w3.org/2001/XMLSchema#\",\n \"library\" : \"http://purl.org/library/\",\n \"void\" : \"http://rdfs.org/ns/void#\",\n \"rdf\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n \"bgn\" : \"http://bibliograph.net/\",\n \"pto\" : \"http://www.productontology.org/id/\",\n \"dcterms\" : \"http://purl.org/dc/terms/\"\n }\n}"
Loading

0 comments on commit b4b744a

Please sign in to comment.