public function toRDF($input, $options) {
    global $jsonld_default_load_document;
    self::setdefaults($options, array(
      'base' => is_string($input) ? $input : '',
      'produceGeneralizedRdf' => false,
      'documentLoader' => $jsonld_default_load_document));

    try {
      // expand input
      $expanded = $this->expand($input, $options);
    } catch(JsonLdException $e) {
      throw new JsonLdException(
        'Could not expand input before serialization to RDF.',
        'jsonld.RdfError', null, null, $e);
    }

    // create node map for default graph (and any named graphs)
    $namer = new UniqueNamer('_:b');
    $node_map = (object)array('@default' => new stdClass());
    $this->_createNodeMap($expanded, $node_map, '@default', $namer);

    // output RDF dataset
    $dataset = new stdClass();
    $graph_names = array_keys((array)$node_map);
    sort($graph_names);
    foreach($graph_names as $graph_name) {
      $graph = $node_map->{$graph_name};
      // skip relative IRIs
      if($graph_name === '@default' || self::_isAbsoluteIri($graph_name)) {
        $dataset->{$graph_name} = $this->_graphToRDF($graph, $namer, $options);
      }
    }

    $rval = $dataset;

    // convert to output format
    if(isset($options['format']) && $options['format']) {
      // supported formats
      if($options['format'] === 'application/nquads') {
        $rval = self::toNQuads($dataset);
      } else {
        throw new JsonLdException(
          'Unknown output format.', 'jsonld.UnknownFormat',
          null, array('format' => $options['format']));
      }
    }

    return $rval;
  }