-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve Wikidata URIs via LDF endpoint and LC URIs using HEAD requests #921
Conversation
Issues
======
+ Solved 5
- Added 10
Complexity increasing per file
==============================
- model/ConceptPropertyValue.php 1
- model/resolver/Resolver.php 3
- model/resolver/LDFResource.php 2
- model/resolver/LOCResource.php 4
- model/resolver/LinkedDataResource.php 2
See the complete overview on Codacy |
$res = new LOCResource($uri); | ||
} elseif ($this->startsWith('http://www.wikidata.org/entity/', $uri)) { | ||
$res = new LDFResource($uri, 'https://query.wikidata.org/bigdata/ldf'); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model/resolver/LDFResource.php
Outdated
// change the timeout setting for external requests | ||
$httpclient = EasyRdf\Http::getDefaultHttpClient(); | ||
$httpclient->setConfig(array('timeout' => $timeout)); | ||
EasyRdf\Http::setDefaultHttpClient($httpclient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 1. Unregister the legacy RDF/JSON parser, we don't want to use it | ||
EasyRdf\Format::unregister('json'); | ||
// 2. Add "application/json" as a possible MIME type for the JSON-LD format | ||
$jsonld = EasyRdf\Format::getFormat('jsonld'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// change the timeout setting for external requests | ||
$httpclient = EasyRdf\Http::getDefaultHttpClient(); | ||
$httpclient->setConfig(array('timeout' => $timeout)); | ||
EasyRdf\Http::setDefaultHttpClient($httpclient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
try { | ||
// change the timeout setting for external requests | ||
$httpclient = EasyRdf\Http::getDefaultHttpClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model/resolver/LDFResource.php
Outdated
public function resolve(int $timeout) : ?EasyRdf\Resource { | ||
try { | ||
// change the timeout setting for external requests | ||
$httpclient = EasyRdf\Http::getDefaultHttpClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$httpclient->setConfig(array('timeout' => $timeout)); | ||
EasyRdf\Http::setDefaultHttpClient($httpclient); | ||
|
||
$graph = EasyRdf\Graph::newAndLoad(EasyRdf\Utils::removeFragmentFromUri($this->uri)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
if ($this->isExternal()) { | ||
return $this->vocab; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function resolve(int $timeout) : ?EasyRdf\Resource { | ||
// prevent parsing errors for sources which return invalid JSON (see #447) | ||
// 1. Unregister the legacy RDF/JSON parser, we don't want to use it | ||
EasyRdf\Format::unregister('json'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model/resolver/LOCResource.php
Outdated
'user_agent' => 'Skosmos', | ||
'timeout' => $timeout)); | ||
$context = stream_context_create($opts); | ||
$fd = fopen($this->uri, 'rb', false, $context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## master #921 +/- ##
============================================
- Coverage 65.76% 59.69% -6.08%
- Complexity 1469 1488 +19
============================================
Files 27 32 +5
Lines 3637 4037 +400
============================================
+ Hits 2392 2410 +18
- Misses 1245 1627 +382
Continue to review full report at Codecov.
|
…andling property values that are outside the current vocabulary, but in another vocabulary known to Skosmos.
…relying on label heuristic
264ce87
to
63932b8
Compare
Kudos, SonarCloud Quality Gate passed!
|
fix some test coverage annotations after PR #921
This PR refactors and modularizes the lookup/resolution mechanism for remote URIs, that is, URIs that Skosmos knows nothing about.
There is a new Resolver class which knows which resolution mechanism to use for a particular URI. Wikidata URIs are looked up via the LDF endpoint (fixes #912); HEAD requests are used for LCSH and other LC vocabularies (fixes #915); and for everything else, a generic Linked Data mechanism (just retrieve the URI and ask for RDF) is used, as before.
Unfortunately, it turns out that the Wikidata LDF endpoint cannot currently handle language tags. I've reported this to the Wikidata list. If the issue isn't fixed soon, then that mechanism has to be disabled for now - perhaps the Wikidata SPARQL endpoint could be used instead, although it may be less reliable than the LDF endpoint.
I'm keeping this just as a draft PR for now, until there is more clarity on the LDF endpoint issue. I just want to see the automated QA reports.