summaryrefslogtreecommitdiff
path: root/docs/plugin_parsers.rst
blob: f199b9226882d6c84e61a230a5167ceb15d784c4 (plain)
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
.. _plugin_parsers: Plugin parsers

==============
Plugin parsers
==============

These serializers are available in default RDFLib, you can use them by 
passing the name to graph's :meth:`~rdflib.graph.Graph.parse` method:: 

	graph.parse(my_url, format='n3')

The ``html`` parser will auto-detect RDFa, HTurtle or Microdata.

It is also possible to pass a mime-type for the ``format`` parameter::
    
	graph.parse(my_url, format='application/rdf+xml')

If you are not sure what format your file will be, you can use :func:`rdflib.util.guess_format` which will guess based on the file extension. 

========= ====================================================================
Name      Class                                                               
========= ====================================================================
json-ld   :class:`~rdflib.plugins.parsers.jsonld.JsonLDParser`
hext      :class:`~rdflib.plugins.parsers.hext.HextuplesParser`
n3        :class:`~rdflib.plugins.parsers.notation3.N3Parser`
nquads    :class:`~rdflib.plugins.parsers.nquads.NQuadsParser`
nt        :class:`~rdflib.plugins.parsers.ntriples.NTParser`
trix      :class:`~rdflib.plugins.parsers.trix.TriXParser`
turtle    :class:`~rdflib.plugins.parsers.notation3.TurtleParser`
xml       :class:`~rdflib.plugins.parsers.rdfxml.RDFXMLParser`
========= ====================================================================

Multi-graph IDs
---------------
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a ``ConjunctiveGraph`` or a ``Dataset``,
as opposed to a context-unaware ``Graph``, you will need to set the ``publicID`` of the ``ConjunctiveGraph`` a 
``Dataset`` to the identifier of the ``default_context`` (default graph), for example::

    d = Dataset()
    d.parse(
        data=""" ... """, 
        format="trig", 
        publicID=d.default_context.identifier
    )

(from the file tests/test_serializer_hext.py)