rdflib 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -1
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/fetcher.js +33 -7
- package/esm/index.js +1 -2
- package/esm/parse.js +4 -3
- package/esm/serializer.js +2 -2
- package/lib/fetcher.js +33 -7
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -10
- package/lib/parse.js +3 -2
- package/lib/serialize.d.ts +1 -1
- package/lib/serializer.js +2 -2
- package/lib/types.d.ts +1 -1
- package/package.json +2 -3
- package/src/fetcher.ts +33 -6
- package/src/index.ts +0 -2
- package/src/parse.ts +4 -3
- package/src/serialize.ts +1 -1
- package/src/serializer.js +2 -2
- package/src/types.ts +1 -0
- package/esm/jsonparser.js +0 -53
- package/lib/jsonparser.d.ts +0 -4
- package/lib/jsonparser.js +0 -59
- package/src/jsonparser.js +0 -53
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Javascript RDF library for browsers and Node.js.
|
|
|
8
8
|
- Read/Write Linked Data client, using WebDav or SPARQL/Update
|
|
9
9
|
- Real-Time Collaborative editing with web sockets and PATCHes
|
|
10
10
|
- Local API for querying a store
|
|
11
|
-
- Compatible with [
|
|
11
|
+
- Compatible with the [RDF/JS data model specification](https://rdf.js.org/data-model-spec/)
|
|
12
12
|
- SPARQL queries (not full SPARQL - just graph match and optional)
|
|
13
13
|
- Smushing of nodes from `owl:sameAs`, and `owl:{f,inverseF}unctionProperty`
|
|
14
14
|
- Tracks provenance of triples keeps metadata (in RDF) from HTTP accesses
|
|
@@ -63,6 +63,52 @@ installed.
|
|
|
63
63
|
npm install --save rdflib
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
## Creating terms
|
|
67
|
+
|
|
68
|
+
rdflib implements the [RDF/JS data model specification](https://rdf.js.org/data-model-spec/): terms are created with the factory functions `namedNode()`, `blankNode()`, `literal()`, `variable()` and `quad()`, all exported from the package root (`sym()` is an alias for `namedNode()`).
|
|
69
|
+
|
|
70
|
+
Note that, per that specification, `literal()` takes **two** arguments — the second one is *either* a language tag *or* a datatype:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
literal(value: string | number | boolean | Date, languageOrDatatype?: string | NamedNode): Literal
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For example:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
import { literal, namedNode } from 'rdflib'
|
|
80
|
+
|
|
81
|
+
literal('chat') // plain string literal ("chat"^^xsd:string)
|
|
82
|
+
literal('chat', 'fr') // language-tagged literal ("chat"@fr, datatype rdf:langString)
|
|
83
|
+
literal('2019', namedNode('http://www.w3.org/2001/XMLSchema#gYear')) // typed literal
|
|
84
|
+
literal('2019', 'http://www.w3.org/2001/XMLSchema#gYear') // same, with the datatype IRI as a string
|
|
85
|
+
literal(4) // convenience form: infers the datatype ("4"^^xsd:integer)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A string second argument is interpreted as a datatype IRI when it contains a colon, and as a language tag otherwise.
|
|
89
|
+
|
|
90
|
+
A common pitfall (present in some older tutorials) is calling `literal(value, undefined, datatype)`: the factory function ignores the third argument and returns a plain `xsd:string` literal. The three-argument form only exists on the class constructor, `new Literal(value, language, datatype)`. To create a typed literal with the factory function, pass the datatype as the second argument, as shown above.
|
|
91
|
+
|
|
92
|
+
## owl:sameAs smushing and link#uri statements
|
|
93
|
+
|
|
94
|
+
"Smushing" is the merging of everything a graph knows about two identifiers which are stated to denote the same thing. Stores perform **no** smushing by default (see [#458](https://github.com/linkeddata/rdflib.js/issues/458)); you opt in per feature when creating the store:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const kb = $rdf.graph(['sameAs', 'InverseFunctionalProperty', 'FunctionalProperty'])
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
With the `sameAs` feature enabled, whenever a statement `A owl:sameAs B` is added the store equates the two nodes: one of them is chosen as canonical and all statements are re-indexed under it, so queries about either identifier see the merged data. The `InverseFunctionalProperty` and `FunctionalProperty` features likewise equate nodes which share a value of such a property.
|
|
101
|
+
|
|
102
|
+
When two nodes are equated, the store records the equivalence by adding one statement of the form:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
<canonical> <http://www.w3.org/2007/ont/link#uri> <obsoleted> .
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
that is, a back-link from the canonical node to the identifier it replaced. This is internal book-keeping: it is how the store remembers aliases, so that `store.uris(term)` and `store.allAliases(node)` can list all the identifiers something is known by. It is stored like any other statement, though, so you may encounter these triples when querying or serializing a store that has smushing enabled. If a Fetcher is attached to the store, equating two nodes also triggers a look-up of the newly-learned alias, so that data published under either URI gets loaded.
|
|
109
|
+
|
|
110
|
+
The same `http://www.w3.org/2007/ont/link#` namespace is also used by the Fetcher for the HTTP metadata (requests, responses, status codes) it records; that metadata lives in a separate metadata graph and can be removed with `store.removeMetadata(doc)`.
|
|
111
|
+
|
|
66
112
|
## Serializer flags
|
|
67
113
|
|
|
68
114
|
The Turtle/N3/JSON‑LD serializers accept an optional `flags` string to tweak output formatting and abbreviation behavior.
|