Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added prolog bypass

  • Loading branch information...
commit b51013471c3fea52bc0768a2bc1c94de2480bc75 1 parent e797131
@phifty authored
View
13 lib/allegro_graph/proxy/sparql.rb → lib/allegro_graph/proxy/query.rb
@@ -3,22 +3,31 @@ module AllegroGraph
module Proxy
- class SparQL
+ class Query
+
+ LANGUAGES = [ :sparql, :prolog ].freeze unless defined?(LANGUAGES)
attr_reader :server
attr_reader :repository
+ attr_reader :language
def initialize(repository)
@repository = repository
@server = @repository.server
+ @language = :sparql
end
def path
@repository.path
end
+ def language=(value)
+ raise NotImplementedError, "query langauge [#{value}] is not implemented" unless LANGUAGES.include?(value.to_sym)
+ @language = value.to_sym
+ end
+
def perform(query)
- parameters = { :query => query, :queryLn => "sparql" }
+ parameters = { :query => query, :queryLn => @language.to_s }
@server.request :get, self.path, :parameters => parameters, :expected_status_code => 200
end
View
6 lib/allegro_graph/repository.rb
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), "server")
require File.join(File.dirname(__FILE__), "proxy", "statements")
-require File.join(File.dirname(__FILE__), "proxy", "sparql")
+require File.join(File.dirname(__FILE__), "proxy", "query")
module AllegroGraph
@@ -10,14 +10,14 @@ class Repository
attr_reader :catalog
attr_accessor :name
attr_reader :statements
- attr_reader :sparql
+ attr_reader :query
def initialize(server_or_catalog, name, options = { })
@catalog = server_or_catalog.is_a?(AllegroGraph::Server) ? server_or_catalog.root_catalog : server_or_catalog
@server = @catalog.server
@name = name
@statements = Proxy::Statements.new self
- @sparql = Proxy::SparQL.new self
+ @query = Proxy::Query.new self
end
def ==(other)
View
34 spec/integration/basic_spec.rb
@@ -123,7 +123,7 @@
end
- describe "sparql" do
+ describe "query bypass" do
before :each do
@repository.create_if_missing!
@@ -131,16 +131,34 @@
statements = @repository.statements
statements.create "\"test_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"test_object\"", "\"test_context\""
statements.create "\"another_subject\"", "<http://xmlns.com/foaf/0.1/knows>", "\"another_object\"", "\"test_context\""
+ end
+
+ context "sparql" do
+
+ before :each do
+ @repository.query.language = :sparql
+ end
+
+ it "should respond to queried data" do
+ result = @repository.query.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
+ result["names"].should include("subject")
+ result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
+ end
- @sparql = @repository.sparql
end
- it "should respond to queried data" do
- result = @sparql.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
- result.should == {
- "names" => [ "subject" ],
- "values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
- }
+ context "prolog" do
+
+ before :each do
+ @repository.query.language = :prolog
+ end
+
+ it "should respond to queried data" do
+ result = @repository.query.perform "(select (?subject) (q- ?subject !<http://xmlns.com/foaf/0.1/knows> ?object))"
+ result["names"].should include("subject")
+ result["values"].should include([ "\"another_subject\"" ], [ "\"test_subject\"" ])
+ end
+
end
end
View
62 spec/lib/allegro_graph/proxy/query_spec.rb
@@ -0,0 +1,62 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "lib", "allegro_graph", "proxy", "query"))
+
+describe AllegroGraph::Proxy::Query do
+
+ before :each do
+ @server = AllegroGraph::Server.new :username => "test", :password => "test"
+ @catalog = AllegroGraph::Catalog.new @server, "test_catalog"
+ @repository = AllegroGraph::Repository.new @catalog, "test_repository"
+ @query = AllegroGraph::Proxy::Query.new @repository
+ end
+
+ describe "path" do
+
+ it "should return the correct path" do
+ @query.path.should == @repository.path
+ end
+
+ end
+
+ describe "language=" do
+
+ it "should take :sparql" do
+ @query.language = :sparql
+ @query.language.should == :sparql
+ end
+
+ it "should take :prolog" do
+ @query.language = :prolog
+ @query.language.should == :prolog
+ end
+
+ it "should raise a NotImplementedError on invalid language" do
+ lambda do
+ @query.language = :invalid
+ end.should raise_error(NotImplementedError)
+ end
+
+ end
+
+ describe "perform" do
+
+ it "should return the sparql query result" do
+ result = @query.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
+ result.should == {
+ "names" => [ "subject" ],
+ "values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
+ }
+ end
+
+ it "should return the query result" do
+ @query.language = :prolog
+ result = @query.perform "(select (?subject) (q- ?subject ?predicate ?object))​"
+ result.should == {
+ "names" => [ "subject" ],
+ "values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
+ }
+ end
+
+ end
+
+end
View
33 spec/lib/allegro_graph/proxy/sparql_spec.rb
@@ -1,33 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
-require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "lib", "allegro_graph", "proxy", "sparql"))
-
-describe AllegroGraph::Proxy::SparQL do
-
- before :each do
- @server = AllegroGraph::Server.new :username => "test", :password => "test"
- @catalog = AllegroGraph::Catalog.new @server, "test_catalog"
- @repository = AllegroGraph::Repository.new @catalog, "test_repository"
- @sparql = AllegroGraph::Proxy::SparQL.new @repository
- end
-
- describe "path" do
-
- it "should return the correct path" do
- @sparql.path.should == @repository.path
- end
-
- end
-
- describe "perform" do
-
- it "should return the query result" do
- result = @sparql.perform "SELECT ?subject WHERE { ?subject <http://xmlns.com/foaf/0.1/knows> ?object . }"
- result.should == {
- "names" => [ "subject" ],
- "values" => [ [ "\"another_subject\"" ], [ "\"test_subject\"" ] ]
- }
- end
-
- end
-
-end
Please sign in to comment.
Something went wrong with that request. Please try again.