Module: PubliSci::Query

Included in:
DataSet::ORM::DataCube, DataSet::ORM::DataCube, QueryHelper, Readers::Base, Store, Writers::Base
Defined in:
lib/publisci/query/query_helper.rb

Overview

.gsub(/^s+/,”)

Instance Method Summary collapse

Instance Method Details

#execute(string, store, type = :fourstore) ⇒ Object

def execute_internal(query,repo)

SPARQL.execute(query,repo)

end



39
40
41
42
43
44
45
46
47
48
# 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 = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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) ⇒ Object

Currently will say “_ Component”, needs further parsing



108
109
110
111
112
113
114
115
116
# 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) ⇒ Object

EOF

end


85
86
87
88
89
90
91
92
93
94
# 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) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# 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

#vocabularyObject



22
23
24
25
26
27
28
29
30
31
# 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