From 92f66b3ccb4c1c73cdf0ba1296c7e72aaf867852 Mon Sep 17 00:00:00 2001 From: Mark Watts Date: Sun, 31 May 2020 18:22:32 -0500 Subject: [PATCH] Adding docs for bnode_context arguments (#980) - Also making "py:obj" the default role for docs --- docs/conf.py | 2 +- rdflib/plugins/parsers/ntriples.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index dd9087c32..300cf0f1e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -102,7 +102,7 @@ def find_version(filename): exclude_trees = ["_build", "draft"] # The reST default role (used for this markup: `text`) to use for all documents. -# default_role = None +default_role = 'py:obj' # If true, '()' will be appended to :func: etc. cross-reference text. add_function_parentheses = True diff --git a/rdflib/plugins/parsers/ntriples.py b/rdflib/plugins/parsers/ntriples.py index f817cede2..21c931c69 100644 --- a/rdflib/plugins/parsers/ntriples.py +++ b/rdflib/plugins/parsers/ntriples.py @@ -120,6 +120,11 @@ class NTriplesParser(object): p = NTriplesParser(sink=MySink()) sink = p.parse(f) # file; use parsestring for a string + + To define a context in which blank node identifiers refer to the same blank node + across instances of NTriplesParser, pass the same dict as `bnode_context` to each + instance. By default, a new blank node context is created for each instance of + `NTriplesParser`. """ def __init__(self, sink=None, bnode_context=None): @@ -136,7 +141,14 @@ def __init__(self, sink=None, bnode_context=None): self.sink = Sink() def parse(self, f, bnode_context=None): - """Parse f as an N-Triples file.""" + """ + Parse f as an N-Triples file. + + :param f: the N-Triples source + :param bnode_context: a dict mapping blank node identifiers (e.g., ``a`` in ``_:a``) + to `.BNode` instances. An empty dict can be passed in to + define a distinct context for a given call to `parse`. + """ if not hasattr(f, "read"): raise ParseError("Item to parse must be a file-like object.") # since N-Triples 1.1 files can and should be utf-8 encoded