File: jsonld-parser.rst

package info (click to toggle)
python-rdflib-jsonld 0.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,832 kB
  • sloc: python: 1,800; makefile: 132
file content (50 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.. _rdflib_jsonld.jsonld_parser: an RDFLib plugin JSONLD parser

===================================
JSONLD parser plug-in for RDFLib
===================================

Using the plug-in JSONLD parser with RDFLib
---------------------------------------------

The plugin serializer is automatically registered if installed by
setuptools.

Identify a source of JSON-LD, pass the source to the parser,
manipulate the resulting graph.

.. code-block:: python

    >>> from rdflib import Graph, URIRef, Literal
    >>> test_json = """
    ... {
    ...     "@context": {
    ...         "dcterms": "http://purl.org/dc/terms/",
    ...         "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    ...         "rdfs": "http://www.w3.org/2000/01/rdf-schema#"
    ...     },
    ...     "@id": "http://example.org/about",
    ...     "dcterms:title": {
    ...         "@language": "en",
    ...         "@value": "Someone's Homepage"
    ...     }
    ... }
    ... """
    >>> g = Graph().parse(data=test_json, format='json-ld')
    >>> list(g) == [(URIRef('http://example.org/about'),
    ...     URIRef('http://purl.org/dc/terms/title'),
    ...     Literal(%(u)s"Someone's Homepage", lang=%(u)s'en'))]
    True


Module contents
---------------

.. currentmodule:: rdflib_jsonld.parser

.. automodule:: rdflib_jsonld.parser

.. autoclass:: JsonLDParser
   :members: parse

.. autofunction:: to_rdf