@@ -250,6 +250,8 @@ def link(input_, ctx, options=None):
250250 defaults to 'json-ld-1.1'.
251251 [documentLoader(url, options)] the document loader
252252 (default: _default_document_loader).
253+ [identifierIssuer] an IdentifierIssuer instance to use for blank node
254+ identifiers (default: IdentifierIssuer('_:b')).
253255
254256 :return: the linked JSON-LD output.
255257 """
@@ -685,6 +687,8 @@ def flatten(self, input_, ctx, options):
685687 defaults to 'json-ld-1.1'.
686688 [documentLoader(url, options)] the document loader
687689 (default: _default_document_loader).
690+ [identifierIssuer] an IdentifierIssuer instance to use for blank node
691+ identifiers (default: IdentifierIssuer('_:b')).
688692
689693 :return: the flattened JSON-LD output.
690694 """
@@ -697,6 +701,7 @@ def flatten(self, input_, ctx, options):
697701 )
698702 options .setdefault ('extractAllScripts' , True )
699703 options .setdefault ('processingMode' , 'json-ld-1.1' )
704+ options .setdefault ('identifierIssuer' , IdentifierIssuer ('_:b' ))
700705
701706 try :
702707 # expand input
@@ -707,7 +712,7 @@ def flatten(self, input_, ctx, options):
707712 ) from cause
708713
709714 # do flattening
710- flattened = self ._flatten (expanded )
715+ flattened = self ._flatten (expanded , options )
711716
712717 if ctx is None :
713718 return flattened
@@ -750,6 +755,8 @@ def frame(self, input_, frame, options):
750755 [requireAll] default @requireAll flag (default: False).
751756 [documentLoader(url, options)] the document loader
752757 (default: _default_document_loader).
758+ [identifierIssuer] an IdentifierIssuer instance to use for blank node
759+ identifiers (default: IdentifierIssuer('_:b')).
753760
754761 :return: the framed JSON-LD output.
755762 """
@@ -769,6 +776,7 @@ def frame(self, input_, frame, options):
769776 )
770777 options .setdefault ('extractAllScripts' , False )
771778 options .setdefault ('processingMode' , 'json-ld-1.1' )
779+ options .setdefault ('identifierIssuer' , IdentifierIssuer ('_:b' ))
772780
773781 # if frame is a string, attempt to dereference remote document
774782 if _is_string (frame ):
@@ -901,6 +909,8 @@ def normalize(self, input_, options):
901909 )
902910 options .setdefault ('extractAllScripts' , True )
903911 options .setdefault ('processingMode' , 'json-ld-1.1' )
912+ # Prevent a custom identifier issuer accidentally messing up normalization.
913+ options .pop ('identifierIssuer' , None )
904914
905915 if options ['algorithm' ] not in ['URDNA2015' , 'URGNA2012' ]:
906916 raise JsonLdError (
@@ -2845,7 +2855,7 @@ def _prepare_nested_context(self, active_ctx, element, options):
28452855
28462856 return active_ctx , type_key , type_scoped_ctx
28472857
2848- def _flatten (self , input ):
2858+ def _flatten (self , input , options ):
28492859 """
28502860 Performs JSON-LD flattening.
28512861
@@ -2854,7 +2864,7 @@ def _flatten(self, input):
28542864 :return: the flattened JSON-LD output.
28552865 """
28562866 # produce a map of all subjects and label each bnode
2857- issuer = IdentifierIssuer ('_:b' )
2867+ issuer = options [ 'identifierIssuer' ] or IdentifierIssuer ('_:b' )
28582868 graphs = {'@default' : {}}
28592869 self ._create_node_map (input , graphs , '@default' , issuer )
28602870
@@ -2900,7 +2910,7 @@ def _frame(self, input_, frame, options):
29002910 }
29012911
29022912 # produce a map of all graphs and name each bnode
2903- issuer = IdentifierIssuer ('_:b' )
2913+ issuer = options [ 'identifierIssuer' ] or IdentifierIssuer ('_:b' )
29042914 self ._create_node_map (input_ , state ['graphMap' ], '@default' , issuer )
29052915 if options ['merged' ]:
29062916 state ['graphMap' ]['@merged' ] = self ._merge_node_map_graphs (
0 commit comments