Changeset 197

Show
Ignore:
Timestamp:
12/08/08 16:37:02 (5 years ago)
Author:
samuraraujo
Message:
 
Location:
Explorator/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • Explorator/trunk/app/controllers/explorator_controller.rb

    r153 r197  
    1515  # attr_accessor :resourceset 
    1616  #default rails method. returns the view index.rhtml. 
    17   def index         
     17  def index      
     18  
    1819end 
    1920  
  • Explorator/trunk/app/helpers/explorator_helper.rb

    r156 r197  
    2222    if((@filter!=nil)&&(@filter!="")) 
    2323      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} 
    2626      @size = resources.size() 
    2727      return resources 
    2828    end 
    2929    resources = resources[@resourceset.offset.to_i,@resourceset.pagination.to_i] 
    30   resources 
     30    resources 
    3131  end 
    3232  def subjects(predicate, resource=nil) 
     
    6767    classes = Array.new       
    6868    resource.type.each do |type| 
    69       classes <<   type.localname.downcase 
     69       
     70        classes <<   type.localname.downcase 
     71      
    7072    end     
    71     classes.uniq.join(' ') << ' ' 
     73    classes.uniq.join(' ') << ' '     
    7274  end 
    7375  #verifies whether the resource is from type class. 
  • Explorator/trunk/app/helpers/render_helper.rb

    r156 r197  
    1919  # The heuristic used is the following: 
    2020  #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)        
    2422    return truncate(resource) if !(resource.instance_of? RDFS::Resource)      
    2523    #if a view was defined by the user.         
  • Explorator/trunk/lib/dataload.rb

    r84 r197  
    2525 
    2626adapter =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' 
     27adapter.title='NOKIA_DEFAULT' 
    2828 
    2929adapter =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' 
     30adapter.title='MONDIAL_DEFAULT' 
    3131 
    3232adapter =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' 
     33adapter.title='CIA_DEFAULT' 
    3434 
    3535#adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://localhost:8087/openrdf-sesame/repositories/METAMODEL", :results => :sparql_xml, :caching =>true 
     
    3737 
    3838adapter =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' 
     39adapter.title='FACETO_DEFAULT' 
    4040#adapter =ConnectionPool.add_data_source :type => :sparql,:engine => :sesame2, :url => "http://data.linkedmdb.org/sparql", :results => :sparql_xml, :caching =>true 
    4141#adapter.title='IMDB_SPARQL' 
  • Explorator/trunk/lib/query_builder.rb

    r159 r197  
    1515  attr_accessor  :result   
    1616  #constructor. 
    17   def initialize(s=nil,p=nil,o=nil,*r)     
     17  def initialize(s=nil,p=nil,o=nil,r=nil)     
    1818    # initialize the variable query with the ActiveRDF Query 
    1919    @result = Array.new     
     
    3535  # 
    3636  #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) 
    3838    if s == nil 
    3939      Array.new  
    4040    elsif s.instance_of? SemanticExpression 
    41       s.result.collect {|s,p,o| s}.compact.uniq 
     41      s.result.collect {|s,p,o| eval(r.to_s)}.compact.uniq 
    4242    elsif s.instance_of? Array 
    4343      s 
     
    5252  #the same method as query, but it is able to treat arrays. 
    5353  #This methos 
    54   def spo(s,p,o,*r)       
     54  def spo(s,p,o,r=nil)       
    5555    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) 
    5959    s.each do |x| 
    6060      p.each do |y| 
     
    7474  #Wrapper for the class ActiveRDF Query. This method executes a query and returns a set of resources. 
    7575  #With parameter must be a single resource. 
    76   def query(s,p,o,*r)        
     76  def query(s,p,o,r=nil)        
    7777    q = Query.new     
    7878    if r.to_s == :p.to_s 
     
    141141        tmp = SemanticExpression.new.spo(Thread.current[:application].get(s).elements.collect{|s,p,o| eval(r.to_s)}.uniq,:p,:o).result 
    142142      else 
    143         tmp =  Thread.current[:application].get(s).elements 
     143        tmp =Thread.current[:application].get(s).elements 
    144144      end 
    145145      #Intersection method, passed as parameter a triple expression 
    146146    else 
    147       tmp =  query(s,p,o,r) 
     147      tmp = query(s,p,o,r) 
    148148    end 
    149149    #@result = @result & tmp - The intersection is between the subjects and it is not between triples. 
     
    206206    end 
    207207    return false 
     208  end 
     209  def resources(r) 
     210    self.result.collect {|s,p,o| eval(r.to_s)} 
    208211  end 
    209212   
  • Explorator/trunk/public/javascripts/explorator_controller.js

    r141 r197  
    148148                                view = 'object_view'; 
    149149                        }  
    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); 
    151151                }                   
    152152          clear(); 
     
    187187/////////////////////////////// SEMANTIC OPERATIONS ////////////////////////////////////////// 
    188188//These are the operations applyed over triples or semantics annotations 
    189 function cmd_semantic(){ 
    190      
    191      
     189function cmd_semantic(){     
    192190         $$('._clear').each(function(item){ 
    193191        item.onclick = function(){ 
     
    281279        return this; 
    282280    }, 
    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) + ')'; 
    285310        return this; 
    286311    },