Method: ActiveRubinstein::JenaQuery.execute
- Defined in:
- lib/active_rubinstein/jena_query.rb
.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 |