Class: DirectAccess
- Inherits:
-
Object
- Object
- DirectAccess
- Defined in:
- lib/active_rdf/directaccess/direct_access.rb
Overview
Direct access for Redland adapter
Syntax “<http://.…..>” = Resource “abc” = Literal “_:” = Blank Node “_:123” = Blank Node with id
Class Method Summary collapse
-
.find_all_by_subject_and_predicate(s, p) ⇒ Object
Find all triple by subject and predicate The return value is a PropertyList.
-
.sparql_query(query, result_format = :array) ⇒ Object
Execute a SPARQL query.
Class Method Details
.find_all_by_subject_and_predicate(s, p) ⇒ Object
Find all triple by subject and predicate The return value is a PropertyList
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_rdf/directaccess/direct_access.rb', line 36 def self.find_all_by_subject_and_predicate(s,p) # verify input if s.nil? || p.nil? raise ActiveRdfError, "subject and predicate can't be nil" end # execute query query_result = self.sparql_query("SELECT ?o WHERE {#{s} #{p} ?o}") # return propertyList return PropertyList.new(p, query_result, s) end |
.sparql_query(query, result_format = :array) ⇒ Object
Execute a SPARQL query. The second parameter specify the result format (:json, :xml, :array) (optional)
The return default value is an Array. If you specify :xml or :json in result_format, the return value is a String that contain the request format.
Example: query(“SELECT ?p ?o WHERE href="http://activerdf.org/test/eyal">activerdf.org/test/eyal> ?p ?o”, :json)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_rdf/directaccess/direct_access.rb', line 19 def self.sparql_query(query, result_format=:array) # verify input if query.nil? raise ActiveRdfError, "cannot execute empty query" end # verify class type if query.class != String raise ActiveRdfError, "query must be String." end # execute query FederationManager.query(query, {:result_format => result_format}) end |