Class: RDF::Smart
- Inherits:
-
Object
- Object
- RDF::Smart
- Defined in:
- lib/rdf/smart.rb,
ext/rsm.c
Overview
Creates a RDF::Smart Object.
Constant Summary collapse
- VERSION =
Equals the current version number
rb_str_new2(RSM_VERSION)
Instance Method Summary collapse
-
#data_sources ⇒ Object
Returns an array, containing all
data_sources. -
#execute(query) ⇒ Object
Executes a
query. -
#initialize(*args) ⇒ Object
constructor
Creates a new RDF::Smart object.
-
#namespaces ⇒ Object
This method returns a hash containing all key value pairs of
namespacesfound indata_sources. -
#version ⇒ Object
Returns the currently used version of rdf-smart.
Constructor Details
#initialize(*args) ⇒ Object
Creates a new RDF::Smart object.
Parameter args can be zero to n strings of filenames.
Parameter args will be saved as data_sources.
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'ext/rsm.c', line 345
VALUE rsm_initialize(int argc, VALUE *argv, VALUE self) {
int i;
rsm_obj *prsm_obj;
Data_Get_Struct(self, rsm_obj, prsm_obj);
prsm_obj->data_sources = rb_ary_new();
for (i=0; i<argc; i++) {
if (TYPE(argv[i]) == T_STRING)
rb_ary_push(prsm_obj->data_sources,argv[i]);
}
return self;
}
|
Instance Method Details
#data_sources ⇒ Object
Returns an array, containing all data_sources
327 328 329 330 331 |
# File 'ext/rsm.c', line 327
VALUE rsm_data_sources(VALUE self) {
rsm_obj *prsm_obj;
Data_Get_Struct(self, rsm_obj, prsm_obj);
return(prsm_obj->data_sources);
}
|
#execute(query) ⇒ Object
Executes a query. query is a string.
An Error is raised if a data_source does not exist
A JSON Object will be returned.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rdf/smart.rb', line 18 def execute(query) #{{{ data_sources.each do |s| raise 'BlaBlaBla' unless File.exists?(s) end ## # +res+ is the returned value. if query.lstrip.downcase['prefix'] == nil namespaces.each do |k,v| query = "prefix #{k}: <#{v}> " +query end end (res = JSON::parse(__execute(query)))['results']['bindings'].each do |solution| solution.each do |k,v| catch :done do ## # Convert Strings into the right datatype. ## # Add +pvalue+ into returned Value. +pvalue+ contains the real value without namespaces. case v['datatype'] when 'http://www.w3.org/2001/XMLSchema#integer', 'http://www.w3.org/2001/XMLSchema#long', 'http://www.w3.org/2001/XMLSchema#int', 'http://www.w3.org/2001/XMLSchema#short', 'http://www.w3.org/2001/XMLSchema#long', 'http://www.w3.org/2001/XMLSchema#nonPositiveInteger', 'http://www.w3.org/2001/XMLSchema#negativeInteger', 'http://www.w3.org/2001/XMLSchema#nonNegativeInteger', 'http://www.w3.org/2001/XMLSchema#positiveInteger', 'http://www.w3.org/2001/XMLSchema#unsignedLong', 'http://www.w3.org/2001/XMLSchema#unsignedInt', 'http://www.w3.org/2001/XMLSchema#unsignedShort' v['ns'] = v['datatype'] v['pvalue'] = v['value'].to_i throw :done when 'http://www.w3.org/2001/XMLSchema#float', 'http://www.w3.org/2001/XMLSchema#decimal', 'http://www.w3.org/2001/XMLSchema#double' v['ns'] = v['datatype'] v['pvalue'] = v['value'].to_f throw :done when 'http://www.w3.org/2001/XMLSchema#boolean' v['ns'] = v['datatype'] v['pvalue'] = v['value'] == 'true' ? true : false throw :done when 'http://www.w3.org/2001/XMLSchema#notation', 'http://www.w3.org/2001/XMLSchema#qname' v['ns'] = v['datatype'] v['pvalue'] = v['value'] throw :done when nil else v['ns'] = v['datatype'] v['pvalue'] = v['value'] throw :done end if v.length == 2 && v['value'] && v['type'] == 'literal' v['datatype'] = 'http://www.w3.org/2001/XMLSchema#string' v['ns'] = v['datatype'] v['pvalue'] = v['value'] throw :done end if v['value'] == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' v['ns'] = v['value'] v['pvalue'] = 'a' throw :done end namespaces.each do |kk, vv| if v['value'].start_with?(vv) v['ns'] = vv v['pvalue'] = v['value'].sub(vv,'') throw :done end end end end end res #}}} end |
#namespaces ⇒ Object
This method returns a hash containing all key value pairs of namespaces found in data_sources
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'ext/rsm.c', line 185
VALUE rsm_namespaces(VALUE self) {
rsm_obj *prsm_obj;
int i;
Data_Get_Struct(self, rsm_obj, prsm_obj);
VALUE namespaces = rb_hash_new();
for (i = 0; i < RARRAY_LEN(prsm_obj->data_sources); i++) {
const char* data_source = RSTRING_PTR(RARRAY_PTR(prsm_obj->data_sources)[i]);
rsm_get_namespaces(namespaces,(unsigned char *)data_source);
}
return namespaces;
}
|
#version ⇒ Object
Returns the currently used version of rdf-smart.
85 86 87 |
# File 'lib/rdf/smart.rb', line 85 def version VERSION end |