From 4ce962860cbd4e7c25168fe398bd73fc3f865fca Mon Sep 17 00:00:00 2001
From: Gregg Kellogg Compacts the given input using the
- context according to the steps in the
- Compaction algorithm:The JsonLdProcessor Interface
false
.
- @context
member, set
- context to that member's value, otherwise to context.@context
member,
+ set context to that member's value,
+ otherwise to context.null
.null
.null
as property,
- expanded input as element, and if passed, the
- compactArrays
+ expanded input as element,
+ and if passed, the compactArrays
and ordered
flags in options.input
;
- it can be specified by using a dictionary, an
- IRI, or an array consisting of
- dictionaries and IRIs.Expands the given input according to - the steps in the Expansion algorithm:
+Expands the given input + according to the steps in the Expansion algorithm:
application/json
,
- nor application/ld+json
, nor any other media type using a
- +json
suffix as defined in [[RFC6839]], reject the promise passing an
- loading document failed
- error.null
. If set, the
- base option from options overrides the base IRI.@context
member, pass that member's value instead.http://www.w3.org/ns/json-ld#context
link relation
- and a content type of application/json
or any media type
- with a +json
suffix as defined in [[RFC6839]] except
- application/ld+json
, update the active context using the
- Context Processing algorithm, passing the
- context referenced in the HTTP Link Header as local context. The
- HTTP Link Header is ignored for documents served as application/ld+json
If
- multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
- link relation are found, the promise is rejected with a JsonLdError whose code is set to
- multiple context link headers
+ text/html
,
+ application/json
,
+ application/ld+json
,
+ nor any other media type using a
+ +json
suffix as defined in [[RFC6839]],
+ reject the promise passing an loading document failed error.null
.
+ If set, the base option from options overrides the base IRI.@context
member,
+ pass that member's value instead.http://www.w3.org/ns/json-ld#context
link relation
+ and a content type of application/json
+ or any media type with a +json
suffix as defined in [[RFC6839]]
+ except application/ld+json
,
+ update the active context using the Context Processing algorithm,
+ passing the context referenced in the HTTP Link Header as local context.
+ The HTTP Link Header is ignored for documents served as application/ld+json
.
+ If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
link relation are found,
+ the promise is rejected with a JsonLdError whose code is set to multiple context link headers
and processing is terminated.Flattens the given input and - compacts it using the passed context +
Flattens the given input + and compacts it using the passed context according to the steps in the Flattening algorithm:
false
.@context
member, set
- context to that member's value, otherwise to context.@context
member,
+ set context to that member's value,
+ otherwise to context.null
.null
.
null
is passed, the result will not be compacted
- but kept in expanded form.null
is passed,
+ the result will not be compacted but kept in expanded form.Transforms the given input into - a JSON-LD document in expanded form +
Transforms the given input + into a JSON-LD document in expanded form according to the steps in the Serialize RDF as JSON-LD Algorithm:
-This interface does not define a means of creating - an RdfDataset from an arbitrary input, other than the - toRdf method.
+This interface does not define a means of creating an RdfDataset + from an arbitrary input, other than the toRdf method.
The JsonLdDictionary is the definition of a dictionary - used to contain arbitrary dictionary members which are the result of - parsing a JSON Object. + used to contain arbitrary dictionary members + which are the result of parsing a JSON Object.
-The JsonLdInput type is used to refer to an input value that - that may be a dictionary, an array of dictionaries or a string representing an - IRI which an be dereferenced to retrieve a valid JSON document.
+The JsonLdInput type is used to refer to an input value + that that may be a dictionary, + an array of dictionaries , + or a string representing an IRI + which can be dereferenced to retrieve a valid JSON document.
-The JsonLdContext type is used to refer to a value that - that may be a dictionary, a string representing an - IRI, or an array of dictionaries - and strings.
+The JsonLdContext type is used to refer to a value + that may be a dictionary, + a string representing an IRI, + or an array of dictionaries and strings.
The RdfDataset interface describes operations on an RDF dataset used by the fromRdf and toRdf methods in the JsonLdProcessor interface. The interface may be used for constructing a new RDF dataset, which has a default graph accessible via the defaultGraph attribute.
+The RdfDataset interface describes operations on an RDF dataset + used by the fromRdf + and toRdf methods + in the JsonLdProcessor interface. + The interface may be used for constructing a new RDF dataset, + which has a default graph accessible via the defaultGraph attribute.
[Constructor] @@ -5011,7 +5014,8 @@RDF Dataset Interfaces
Adds an RdfGraph and its associated graph name to the RdfDataset. Used by the Deserialize JSON-LD to RDF Algorithm.
+Adds an RdfGraph and its associated graph name to the RdfDataset. + Used by the Deserialize JSON-LD to RDF Algorithm.
null
(for the default
- graph), an IRI or blank node identifier and graph an
- RdfGraph instance.null
+ (for the default graph),
+ an IRI,
+ or blank node identifier
+ and graph an RdfGraph instance.
- The RdfGraph interface describes operations on an RDF graph used by the fromRdf and toRdf methods in the JsonLdProcessor interface. The interface may be used for constructing a new RDF graph, which is composed of zero or more RdfTriple instances.
+The RdfGraph interface describes operations on an RDF graph used by the fromRdf + and toRdf methods + in the JsonLdProcessor interface. + The interface may be used for constructing a new RDF graph, + which is composed of zero or more RdfTriple instances.
[Constructor] @@ -5043,7 +5053,8 @@RDF Dataset Interfaces
Adds an RdfTriple to the RdfGraph. Used by the Deserialize JSON-LD to RDF Algorithm.
+Adds an RdfTriple to the RdfGraph. + Used by the Deserialize JSON-LD to RDF Algorithm.
The RdfTriple interface describes an RDF Triple.
@@ -5070,15 +5081,18 @@The RdfLiteral interface describes an RDF Literal.
@@ -5097,10 +5111,11 @@rdf:langString
, language MUST be specified.rdf:langString
,
+ language MUST be specified.
rdf:langString
rdf:langString
.true
, the JSON-LD processor replaces arrays with just
- one element with that element during compaction. If set to false
,
+ true
, the JSON-LD processor replaces arrays
+ with just one element with that element during compaction.
+ If set to false
,
all arrays will remain arrays even if they have just one element.
true
, the JSON-LD processor may emit blank nodes for
- triple predicates, otherwise they will be omitted.
+ true
, the JSON-LD processor may emit
+ blank nodes for triple predicates,
+ otherwise they will be omitted.
Generalized RDF Datasets
are defined in [[RDF11-CONCEPTS]].
json-ld-1.0
or json-ld-1.1
, the
- implementation must produce exactly the same results as the algorithms
- defined in this specification.
- If set to another value, the JSON-LD processor is allowed to extend
- or modify the algorithms defined in this specification to enable
- application-specific optimizations. The definition of such
- optimizations is beyond the scope of this specification and thus
- not defined. Consequently, different implementations may implement
- different optimizations. Developers must not define modes beginning
- with json-ld
as they are reserved for future versions
- of this specification.json-ld-1.0
or json-ld-1.1
,
+ the implementation must produce exactly the same results as the
+ algorithms defined in this specification.
+ If set to another value,
+ the JSON-LD processor is allowed to extend or modify the algorithms defined in this specification
+ to enable application-specific optimizations.
+ The definition of such optimizations is beyond the scope of this specification
+ and thus not defined.
+ Consequently, different implementations may implement different optimizations.
+ Developers must not define modes beginning with json-ld
+ as they are reserved for future versions of this specification.
rdf:type
properties to be kept as IRIs in the output, rather than use @type
.true
, certain algorithm
- processing steps where indicated are ordered lexicographically.
- If false
, order
- is not considered in processing.true
,
+ certain algorithm processing steps where indicated are ordered lexicographically.
+ If false
, order is not considered in processing.Users of an API implementation can utilize a callback to control how remote - documents and contexts are retrieved. This section details the parameters of - that callback and the data structure used to return the retrieved context.
+Users of an API implementation can utilize a callback to control how + remote documents and contexts are retrieved. + This section details the parameters of that callback + and the data structure used to return the retrieved context.
All errors result in the Promise being rejected with - a JsonLdError whose code is set to - loading document failed +
All errors result in the Promise being rejected with a JsonLdError + whose code is set to loading document failed or multiple context link headers as described in the next section.
http://www.w3.org/ns/json-ld#context
link relation in the
- response. If the response's content type is application/ld+json
,
- the HTTP Link Header is ignored. If multiple HTTP Link Headers using
- the http://www.w3.org/ns/json-ld#context
link relation are found,
- the Promise of the LoadDocumentCallback is rejected with
- a JsonLdError whose code is set to
- multiple context link headers.http://www.w3.org/ns/json-ld#context
link relation
+ in the response.
+ If the response's content type is application/ld+json
,
+ the HTTP Link Header is ignored.
+ If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
link relation are found,
+ the Promise of the LoadDocumentCallback is rejected
+ with a JsonLdError whose code is set to multiple context link headers.This section describes the datatype definitions used within the - JSON-LD API for error handling.
+This section describes the datatype definitions + used within the JSON-LD API for error handling.
The JsonLdErrorCode represents the collection of valid JSON-LD error - codes.
+The JsonLdErrorCode represents the collection of valid JSON-LD error codes.
The algorithm extracts the text content a
+ JSON-LD script element into a dictionary or array of dictionaries.
+ A JSON-LD script element is a script element
+ within an HTML [[HTML52]] document with the with the type
attribute set to
+ application/ld+json
.
As a data block + may be inside a comment, and may be escaped, the algorithm extracts the JSON from any comment, + removes REVERSE SOLIDUS escapes, + and reverses HTML Character references. +
The algorithm takes a single required input variable: source, + the textContent of an HTML script element.
+For the purpose of this algorithm, the following tokens are defined in [[ABNF]]:
+ ++ space-character = %20 ; SPACE + / %09 ; CHARACTER TABULATION (tab) + / %0A ; LINE FEED (LF) + / %0C ; FORM FEED (FF) + / %0D ; CARRIAGE RETURN (CR) + comment-open = *space-character+ +"<!--"
*space-character + comment-close = *space-character"-->"
*space-character +
<\script
,
+ <\/script
,
+ <\!--
,
+ or --\>
+ in source using a case-insenstive match,
+ replace the sequence with the equivalent sequence excluding the REVERSE SOLIDUS (\
).Compacts the given input using the +
Compacts the given input using the context according to the steps in the Compaction algorithm:
false
.
+ with ordered set to false
,
+ and extractAllScripts defaulting to false
.
@context
member,
set context to that member's value,
otherwise to context.input
;
+ text/html
,
application/json
,
application/ld+json
,
@@ -4792,20 +4851,55 @@ http://www.w3.org/ns/json-ld#context
link relation
- and a content type of application/json
+ and a Content-Type of application/json
or any media type with a +json
suffix as defined in [[RFC6839]]
except application/ld+json
,
update the active context using the Context Processing algorithm,
passing the context referenced in the HTTP Link Header as local context.
- The HTTP Link Header is ignored for documents served as application/ld+json
.
+ The HTTP Link Header is ignored for documents served as application/ld+json
+ or text/html
.
If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
link relation are found,
the promise is rejected with a JsonLdError whose code is set to multiple context link headers
and processing is terminated.text/html
+ and the passed input is
+ a string representing the IRI of a remote document,
+ extract the content of the JSON-LD script element(s) into original input:
+ type
application/ld+json
,
+ reject promise passing an invalid script element error.
+ Set original input to the result of the Extract Script Content algorithm,
+ using source.false
,
+ locate the first JSON-LD script element in input,
+ and set source to its textContent, if found.
+ Set original input to the result of the Extract Script Content algorithm,
+ using source.
+ If no JSON-LD script element is found, set original input to a new empty array.false
.false
,
+ and extractAllScripts defaulting to true
.
@context
member,
set context to that member's value,
otherwise to context.false
,
+ and extractAllScripts defaulting to true
.
true
,
+ when extracting JSON-LD script elements from HTML,
+ unless a specific fragment identifier is targeted,
+ extracts all encountered JSON-LD script elements using an array form, if necessary.true
, the JSON-LD processor may emit
blank nodes for triple predicates,
@@ -5242,6 +5345,7 @@ http://www.w3.org/ns/json-ld#context
link relation
in the response.
- If the response's content type is application/ld+json
,
+ If the response's Content-Type is application/ld+json
,
the HTTP Link Header is ignored.
If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
link relation are found,
the Promise of the LoadDocumentCallback is rejected
@@ -5261,6 +5365,9 @@ type
attribute.text/html
as input,
+ extracting either a specifically targeted script element,
+ the first found JSON-LD script element,
+ or all JSON-LD script elements.For the 1.0 version of the specification, the editors would like to thank Mark Birbeck, who provided a great deal of
the initial push behind the JSON-LD work via his work on RDFj.
From 46302eb79ddb149fd1735bd47f080937735b767b Mon Sep 17 00:00:00 2001
From: Gregg Kellogg
+ {
+ "@context": {
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ },
+ "foo": [{"@value": "bar"}]
+ }
+
+
+
\ No newline at end of file
diff --git a/tests/expand/h013-in.html b/tests/expand/h013-in.html
new file mode 100644
index 00000000..4e0d64a4
--- /dev/null
+++ b/tests/expand/h013-in.html
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/expand/h014-in.html b/tests/expand/h014-in.html
new file mode 100644
index 00000000..ceeeff8b
--- /dev/null
+++ b/tests/expand/h014-in.html
@@ -0,0 +1,14 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/expand/h015-in.html b/tests/expand/h015-in.html
new file mode 100644
index 00000000..eb0e188a
--- /dev/null
+++ b/tests/expand/h015-in.html
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/expand/h016-in.html b/tests/expand/h016-in.html
new file mode 100644
index 00000000..1bc35a18
--- /dev/null
+++ b/tests/expand/h016-in.html
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/expand/h017-in.html b/tests/expand/h017-in.html
new file mode 100644
index 00000000..be515958
--- /dev/null
+++ b/tests/expand/h017-in.html
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/flatten-manifest.jsonld b/tests/flatten-manifest.jsonld
index adbbcc37..be4c3dcb 100644
--- a/tests/flatten-manifest.jsonld
+++ b/tests/flatten-manifest.jsonld
@@ -348,6 +348,42 @@
"option": {"specVersion": "json-ld-1.1"},
"input": "flatten/e001-in.jsonld",
"expect": "conflicting indexes"
+ }, {
+ "@id": "#th001",
+ "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"],
+ "name": "Flattens embedded JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML",
+ "input": "flatten/h001-in.html",
+ "context": "flatten/h001-context.jsonld",
+ "expect": "flatten/h001-out.jsonld",
+ "option": {"specVersion": "json-ld-1.1"}
+ }, {
+ "@id": "#th002",
+ "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"],
+ "name": "Flattens first embedded JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML",
+ "input": "flatten/h002-in.html",
+ "context": "flatten/h002-context.jsonld",
+ "expect": "flatten/h002-out.jsonld",
+ "option": {"specVersion": "json-ld-1.1", "extractAllScripts": false}
+ }, {
+ "@id": "#th003",
+ "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"],
+ "name": "Flattens targeted JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML with fragment identifier",
+ "input": "flatten/h003-in.html#second",
+ "context": "flatten/h003-context.jsonld",
+ "expect": "flatten/h003-out.jsonld",
+ "option": {"specVersion": "json-ld-1.1"}
+ }, {
+ "@id": "#th004",
+ "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"],
+ "name": "Flattens all script elements by default",
+ "purpose": "Tests embedded JSON-LD in HTML with fragment identifier",
+ "input": "flatten/h004-in.html",
+ "context": "flatten/h004-context.jsonld",
+ "expect": "flatten/h004-out.jsonld",
+ "option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tli01",
"@type": [ "jld:PositiveEvaluationTest", "jld:FlattenTest" ],
diff --git a/tests/flatten/h001-context.jsonld b/tests/flatten/h001-context.jsonld
new file mode 100644
index 00000000..c9ee5d89
--- /dev/null
+++ b/tests/flatten/h001-context.jsonld
@@ -0,0 +1,5 @@
+{
+ "@context": {
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ }
+}
\ No newline at end of file
diff --git a/tests/flatten/h001-in.html b/tests/flatten/h001-in.html
new file mode 100644
index 00000000..57328e38
--- /dev/null
+++ b/tests/flatten/h001-in.html
@@ -0,0 +1,12 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/flatten/h001-out.jsonld b/tests/flatten/h001-out.jsonld
new file mode 100644
index 00000000..b62c9ff4
--- /dev/null
+++ b/tests/flatten/h001-out.jsonld
@@ -0,0 +1,7 @@
+{
+ "@context": {
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ },
+ "@graph": [{"@id": "_:b0","foo": ["bar"]}
+ ]
+}
\ No newline at end of file
diff --git a/tests/flatten/h002-context.jsonld b/tests/flatten/h002-context.jsonld
new file mode 100644
index 00000000..c9ee5d89
--- /dev/null
+++ b/tests/flatten/h002-context.jsonld
@@ -0,0 +1,5 @@
+{
+ "@context": {
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ }
+}
\ No newline at end of file
diff --git a/tests/flatten/h002-in.html b/tests/flatten/h002-in.html
new file mode 100644
index 00000000..b287ab50
--- /dev/null
+++ b/tests/flatten/h002-in.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/flatten/h002-out.jsonld b/tests/flatten/h002-out.jsonld
new file mode 100644
index 00000000..b62c9ff4
--- /dev/null
+++ b/tests/flatten/h002-out.jsonld
@@ -0,0 +1,7 @@
+{
+ "@context": {
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ },
+ "@graph": [{"@id": "_:b0","foo": ["bar"]}
+ ]
+}
\ No newline at end of file
diff --git a/tests/flatten/h003-context.jsonld b/tests/flatten/h003-context.jsonld
new file mode 100644
index 00000000..bd58ee54
--- /dev/null
+++ b/tests/flatten/h003-context.jsonld
@@ -0,0 +1,3 @@
+{
+ "@context": {"ex": "http://example.com/"}
+}
\ No newline at end of file
diff --git a/tests/flatten/h003-in.html b/tests/flatten/h003-in.html
new file mode 100644
index 00000000..f18c1dae
--- /dev/null
+++ b/tests/flatten/h003-in.html
@@ -0,0 +1,21 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/flatten/h003-out.jsonld b/tests/flatten/h003-out.jsonld
new file mode 100644
index 00000000..cd0c43e1
--- /dev/null
+++ b/tests/flatten/h003-out.jsonld
@@ -0,0 +1,7 @@
+{
+ "@context": {"ex": "http://example.com/"},
+ "@graph": [
+ {"@id": "_:b0", "ex:foo": "foo"},
+ {"@id": "_:b1", "ex:bar": "bar"}
+ ]
+}
\ No newline at end of file
diff --git a/tests/flatten/h004-context.jsonld b/tests/flatten/h004-context.jsonld
new file mode 100644
index 00000000..c68c329c
--- /dev/null
+++ b/tests/flatten/h004-context.jsonld
@@ -0,0 +1,6 @@
+{
+ "@context": {
+ "ex": "http://example.com/",
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ }
+}
\ No newline at end of file
diff --git a/tests/flatten/h004-in.html b/tests/flatten/h004-in.html
new file mode 100644
index 00000000..cfac7160
--- /dev/null
+++ b/tests/flatten/h004-in.html
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tests/flatten/h004-out.jsonld b/tests/flatten/h004-out.jsonld
new file mode 100644
index 00000000..e0315dd2
--- /dev/null
+++ b/tests/flatten/h004-out.jsonld
@@ -0,0 +1,11 @@
+{
+ "@context": {
+ "ex": "http://example.com/",
+ "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+ },
+ "@graph": [
+ {"@id": "_:b0", "foo": ["bar"]},
+ {"@id": "_:b1", "ex:foo": "foo"},
+ {"@id": "_:b2", "ex:bar": "bar"}
+ ]
+}
\ No newline at end of file
diff --git a/tests/toRdf-manifest.jsonld b/tests/toRdf-manifest.jsonld
index 8402e443..6a9ab44c 100644
--- a/tests/toRdf-manifest.jsonld
+++ b/tests/toRdf-manifest.jsonld
@@ -877,6 +877,30 @@
"purpose": "IRI resolution according to RFC3986.",
"input": "toRdf/0129-in.jsonld",
"expect": "toRdf/0129-out.nq"
+ }, {
+ "@id": "#th001",
+ "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
+ "name": "Transforms embedded JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML",
+ "input": "toRdf/h001-in.html",
+ "expect": "toRdf/h001-out.nq",
+ "option": {"specVersion": "json-ld-1.1"}
+ }, {
+ "@id": "#th002",
+ "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
+ "name": "Transforms first embedded JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML",
+ "input": "toRdf/h002-in.html",
+ "expect": "toRdf/h002-out.nq",
+ "option": {"specVersion": "json-ld-1.1", "extractAllScripts": false}
+ }, {
+ "@id": "#th003",
+ "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
+ "name": "Transforms targeted JSON-LD script element",
+ "purpose": "Tests embedded JSON-LD in HTML with fragment identifier",
+ "input": "toRdf/h003-in.html#second",
+ "expect": "toRdf/h003-out.nq",
+ "option": {"specVersion": "json-ld-1.1"}
}, {
"@id": "#tli01",
"@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"],
diff --git a/tests/toRdf/h001-in.html b/tests/toRdf/h001-in.html
new file mode 100644
index 00000000..5f7274ed
--- /dev/null
+++ b/tests/toRdf/h001-in.html
@@ -0,0 +1,12 @@
+
+
+
+
+)
\ No newline at end of file
diff --git a/tests/toRdf/h001-out.nq b/tests/toRdf/h001-out.nq
new file mode 100644
index 00000000..91e9e279
--- /dev/null
+++ b/tests/toRdf/h001-out.nq
@@ -0,0 +1,3 @@
+_:b0