127127# Initial contexts, defined on first access
128128INITIAL_CONTEXTS = {}
129129
130- # In legacy mode, pyld returns RDF datasets as
131- # RDFJS-like dict objects, equivalent to PyLD < 4.0
132- LEGACY_MODE = True
133-
134130# Handler to call if a property was dropped during expansion
135131OnPropertyDropped = Callable [[str | None ], Any ]
136132
@@ -1059,6 +1055,7 @@ def to_rdf(self, input_, options):
10591055 (default: _default_document_loader).
10601056 [rdfDirection] Only 'i18n-datatype' supported
10611057 (default: None).
1058+ [legacyMode] Output result as RDF.js-like dict.
10621059
10631060 :return: the resulting RDF dataset (or a serialization of it).
10641061 """
@@ -1107,7 +1104,9 @@ def to_rdf(self, input_, options):
11071104 'jsonld.UnknownFormat' ,
11081105 {'format' : options ['format' ]},
11091106 )
1110- return to_legacy_dataset (dataset ) if LEGACY_MODE else dataset
1107+ # In legacy mode, return RDF datasets as
1108+ # RDFJS-like dict objects equivalent to PyLD < 4.0
1109+ return to_legacy_dataset (dataset ) if options .get ('legacyMode' , False ) else dataset
11111110
11121111 def process_context (self , active_ctx , local_ctx , options ):
11131112 """
@@ -1416,7 +1415,7 @@ def get_context_value(ctx, key, type_):
14161415 return rval
14171416
14181417 @staticmethod
1419- def parse_nquads (input_ : str ) -> Dataset | dict :
1418+ def parse_nquads (input_ : str , ** kwargs ) -> Dataset | dict :
14201419 """
14211420 Parses RDF in the form of N-Quads.
14221421
@@ -1435,7 +1434,9 @@ def parse_nquads(input_: str) -> Dataset | dict:
14351434 parser = NQuadsParser ()
14361435 rdflib .NORMALIZE_LITERALS = False
14371436 parser .parse (StringInputSource (input_ ), dataset , bnode_context = bnode_context )
1438- return to_legacy_dataset (dataset ) if LEGACY_MODE else dataset
1437+ # In legacy mode, return RDF datasets as
1438+ # RDFJS-like dict objects equivalent to PyLD < 4.0
1439+ return to_legacy_dataset (dataset ) if kwargs .get ('legacy_mode' , False ) else dataset
14391440 except SyntaxError as cause :
14401441 raise JsonLdError (
14411442 str (cause ), 'jsonld.ParseError' , {'line' : cause .lineno }
0 commit comments