Sha256: 383a86828479886ccffe3ac5f297c05cb2dc93b82d958043e29f0b6e1757f007

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# Author:: Eyal Oren
# Copyright:: (c) 2005-2006 Eyal Oren
# License:: LGPL

# FetchingAdapter is an extension to rdflite for fetching RDF from online sources.
class FetchingAdapter < RDFLite
  ConnectionPool.register_adapter(:fetching, self)

  # TODO: check that rapper is installed

  # fetches RDF/XML data from given url and adds it to the datastore, using the 
  # source url as context identifier.
  def fetch url
    # check if url starts with http://
    return unless url.match(/http:\/\/(.*)/)

    ActiveRdfLogger::log_debug(self) { "Fetching from #{url}" }

    #model = Redland::Model.new
    #parser = Redland::Parser.new('rdfxml')
    #scan = Redland::Uri.new('http://feature.librdf.org/raptor-scanForRDF')
    #enable = Redland::Literal.new('1')
    #Redland::librdf_parser_set_feature(parser, scan.uri, enable.node)
    #parser.parse_into_model(model, url)
    #triples = Redland::Serializer.ntriples.model_to_string(nil, model)

    triples = `rapper --scan --quiet "#{url}"`
    lines = triples.split($/)
    ActiveRdfLogger::log_debug(self) { "Found #{lines.size} triples" }

    context = Query.resource_class.new(url)
    add_ntriples(triples, context)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activerdf_net7-1.6.16 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb
activerdf_net7-1.6.15 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb
activerdf_net7-1.6.14 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb
activerdf_net7-1.6.13 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb
activerdf_net7-1.6.12 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb
activerdf_net7-1.6.11 activerdf-rdflite/lib/activerdf_rdflite/fetching.rb