Module: PubliSci::Query

Included in:
ORM::DataCube, ORM::DataCube, QueryHelper, Store, Writer::ARFF
Defined in:
lib/bio-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/bio-publisci/query/query_helper.rb', line 39

def execute(string,store,type=:fourstore)
	if type == :graph || store.is_a?(RDF::Graph) || store.is_a?(RDF::Repository)
sparql = SPARQL::Client.new(store)
			elsif store.is_a? PubliSci::Store
sparql = SPARQL::Client.new(store.url+"/sparql/")
			elsif type == :fourstore
sparql = SPARQL::Client.new(store+"/sparql/")
  end
  sparql.query(string)
end

#execute_from_file(file, store, type = :fourstore) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bio-publisci/query/query_helper.rb', line 50

def execute_from_file(file,store,type=:fourstore)
  if File.exist?(file)
    string = IO.read(file)
  elsif File.exist?(File.dirname(__FILE__) + '/../../../resources/queries/' + file)
    string = IO.read(File.dirname(__FILE__) + '/../../../resources/queries/' + file)
  elsif File.exist?(File.dirname(__FILE__) + '/../../../resources/queries/' + file + '.rq')
    string = IO.read(File.dirname(__FILE__) + '/../../../resources/queries/' + file + '.rq')
  else
    raise "couldn't find query for #{file}"
  end
	execute(string, store, type)
end

#property_names(var) ⇒ Object

Currently will say “_ Component”, needs further parsing



99
100
101
102
103
104
105
106
107
# File 'lib/bio-publisci/query/query_helper.rb', line 99

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


76
77
78
79
80
81
82
83
84
85
# File 'lib/bio-publisci/query/query_helper.rb', line 76

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



87
88
89
90
91
92
93
94
95
96
# File 'lib/bio-publisci/query/query_helper.rb', line 87

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/bio-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