How to use the jsonld.fromRDF function in jsonld

To help you get started, we’ve selected a few jsonld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LinkedDataFragments / Server.js / lib / JsonLdFragmentWriter.js View on Github external
end: function () {
      jsonld.fromRDF(triples, { format: true, useNativeTypes: true, rdfParser:
      // Converts the N3.js library triple representation to the JSON-LD library representation
      function fromN3Representation(triples) {
        return { '@default': triples.map(function (triple) {
          var subject = triple.subject, predicate = triple.predicate, object = triple.object;
          return {
            subject:   { value: subject,   type: getTypeName(object) },
            predicate: { value: predicate, type: getTypeName(object) },
            object:    !N3Util.isLiteral(object) ? { value: object, type: getTypeName(object) }
                                                 : { value: N3Util.getLiteralValue(object),
                                                     datatype: N3Util.getLiteralType(object),
                                                     language: N3Util.getLiteralLanguage(object) }
          };
        })};
      }},
      function (error, json) {
        jsonld.compact(error ? {} : json, context, function (err, compacted) {
github digitalbazaar / jsonld-request / lib / request.js View on Github external
done: function(errors, window) {
            if(errors && errors.length > 0) {
              return callback({
                message: 'DOM Errors:',
                errors: errors,
                url: loc
              });
            }

            try {
              // extract JSON-LD from RDFa
              RDFa.attach(window.document);
              jsonld.fromRDF(window.document.data,
                {format: 'rdfa-api'}, callback);
            } catch(ex) {
              // FIXME: expose RDFa/jsonld ex?
              callback({
                message: 'RDFa extraction error.',
                contentType: type,
                url: loc
              });
            }
          }
        });
github TopQuadrant / shacl / js / index.js View on Github external
nodes[result[0].toString()] = true;
                resultGraph.add(reportNode, T("sh:result"), result[0]);
            }
            resultGraph.add(result[0], result[1], result[2]);
        }

        // Unsupported bug in JSON parser bug workaround
        var oldToString = resultGraph.toString;
        resultGraph.toString = function () {
            var text = oldToString.call(resultGraph);
            text = text.replace(/^\{/, "").replace(/\}$/, "");
            return text;
        };
        //////////////////

        jsonld.fromRDF(resultGraph.toNT(), {}, function (err, doc) {
            if (err != null) {
                cb(err);
            } else {
                jsonld.flatten(doc, function (err, result) {
                    if (err != null) {
                        cb(err);
                    } else {
                        cb(null, new ValidationReport(result));
                    }
                });
            }
        });
    }
};
github science-periodicals / schema.org / data / index.js View on Github external
label: 'rdfs:label',
    altLabel: 'skos:altLabel',
    status: 'vs:term_status',
    subPropertyOf: {
      '@id': 'rdfs:subPropertyOf',
      '@type': '@id'
    },
    source: {
      '@id': 'dc:source',
      '@type': '@id'
    },
    defines: { '@reverse': 'rdfs:isDefinedBy' }
  }
};

jsonld.fromRDF(
  'http://schema.org/docs/schema_org_rdfa.html',
  { format: 'text/html' },
  function(err, data) {
    if (err) throw err;
    jsonld.compact(data, context, function(err, data) {
      if (err) throw err;
      fs.writeFile(
        path.resolve(path.dirname(__dirname), 'src', 'schema_org.json'),
        JSON.stringify(data, null, 2),
        function(err) {
          if (err) throw err;

          // grab schema.org context
          request.get(
            {
              url: 'http://schema.org',
github digibib / ls.ext / redef / patron-client / src / backend / routes / resources.js View on Github external
return new Promise((resolve, reject) => {
    jsonld.fromRDF(ntdata, { format: 'application/nquads' }, (error, ntdoc) => {
      if (error) {
        reject(error)
      }

      // We need to add a class to the work 'in focus', in case there are other works
      // in the graph (for example work as subject of work), and use this class
      // for framing.
      //
      // We also delete the class migration:Work, as it trips up the framing.
      ntdoc = ntdoc.map(el => {
        if (el[ '@type' ] && el[ '@type' ].includes('http://data.deichman.no/ontology#Work') && el[ '@id' ] === `http://data.deichman.no/work/${workId}`) {
          el[ '@type' ].push('http://data.deichman.no/ontology#WorkInFocus')
        }
        if (el[ '@type' ]) {
          const i = el[ '@type' ].indexOf('http://migration.deichman.no/Work')
          if (i !== -1) {
github DefinitelyTyped / DefinitelyTyped / types / jsonld / jsonld-tests.ts View on Github external
* fromRDF() test
 */
jsonld.fromRDF(docNQuads, (err, res) => {
    log(res);
});

jsonld.fromRDF(docNQuads, {format: 'application/n-quads'}, (err, res) => {
    log(res);
});

jsonld.fromRDF(docRDF)
.then((res) => {
    log(res);
});

jsonld.fromRDF(docRDF, {useRdfType: false})
.then((res) => {
    log(res);
});

/**
 * toRDF() test
 */
jsonld.toRDF(doc, (err, res) => {
    log(res);
});

jsonld.toRDF(doc, {format: 'application/n-quads'}, (err, res) => {
    log(res);
});

jsonld.toRDF(doc)
github iRail / stations / bin / build.js View on Github external
writer.end(function (error, output) {
    if (error) {
      console.error("Problem: " + error);
    } else {
      if (format !== "json") {
        console.log(output);
      } else {
        jsonld.fromRDF(output, {format: 'application/nquads'}, function(err, doc) {
          jsonld.compact(doc, context, function(err, compacted) {
            var jsonresult = JSON.stringify(compacted);
            //ugly fix for https://github.com/iRail/stations/issues/8
            jsonresult = jsonresult.replace(/"alternative":({.*?})/gi,"\"alternative\":[$1]");
            console.log(jsonresult);
          });   
        });
      }
    }
  });
});
github BlueBrain / nexus-js / apps / search-poc / src / views / MainView.tsx View on Github external
        .then(response => jsonld.fromRDF(makeNQuad(response), studioData))
        .then(json => jsonld.frame(json, studioFrame, { embed: '@always' }))
github LinkedDataFragments / Server.js / lib / views / RdfView.js View on Github external
end: function () {
      jsonld.fromRDF(quads, { format: false, useNativeTypes: true },
      function (error, json) {
        jsonld.compact(error ? {} : json, context, function (error, compacted) {
          response.write(JSON.stringify(compacted, null, '  ') + '\n');
          done(error);
        });
      });
    },
  };
github researchstudio-sat / webofneeds / webofneeds / won-owner-webapp / src / main / webapp / app / service / file-service.js View on Github external
rawFile.onreadystatechange = function()
        {
            if(rawFile.readyState === 4)
            {
                if(rawFile.status === 200 || rawFile.status == 0)
                {
                    var allText = rawFile.responseText;
                    jsonLD.fromRDF(allText,{format:'application/trig'},function(err,doc){
                        $log.debug(doc);
                    });

                }
            }
        }
    }