Skip to content

Commit

Permalink
Merge pull request #1489 from RDFLib/hextuples
Browse files Browse the repository at this point in the history
Hextuples Serializer
  • Loading branch information
nicholascar authored Dec 9, 2021
2 parents 9882769 + dabcacf commit 327de4e
Show file tree
Hide file tree
Showing 43 changed files with 1,058 additions and 199 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ extend-ignore =
# E501: line too long
# Disabled so that black can control line length.
E501,
# Ignored since this is soon not going to be considered an error, see https://www.flake8rules.com/rules/W503.html
W503,
25 changes: 18 additions & 7 deletions docs/plugin_parsers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@ 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')
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`
html :class:`~rdflib.plugins.parsers.structureddata.StructuredDataParser`
hturtle :class:`~rdflib.plugins.parsers.hturtle.HTurtleParser`
mdata :class:`~rdflib.plugins.parsers.structureddata.MicrodataParser`
microdata :class:`~rdflib.plugins.parsers.structureddata.MicrodataParser`
n3 :class:`~rdflib.plugins.parsers.notation3.N3Parser`
nquads :class:`~rdflib.plugins.parsers.nquads.NQuadsParser`
nt :class:`~rdflib.plugins.parsers.ntriples.NTParser`
rdfa :class:`~rdflib.plugins.parsers.structureddata.RDFaParser`
rdfa1.0 :class:`~rdflib.plugins.parsers.structureddata.RDFa10Parser`
rdfa1.1 :class:`~rdflib.plugins.parsers.structureddata.RDFaParser`
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)
19 changes: 18 additions & 1 deletion docs/plugin_serializers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,35 @@ passing the name to a graph's :meth:`~rdflib.graph.Graph.serialize` method::

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

========== ===============================================================
Name Class
========== ===============================================================
json-ld :class:`~rdflib.plugins.serializers.jsonld.JsonLDSerializer`
n3 :class:`~rdflib.plugins.serializers.n3.N3Serializer`
nquads :class:`~rdflib.plugins.serializers.nquads.NQuadsSerializer`
nt :class:`~rdflib.plugins.serializers.nt.NTSerializer`
hext :class:`~rdflib.plugins.serializers.hext.HextuplesSerializer`
pretty-xml :class:`~rdflib.plugins.serializers.rdfxml.PrettyXMLSerializer`
trig :class:`~rdflib.plugins.serializers.trig.TrigSerializer`
trix :class:`~rdflib.plugins.serializers.trix.TriXSerializer`
turtle :class:`~rdflib.plugins.serializers.turtle.TurtleSerializer`
longturtle :class:`~rdflib.plugins.serializers.turtle.LongTurtleSerializer`
xml :class:`~rdflib.plugins.serializers.rdfxml.XMLSerializer`
========== ===============================================================


JSON-LD
-------
JSON-LD - 'json-ld' - has been incorprated in rdflib since v6.0.0.

HexTuples
---------
The HexTuples Serializer - 'hext' - uses the HexTuples format defined at https://github.com/ontola/hextuples.

For serialization of non-context-aware data sources, e.g. a single ``Graph``, the 'graph' field (6th variable in the
Hextuple) will be an empty string.

For context-aware (multi-graph) serialization, the 'graph' field of the default graph will be an empty string and
the values for other graphs will be Blank Node IDs or IRIs.
2 changes: 1 addition & 1 deletion rdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
__docformat__ = "restructuredtext en"

# The format of the __version__ line is matched by a regex in setup.py
__version__ = "6.03a"
__version__ = "6.0.3"
__date__ = "2021-10-10"

__all__ = [
Expand Down
1 change: 0 additions & 1 deletion rdflib/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ def _traces(
candidates = self._get_candidates(coloring)
best: List[List[Color]] = []
best_score = None
best_experimental = None
best_experimental_score = None
last_coloring = None
generator: Dict[Node, Set[Node]] = defaultdict(set)
Expand Down
3 changes: 1 addition & 2 deletions rdflib/namespace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@

__all__ = ["is_ncname", "split_uri", "Namespace", "ClosedNamespace", "NamespaceManager"]


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -192,7 +191,7 @@ def __getitem__(cls, name, default=None):
name = str(name)
if str(name).startswith("__"):
return super().__getitem__(name, default)
if (cls._warn or cls._fail) and not name in cls:
if (cls._warn or cls._fail) and name not in cls:
if cls._fail:
raise AttributeError(f"term '{name}' not in namespace '{cls._NS}'")
else:
Expand Down
3 changes: 1 addition & 2 deletions rdflib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ def create_input_source(
input_source = StringInputSource(data)
auto_close = True
else:
raise RuntimeError(
f"parse data can only str, or bytes. not: {type(data)}")
raise RuntimeError(f"parse data can only str, or bytes. not: {type(data)}")

if input_source is None:
raise Exception("could not create InputSource")
Expand Down
Loading

0 comments on commit 327de4e

Please sign in to comment.