Class: ActiveRubinstein::JenaQuery
- Defined in:
- lib/active_rubinstein/jena_query.rb
Overview
JenaQuery translates an ActiveRubic query to JeanLuc::Picard over the DRb via method_missing.
execute accepts these actions:
-
:instances_of :class => getInstances
-
:parents the same method is used for both instances and classes, but the actual method in Java is different :class || :subject
is_class? => getParents is_subject? => getInstanceClass
-
:ancestors :class => getAncestors
-
:children :class => getChildren
-
:descendants :class => getDescendants
-
:roots :ontology => getRoot
-
:classes_within :class, :radius => getClassesWithin
-
:inverse :property => getInverse
Instance Attribute Summary collapse
-
#language ⇒ Object
allow to set query language.
Class Method Summary collapse
-
.execute(query, options) ⇒ Object
analyzes the query to find the correct method to execute.
-
.server ⇒ Object
returns the server object.
Instance Method Summary collapse
-
#initialize ⇒ JenaQuery
constructor
picks a JenaEndpoint from the server pool.
Methods inherited from Base
#hello, #roll, set_language, #shuffle
Constructor Details
#initialize ⇒ JenaQuery
picks a JenaEndpoint from the server pool.
63 64 65 66 67 68 69 70 71 |
# File 'lib/active_rubinstein/jena_query.rb', line 63 def initialize server = $serverPool[ :jena ].first unless server.ping raise ConnectionFailedError, $!. else @@jena = server @@log.rubinstein "@@jena = #{server.inspect}" end end |
Instance Attribute Details
#language ⇒ Object
allow to set query language
60 61 62 |
# File 'lib/active_rubinstein/jena_query.rb', line 60 def language @language end |
Class Method Details
.execute(query, options) ⇒ Object
analyzes the query to find the correct method to execute
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/active_rubinstein/jena_query.rb', line 78 def execute( query, ) if query.is_a? Symbol or query.is_a? RDFS::Resource case query when :instances_of subject = [ :class ] if subject # 2nd parameter sets the reasoner self.getInstances( subject, false ) end when :parents # the same method is used for both instances and classes, # but the actual method in Java is different subject = [ :subject ] if subject.is_class? then self.getParents( subject ) else self.getInstanceClass( subject ) end when :ancestors subject = [ :subject ] if subject.is_class? then self.getAncestors( subject ) elsif subject.is_a? RDFS::Resource then ancestors = Array.new subject.parents.each do |parent| ancestors << parent ancestors << self.getAncestors( parent ) end return ancestors.flatten end when :children subject = [ :class ] if subject self.getChildren( subject ) end when :descendants subject = [ :class ] if subject self.getDescendants( subject ) end when :roots ontology = [ :ontology ] if ontology self.getRoot( ontology ) end when :classes_within subject = [ :class ] radius = [ :radius ] || 0.2 if subject # 2nd parameter sets the reasoner self.getClassesWithin( subject, radius ) end when :properties then subject = [ :subject ] if subject self.getProperties( subject ) end when :inverse property = [ :property ] if property self.getInverse( property ) end else # construct common SPARQL sparql = ActiveRubinstein::SparqlFormulator.construct( query, ) return self.query( sparql, ) if sparql end elsif query.is_a? Query then @@log.query query.to_sp return self.query( query, ) end end |
.server ⇒ Object
returns the server object
153 154 155 |
# File 'lib/active_rubinstein/jena_query.rb', line 153 def server @@jena end |