Created
March 9, 2016 20:33
-
-
Save jcoyne/e25454bfb3f1d978f74c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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