module PubliSci::Query

.gsub(/^s+/,”)

Public Instance Methods

execute(string,store,type=:fourstore) click to toggle source

def execute_internal(query,repo)

SPARQL.execute(query,repo)

end

# File lib/publisci/query/query_helper.rb, line 39
def execute(string,store,type=:fourstore)
                    if store.is_a?(PubliSci::Store) || store.is_a?(RDF::FourStore)
                            sparql = SPARQL::Client.new(store.url+"/sparql/")
  elsif type == :graph || store.is_a?(RDF::Graph) || store.is_a?(RDF::Repository)
    sparql = SPARQL::Client.new(store)
                    elsif type == :fourstore
                            sparql = SPARQL::Client.new(store+"/sparql/")
  end
  sparql.query(string)
end
execute_from_file(file,store,type=:fourstore,substitutions={}) click to toggle source
# File lib/publisci/query/query_helper.rb, line 50
def execute_from_file(file,store,type=:fourstore,substitutions={})
  if Gem::Dependency.new('publisci').matching_specs.size > 0
    queries_dir = Gem::Specification.find_by_name("publisci").gem_dir + "/resources/queries/"
  else
    queries_dir = File.dirname(__FILE__) + '/../../../resources/queries/'
  end
  if File.exist?(file)
    string = IO.read(file)
  elsif File.exist?(queries_dir + file)
    string = IO.read(queries_dir + file)
  elsif File.exist?(queries_dir + file + '.rq')
    string = IO.read(queries_dir + file + '.rq')
  else
    raise "couldn't find query for #{file}"
  end

  substitutions.map{|k,v|
    string = string.gsub(k,v)
  }
    execute(string, store, type)
end
property_names(var) click to toggle source

Currently will say “_ Component”, needs further parsing

# File lib/publisci/query/query_helper.rb, line 108
    def property_names(var)
      str = prefixes
      str << <<-EOS
SELECT DISTINCT ?label WHERE {
  ns:dsd-#{var} qb:component ?c .
  ?c rdfs:label ?label
}
      EOS
    end
property_values(var, property) click to toggle source
EOF

end

# File lib/publisci/query/query_helper.rb, line 85
    def property_values(var, property)
      str = prefixes
      str << <<-EOS
SELECT ?val WHERE {
  ?obs qb:dataSet ns:dataset-#{var} ;
      prop:#{property} ?val ;
}
      EOS
      str
    end
row_names(var) click to toggle source
# File lib/publisci/query/query_helper.rb, line 96
    def row_names(var)
      str = prefixes
      str << <<-EOS
SELECT ?label WHERE {
  ?obs qb:dataSet ns:dataset-#{var} ;
       prop:refRow ?row .
  ?row skos:prefLabel ?label .
}
      EOS
    end
vocabulary() click to toggle source
# File lib/publisci/query/query_helper.rb, line 22
def vocabulary
  {
    base: RDF::Vocabulary.new('<http://www.rqtl.org/ns/#>'),
    qb:   RDF::Vocabulary.new("http://purl.org/linked-data/cube#"),
    rdf:  RDF::Vocabulary.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),
    rdfs: RDF::Vocabulary.new('http://www.w3.org/2000/01/rdf-schema#'),
    prop: RDF::Vocabulary.new('http://www.rqtl.org/dc/properties/'),
    cs:   RDF::Vocabulary.new('http://www.rqtl.org/dc/cs')
  }
end