@@ -131,12 +131,15 @@ function jsonld_link($input, $ctx, $options) {
131
131
};
132
132
133
133
/**
134
- * Performs RDF dataset normalization on the given JSON-LD input. The output
135
- * is an RDF dataset unless the 'format' option is used.
134
+ * Performs RDF dataset normalization on the given input. The input is
135
+ * JSON-LD unless the 'inputFormat' option is used. The output is an RDF
136
+ * dataset unless the 'format' option is used.
136
137
*
137
138
* @param mixed $input the JSON-LD object to normalize.
138
139
* @param assoc [$options] the options to use:
139
140
* [base] the base IRI to use.
141
+ * [intputFormat] the format if input is not JSON-LD:
142
+ * 'application/nquads' for N-Quads.
140
143
* [format] the format if output is a string:
141
144
* 'application/nquads' for N-Quads.
142
145
* [documentLoader(url)] the document loader.
@@ -1229,6 +1232,8 @@ public function frame($input, $frame, $options) {
1229
1232
* @param assoc $options the options to use:
1230
1233
* [base] the base IRI to use.
1231
1234
* [expandContext] a context to expand with.
1235
+ * [inputFormat] the format if input is not JSON-LD:
1236
+ * 'application/nquads' for N-Quads.
1232
1237
* [format] the format if output is a string:
1233
1238
* 'application/nquads' for N-Quads.
1234
1239
* [documentLoader(url)] the document loader.
@@ -1241,18 +1246,26 @@ public function normalize($input, $options) {
1241
1246
'base ' => is_string ($ input ) ? $ input : '' ,
1242
1247
'documentLoader ' => $ jsonld_default_load_document ));
1243
1248
1244
- try {
1245
- // convert to RDF dataset then do normalization
1246
- $ opts = $ options ;
1247
- if (isset ($ opts ['format ' ])) {
1248
- unset($ opts ['format ' ]);
1249
+ if (isset ($ options ['inputFormat ' ])) {
1250
+ if ($ options ['inputFormat ' ] != 'application/nquads ' ) {
1251
+ throw new JsonLdException (
1252
+ 'Unknown normalization input format. ' , 'jsonld.NormalizeError ' );
1253
+ }
1254
+ $ dataset = $ this ->parseNQuads ($ input );
1255
+ } else {
1256
+ try {
1257
+ // convert to RDF dataset then do normalization
1258
+ $ opts = $ options ;
1259
+ if (isset ($ opts ['format ' ])) {
1260
+ unset($ opts ['format ' ]);
1261
+ }
1262
+ $ opts ['produceGeneralizedRdf ' ] = false ;
1263
+ $ dataset = $ this ->toRDF ($ input , $ opts );
1264
+ } catch (Exception $ e ) {
1265
+ throw new JsonLdException (
1266
+ 'Could not convert input to RDF dataset before normalization. ' ,
1267
+ 'jsonld.NormalizeError ' , null , null , $ e );
1249
1268
}
1250
- $ opts ['produceGeneralizedRdf ' ] = false ;
1251
- $ dataset = $ this ->toRDF ($ input , $ opts );
1252
- } catch (Exception $ e ) {
1253
- throw new JsonLdException (
1254
- 'Could not convert input to RDF dataset before normalization. ' ,
1255
- 'jsonld.NormalizeError ' , null , null , $ e );
1256
1269
}
1257
1270
1258
1271
// do normalization
0 commit comments