Skip to content

Instantly share code, notes, and snippets.

@jcoyne
Created March 9, 2016 20:33
Show Gist options
  • Save jcoyne/e25454bfb3f1d978f74c to your computer and use it in GitHub Desktop.
Save jcoyne/e25454bfb3f1d978f74c to your computer and use it in GitHub Desktop.
module RDF
class SubjectFragments < RDF::Repository
attr_reader :client
def initialize(url)
@client = Client.new(url)
end
def query_pattern(pattern, options = {}, &block)
pattern = pattern.dup
pattern.subject ||= RDF::Query::Variable.new
pattern.predicate ||= RDF::Query::Variable.new
pattern.object ||= RDF::Query::Variable.new
pattern.initialize!
query = Query.new(pattern)
if block_given?
client.query(query).each_statement(&block)
else
raise "Not Implemented"
end
end
class Client
def initialize(base_url)
@base_url = base_url
end
def query(query)
resource_uri = query.pattern.subject
url = @base_url + resource_uri.to_s + "?format=ttl"
RDF::Graph.load(resource_uri)
end
end
class Query
attr_reader :pattern
def initialize(pattern)
@pattern = pattern
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment