tasks/jsonld/js/jsonld.js
function _graphToRDF(graph, namer) {
  var rval = [];

  var ids = Object.keys(graph).sort();
  for(var i = 0; i < ids.length; ++i) {
    var id = ids[i];
    var node = graph[id];
    var properties = Object.keys(node).sort();
    for(var pi = 0; pi < properties.length; ++pi) {
      var property = properties[pi];
      var items = node[property];
      if(property === '@type') {
        property = RDF_TYPE;
      }
      else if(_isKeyword(property)) {
        continue;
      }

      for(var ii = 0; ii < items.length; ++ii) {
        var item = items[ii];

        // RDF subject
        var subject = {};
        subject.type = (id.indexOf('_:') === 0) ? 'blank node' : 'IRI';
        subject.value = id;

        // RDF predicate
        var predicate = {};
        predicate.type = (property.indexOf('_:') === 0) ? 'blank node' : 'IRI';
        predicate.value = property;

        // convert @list to triples
        if(_isList(item)) {
          _listToRDF(item['@list'], namer, subject, predicate, rval);
        }
        // convert value or node object to triple
        else {
          var object = _objectToRDF(item);
          rval.push({subject: subject, predicate: predicate, object: object});
        }
      }
    }
  }

  return rval;
}
function _graphToRDF(graph, namer) {
  var rval = [];

  var ids = Object.keys(graph).sort();
  for(var i = 0; i < ids.length; ++i) {
    var id = ids[i];
    var node = graph[id];
    var properties = Object.keys(node).sort();
    for(var pi = 0; pi < properties.length; ++pi) {
      var property = properties[pi];
      var items = node[property];
      if(property === '@type') {
        property = RDF_TYPE;
      }
      else if(_isKeyword(property)) {
        continue;
      }

      for(var ii = 0; ii < items.length; ++ii) {
        var item = items[ii];

        // RDF subject
        var subject = {};
        subject.type = (id.indexOf('_:') === 0) ? 'blank node' : 'IRI';
        subject.value = id;

        // RDF predicate
        var predicate = {};
        predicate.type = (property.indexOf('_:') === 0) ? 'blank node' : 'IRI';
        predicate.value = property;

        // convert @list to triples
        if(_isList(item)) {
          _listToRDF(item['@list'], namer, subject, predicate, rval);
        }
        // convert value or node object to triple
        else {
          var object = _objectToRDF(item);
          rval.push({subject: subject, predicate: predicate, object: object});
        }
      }
    }
  }

  return rval;
}
function _graphToRDF ( graph , namer ) { var rval = [ ] ; var ids = Object . keys ( graph ) . sort ( ) ; for ( var i = 0 ; i < ids . length ; ++ i ) { var id = ids [ i ] ; var node = graph [ id ] ; var properties = Object . keys ( node ) . sort ( ) ; for ( var pi = 0 ; pi < properties . length ; ++ pi ) { var property = properties [ pi ] ; var items = node [ property ] ; if ( property === '@type' ) { property = RDF_TYPE ; } else if ( _isKeyword ( property ) ) { continue ; } for ( var ii = 0 ; ii < items . length ; ++ ii ) { var item = items [ ii ] ; // RDF subject var subject = { } ; subject . type = ( id . indexOf ( '_:' ) === 0 ) ? 'blank node' : 'IRI' ; subject . value = id ; // RDF predicate var predicate = { } ; predicate . type = ( property . indexOf ( '_:' ) === 0 ) ? 'blank node' : 'IRI' ; predicate . value = property ; // convert @list to triples if ( _isList ( item ) ) { _listToRDF ( item [ '@list' ] , namer , subject , predicate , rval ) ; } // convert value or node object to triple else { var object = _objectToRDF ( item ) ; rval . push ( { subject : subject , predicate : predicate , object : object } ) ; } } } } return rval ; }
Creates an array of RDF triples for the given graph.

@param graph the graph to create RDF triples for.
@param namer a UniqueNamer for assigning blank node names.

@return the array of RDF triples for the given graph.
Creates an array of RDF triples for the given graph .