Skip to content

Commit

Permalink
Adding docs for bnode_context arguments (#980)
Browse files Browse the repository at this point in the history
- Also making "py:obj" the default role for docs
  • Loading branch information
mwatts15 committed May 31, 2020
1 parent 04d65c9 commit 92f66b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion rdflib/plugins/parsers/ntriples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 92f66b3

Please sign in to comment.