lanthaler / jsonld Goto Github PK
View Code? Open in Web Editor NEWJSON-LD processor for PHP
License: MIT License
JSON-LD processor for PHP
License: MIT License
I noticed that when you send a boolen it will be returned as a string. For example true ends up as "true".
{
"@context":{
"active":"http://localhost/app_dev.php/hydra/vocab#SomeDTO/active"
},
"@type":"http://localhost/app_dev.php/hydra/vocab#SomeDTO",
"active":true
}
I tried to add a unit test for it but the unit testing failed. With
PHP Warning: file_get_contents(/../vendor/ml/json-ld/ML/JsonLD/Test/tests/expand-manifest.jsonld): failed to open stream: No such file or directory in /../vendor/ml/json-ld/ML/JsonLD/Test/TestManifestIterator.php on line 44
Which is correct because there is no test directory??
How should the unit test be started so that I can add a unit test and try to fix this for boolean type?
See json-ld/json-ld.org#122 for details
{
"@context": {
"@vocab": "http://example.org/vocab#",
"date": { "@id": null }
},
"@id": "example1",
"date": "test"
}
date
should not expand to http://example.org/vocab#date
in this case
UTF8 characters are escaped at the moment. They should be represented as UTF8 chars in the result instead
Currently, a lot of tests fail. Investigate the reason and fix it or file a bug for HHVM.
The README gives the example
$quads = JsonLD::toQuads('document.jsonld');
but toQuads
is not implemented.
So, e.g. in sample-serialized-document.jsonld
the following node shouldn't be there:
{
"@id": "http://example.com/t1"
}
This feature should also be accessible from a JSON-LD frame and not just via a helper method or flag. See the referenced PR request below for such a use case.
Working with this example jsonld doc
{
"@id": "http://example.info/node1",
"http://example.info/testproperty1":
[
{"@value": "value1", "@type": "http://www.w3.org/2001/XMLSchema#string"},
{"@value": "value2", "@type": "http://www.w3.org/2001/XMLSchema#string"},
{"@value": "value3"}
]
}
when using NodeInterface::getProperties() only the last TypedValue node will be returned.
In the case of the upper document I get the nodes with value2 and value3. When I give the value3 node a type, only this node will be returned.
LanguageTagged nodes are fine.
For example the following
{
"@context": {
"title": { "@id": [
"http://purl.org/dc/terms/title",
"http://schema.org/name",
"http://www.w3.org/2000/01/rdf-schema#label"
] }
},
"@id": "http://example.com/book",
"title": "The Count of Monte Cristo"
}
should be expanded to
[ {
"@id": "http://example.com/book",
"http://purl.org/dc/terms/title": [
{ "@value": "The Count of Monte Cristo" } ],
"http://schema.org/name": [
{ "@value": "The Count of Monte Cristo" } ],
"http://www.w3.org/2000/01/rdf-schema#label": [
{ "@value": "The Count of Monte Cristo" } ]
} ]
Keyword aliases are currently just supported in expansion
@context
can't be aliased.
{
"@context": {
"@vocab": "http://xmlns.com/foaf/0.1/",
"homepage": {
"@type": "@id"
}
},
"name": "Markus Lanthaler",
"homepage": "http://www.markus-lanthaler.com/"
}
... to be more in line with the official error handling mechansim. This doesn't mean that callbacks should be used but that the error constants should be the same (and they should be thrown under the same circumstances).
{
"@context": { "@vocab": "hydra:", "targetUrl": { "@reverse": "operations", "@type": "@id" } },
"@type": "Event",
"action": {
"@type": "RsvpAction",
"targetUrl": "https://events-organizer.com/rsvp?eventId=123",
"method": "POST",
"expects": {
"supportedProperties": {
"property": "rsvpStatus",
"required": true
}
}
}
}
The blank nodes are not labeled properly.
While playing with the Hydra Console I came across this issue, which looks like a bug in your JSON-LD processor:
PHP Fatal error: Uncaught exception 'ML\JsonLD\Exception\SyntaxException'
with message 'Invalid value for @language detected (must be a string) (near
{"@language":{"__iri":"@language","__value":"ja"},"@value":
{"__iri":"@value","__value":"リズム天国ゴールド"}}).'
The original document does have just a string "ja" as value for @language, so it seems the processor is complaining about an expansion it performed itself.
I've uploaded a testcase which shows the problem using your HydraConsole proxy:
Currently this triggers a SyntaxException:
Invalid value for
@id
detected (must be a string) (near {}).
See http://json-ld.org/spec/latest/json-ld-api/#jsonldoptions for details. This also means that the base IRI parameter is move into the generic options parameter.
... which means the documents base URL has to be updated.
See RFC3986
Currently file_get_contents
is used to retrieve remote contexts and documents. This isn't really flexible and should sooner or later be replaced with a more sophisticated library.
Keep an eye on the PHP FIG Proposal for a HTTP Client interface.
Add an option to all operations not automatically retrieve remote contexts
The PSR links in the README are broken since the document names have been changed.
It should be possible to work directly with the data contained in a document. Some functionality that should be supported:
// load a document
$doc = Document::load('document.jsonld');
// get the default graph
$graph = $doc->getGraph();
// get all nodes in the document
$nodes = $graph->getNodes();
// retrieve a node by ID
$node = $graph->getNode('http://example.com/node1');
// get a property
$node->getProperty('http://example.com/vocab/name');
// add a new blank node to the document
$newNode = $graph->createNode();
// link the new blank node to the existing node
$node->addPropertyValue('http://example.com/vocab/link', $newNode);
// even reverse properties are supported; this returns $newNode
$node->getReverseProperty('http://example.com/vocab/link');
At a later point, it should also be possible to query for nodes or properties.
In production settings, restrictions re. the installed PHP version are quite frequent. Therefore, it would be great to see the required PHP (sub-) version on the readme page.
An external context A might include an external context B which in turn again includes context A. This should be detected and trigger an error.
Change coding style to PSR-2
{
"@context": {
"label": {
"@id": "http://example.com/label",
"@container": "@language"
}
},
"@id": "http://buckingham.uk/queenie",
"label": {
"en": "The Queen",
"de": "Die Koenigin"
}
}
Should expanded to:
[
{
"@id": "http://buckingham.uk/queenie",
"http://example.com/label": [
{ "@value": "The Queen", "@language": "en" },
{ "@value": "Die Königin", "@language": "de" }
]
}
]
It is still being discussed if non-literal values have to be round-tripable and how: json-ld/json-ld.org#159
Since terms can now be explicitly mapped to null, it is possible that values in @type
expand to null
. These should be removed in expansion:
{
"@context": {
"@vocab": "http://xmlns.com/foaf/0.1/",
"Person": { "@id": null }
},
"@id": "http://me.markus-lanthaler.com/",
"name": "Markus Lanthaler",
"@type": "Person",
"Person": "should be removed as well"
}
The parse() function of IRI.php works fine for me on a Centos 6/PHP 5.3.3 installation. It fails however on Centos 5 (with rpm package php53/PHP 5.3.3 installed).
I could track it down to to following lines of code (first and last line added for demonstration):
$iri = 'http://www.w3.org/2004/02/skos/core#hiddenLabel';
// Parse IRI by using the regular expression as specified by
// http://tools.ietf.org/html/rfc3986#appendix-B
$regex = '|^((?P<scheme>[^:/?#]+):)?' .
'((?P<doubleslash>//)(?P<authority>[^/?#]*))?(?P<path>[^?#]*)' .
'((?<querydef>\?)(?P<query>[^#]*))?(#(?P<fragment>.*))?|';
preg_match($regex, $iri, $match);
print $match['scheme'] . "\n";
On Centos 6, "http" is printed.
On Centos 5, I get the message:
PHP Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 89 in [...]temp.php on line 9
without any other output.
Perhaps I'm missing some unknown dependency - help much appreciated.
Cheers, Joachim
Since the error handling should be aligned more closely to the official API (see #26), some automatic recovery features should either be removed or be hidden behind a lax
flag.
The following code snippet is one of the examples that should be revisited:
if (('@value' === $keyword) || ('@language' === $keyword) || ('@annotation' === $keyword)) {
if (false === $frame) {
if (is_array($value) && (1 === count($value))) {
$value = $value[0];
}
Using this example document
{
"@id": "http://example.info/node1",
"http://example.info/testproperty1":
[
{"@value": "value1", "@type": "http://www.w3.org/2001/XMLSchema#string"},
{"@value": "value3"}
],
"http://example.info/testproperty2": {"@value": "value2", "@type": "http://www.w3.org/2001/XMLSchema#string"},
"http://example.info/testproperty3": {"@id": "http://example.info/node2"}
}
when calling GraphInterface::getNodes(), I would expect 6 nodes (3 named nodes, 2 typed value nodes, 1 value node). But I only get 2 nodes (http://example.info/node1 and http://example.info/node2) .
The parse function of IRI.php works fine for me on a Centos 6/PHP 5.3.3 installation. It fails however on Centos 5 (with rpm package php53 (PHP 5.3.3) installed).
I could track it down to to following lines of code:
//
[^:/?#]+):)?' . '((?P//)(?P[^/?#]*))?(?P[^?#]*)' . '((?\?)(?P[^#]*))?(#(?P.*))?|'; preg_match($regex, $iri, $match); print $match['scheme'] . "\n"; ``` On Centos 6, "http" is printed. On Centos 5, I get the message PHP Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 89 in /opt/thes/var/stw-ws/temp.php on line 9 without any other output.Using the playground for the JsonLD processor, @base: null
causes some problems when @id
is set to the empty string. See: http://tinyurl.com/npjymy9
If you look at the compacted tab, the @id should be changed to ./
, and if you look at the flatten or toRDF tabs, you get an error.
This is related to PHP's problems with empty string keys, but I'm sure it's fixable as php-json-ld produces the same (and correct) output as jsonld.js with the above input.
Currently, createNode()
creates new blank node each time it gets _:something
. The problem is, that, sometimes, it is desirable to reference the same blank node several times (node itself, then some other nodes, which point to it)
The solution is, to keep some kind of cache for blank-nodes, just as there is a cache for "regular" nodes
If "@type": "@vocab"
is specified for a term in the active context, then processing for the value associated with the term attempts to resolve it as an IRI - first processing it as a term, then a CURIE, then an absolute IRI, then against the active @vocab
(if present), then a document-relative IRI.
The value space of values coerced to @id
is: compact IRI, absolute IRI, relative IRI.
[http://json-ld.org/minutes/2013-02-12/#resolution-3]
Currently the triples are generated directly from expanded output.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.