Changeset 197
- Timestamp:
- 12/08/08 16:37:02 (5 years ago)
- Location:
- Explorator/trunk
- Files:
-
- 6 modified
-
app/controllers/explorator_controller.rb (modified) (1 diff)
-
app/helpers/explorator_helper.rb (modified) (2 diffs)
-
app/helpers/render_helper.rb (modified) (1 diff)
-
lib/dataload.rb (modified) (2 diffs)
-
lib/query_builder.rb (modified) (6 diffs)
-
public/javascripts/explorator_controller.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Explorator/trunk/app/controllers/explorator_controller.rb
r153 r197 15 15 # attr_accessor :resourceset 16 16 #default rails method. returns the view index.rhtml. 17 def index 17 def index 18 18 19 end 19 20 -
Explorator/trunk/app/helpers/explorator_helper.rb
r156 r197 22 22 if((@filter!=nil)&&(@filter!="")) 23 23 resources = resources.select {|x| 24 25 render_resource(x).to_s().downcase.index(@filter.downcase) != nil}24 25 render_resource(x).to_s().downcase.index(@filter.downcase) != nil} 26 26 @size = resources.size() 27 27 return resources 28 28 end 29 29 resources = resources[@resourceset.offset.to_i,@resourceset.pagination.to_i] 30 resources30 resources 31 31 end 32 32 def subjects(predicate, resource=nil) … … 67 67 classes = Array.new 68 68 resource.type.each do |type| 69 classes << type.localname.downcase 69 70 classes << type.localname.downcase 71 70 72 end 71 classes.uniq.join(' ') << ' ' 73 classes.uniq.join(' ') << ' ' 72 74 end 73 75 #verifies whether the resource is from type class. -
Explorator/trunk/app/helpers/render_helper.rb
r156 r197 19 19 # The heuristic used is the following: 20 20 #If was defined a resource view than render it, else render the first resource type's view. 21 def render_resource (resource) 22 23 21 def render_resource (resource) 24 22 return truncate(resource) if !(resource.instance_of? RDFS::Resource) 25 23 #if a view was defined by the user. -
Explorator/trunk/lib/dataload.rb
r84 r197 25 25 26 26 adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8080/openrdf-sesame/repositories/NOKIA", :results => :sparql_xml, :caching =>true 27 adapter.title='NOKIA_ SPARQL'27 adapter.title='NOKIA_DEFAULT' 28 28 29 29 adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8080/openrdf-sesame/repositories/MONDIAL", :results => :sparql_xml, :caching =>true 30 adapter.title='MONDIAL_ SPARQL'30 adapter.title='MONDIAL_DEFAULT' 31 31 32 32 adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8080/openrdf-sesame/repositories/CIA", :results => :sparql_xml, :caching =>true 33 adapter.title='CIA_ SPARQL'33 adapter.title='CIA_DEFAULT' 34 34 35 35 #adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8087/openrdf-sesame/repositories/METAMODEL", :results => :sparql_xml, :caching =>true … … 37 37 38 38 adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8080/openrdf-sesame/repositories/FACETO", :results => :sparql_xml, :caching =>true 39 adapter.title='FACETO '39 adapter.title='FACETO_DEFAULT' 40 40 #adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://data.linkedmdb.org/sparql", :results => :sparql_xml, :caching =>true 41 41 #adapter.title='IMDB_SPARQL' -
Explorator/trunk/lib/query_builder.rb
r159 r197 15 15 attr_accessor :result 16 16 #constructor. 17 def initialize(s=nil,p=nil,o=nil, *r)17 def initialize(s=nil,p=nil,o=nil,r=nil) 18 18 # initialize the variable query with the ActiveRDF Query 19 19 @result = Array.new … … 35 35 # 36 36 #returns a array of resource. Sometimes the parameter s could be a SemanticExpression instance. 37 def resource_or_self(s )37 def resource_or_self(s,r) 38 38 if s == nil 39 39 Array.new 40 40 elsif s.instance_of? SemanticExpression 41 s.result.collect {|s,p,o| s}.compact.uniq41 s.result.collect {|s,p,o| eval(r.to_s)}.compact.uniq 42 42 elsif s.instance_of? Array 43 43 s … … 52 52 #the same method as query, but it is able to treat arrays. 53 53 #This methos 54 def spo(s,p,o, *r)54 def spo(s,p,o,r=nil) 55 55 result = Array.new 56 s = resource_or_self(s )57 p = resource_or_self(p )58 o = resource_or_self(o )56 s = resource_or_self(s,r) 57 p = resource_or_self(p,r) 58 o = resource_or_self(o,r) 59 59 s.each do |x| 60 60 p.each do |y| … … 74 74 #Wrapper for the class ActiveRDF Query. This method executes a query and returns a set of resources. 75 75 #With parameter must be a single resource. 76 def query(s,p,o, *r)76 def query(s,p,o,r=nil) 77 77 q = Query.new 78 78 if r.to_s == :p.to_s … … 141 141 tmp = SemanticExpression.new.spo(Thread.current[:application].get(s).elements.collect{|s,p,o| eval(r.to_s)}.uniq,:p,:o).result 142 142 else 143 tmp = Thread.current[:application].get(s).elements143 tmp =Thread.current[:application].get(s).elements 144 144 end 145 145 #Intersection method, passed as parameter a triple expression 146 146 else 147 tmp = query(s,p,o,r)147 tmp = query(s,p,o,r) 148 148 end 149 149 #@result = @result & tmp - The intersection is between the subjects and it is not between triples. … … 206 206 end 207 207 return false 208 end 209 def resources(r) 210 self.result.collect {|s,p,o| eval(r.to_s)} 208 211 end 209 212 -
Explorator/trunk/public/javascripts/explorator_controller.js
r141 r197 148 148 view = 'object_view'; 149 149 } 150 ajax_create(new SemanticExpression().spo( new SemanticExpression(':s'), new SemanticExpression(':p'), new SemanticExpression(':o'), parameters.get(':r')) + "&view=" + view);150 ajax_create(new SemanticExpression().spo(':s', ':p', ':o', ':r') + "&view=" + view); 151 151 } 152 152 clear(); … … 187 187 /////////////////////////////// SEMANTIC OPERATIONS ////////////////////////////////////////// 188 188 //These are the operations applyed over triples or semantics annotations 189 function cmd_semantic(){ 190 191 189 function cmd_semantic(){ 192 190 $$('._clear').each(function(item){ 193 191 item.onclick = function(){ … … 281 279 return this; 282 280 }, 283 spo: function(s, p, o, r){ 284 this.expression += '.spo(' + s + ',' + p + ',' + o + ',' + r + ')'; 281 getResourcesArray: function (param){ 282 var a = parameters.get(param); 283 var expression = ''; 284 if (a == undefined) 285 return param; 286 //The parameter could be only one element or several. 287 if (Object.isArray(a)) { 288 expression += a.map(function(x){ 289 var resource = Element.resource(x); 290 if (resource == 'null'){ 291 var exp = x.readAttribute('exp'); 292 if (exp.indexOf (':o,:o')!= -1) 293 { 294 return 'SemanticExpression.new' + encodeURIComponent(exp.replace(":o,:o",':o')) +'.resources(:o)' ; 295 }else if (exp.indexOf (':o,:p') != -1) 296 { 297 return 'SemanticExpression.new' + encodeURIComponent(exp.replace(":o,:p",':o')) +'.resources(:p)' ; 298 }else{ 299 return 'SemanticExpression.new' + encodeURIComponent(exp) +'.resources(:s)' ; 300 } 301 }else{ 302 return "['" + resource + "']" ; 303 } 304 }).join('|'); 305 } 306 return expression ; //returns a array of resources in ruby 307 }, 308 spo: function(s, p, o, r){ 309 this.expression += '.spo(' + this.getResourcesArray(s) + ',' + this.getResourcesArray(p) + ',' + this.getResourcesArray(o) + ',' + parameters.get(r) + ')'; 285 310 return this; 286 311 },
