@@ -493,8 +493,12 @@ function generateMissingIdsForBlankNodes(nquadsArray) {
493493 }
494494 return term ; // Return IRI or Literal unchanged
495495 }
496-
496+ const unsupportedNquads = [ ] ;
497497 const updatedNquads = parser . parse ( nquadsArray . join ( "" ) ) . map ( ( quad ) => {
498+ // Check if BlankNodes are parsed as graphs
499+ if ( quad . graph . termType === "BlankNode" ) {
500+ unsupportedNquads . push ( writer . quadToString ( quad . object , quad . predicate , quad . object , quad . graph ) ) ;
501+ }
498502 // Replace blank nodes in the quad
499503 const updatedQuad = N3 . DataFactory . quad (
500504 replaceBlankNode ( quad . subject ) ,
@@ -506,6 +510,24 @@ function generateMissingIdsForBlankNodes(nquadsArray) {
506510 return updatedQuad ;
507511 } ) ;
508512
513+ if ( unsupportedNquads . length > 0 ) {
514+ throw new Error ( `
515+ ------------------------------------------------------------------------------------------------
516+ Unsupported JSON-LD input detected
517+
518+ After parsing the JSON-LD input, the parser detected creation of new named graphs.
519+ The DKG does not support custom named graphs.
520+
521+ Problematic Quads:
522+ ${ unsupportedNquads . map ( ( q , i ) => ` ${ i + 1 } . ${ q } ` ) . join ( "\n" ) }
523+
524+ Full Parsed N-Quads Array:
525+ ${ nquadsArray . join ( '\n' ) }
526+ Parsing failed due to presence of unnamed (blank node) graphs. Please ensure all graphs in the input JSON-LD have proper named IRIs.
527+ `
528+ ) ;
529+ }
530+
509531 return writer . quadsToString ( updatedNquads ) . trimEnd ( ) . split ( "\n" ) ;
510532}
511533
0 commit comments