class Object
Public Instance Methods
_pprint(l)
click to toggle source
Formats a list l to be displayed in a tabular layout. It is possible to pass an integer width to the textwrap function. The width of the terminal window could be obtained via the Python console module. However, since it is not included in Jas, we decided not to use it. The default width that textwrap uses is set to 70. There might be a better way to do this.
# File examples/sdjas.rb 57 def _pprint(l) 58 col = l.map{ |x| x.length }.max + 3 # [len(x) for x in l]) + 3 59 padded = l.map{|x| x.ljust(col) } #.join('') 60 #print textwrap(padded).join('\n') 61 line = '' 62 num = 70 63 padded.each{|x| line.length < num ? line+=x : begin puts line; line=x end } 64 end
_uri_to_name(uri)
click to toggle source
Converts a uri to a name or key by only taking everything after the last / or (if present) #.
Examples:
http://example.com/test -> test http://example.com/model#testedBy -> testedBy
# File examples/sdjas.rb 38 def _uri_to_name(uri) 39 usplit = URI(uri) #urlsplit(uri) 40 if usplit.fragment != nil 41 return usplit.fragment 42 else 43 #return pathsplit(usplit.path)[-1] 44 return usplit.path.split('/')[-1] 45 end 46 end
get_value_for_URI(sd, uri, predicate)
click to toggle source
A quick convienience function to retrieve a single value of a given triple (object, predicate, …)
The parameter sd is a SymbolicData
object that contains information about the SPARQL
endpoint.
# File examples/sdjas.rb 73 def get_value_for_URI(sd, uri, predicate) 74 result = nil 75 query = "SELECT * WHERE { <#{uri}> <#{predicate}> ?x }" 76 begin 77 qj = SPARQL.new(sd, query) 78 #puts "qj.json = " + str(qj.json) 79 result = qj.json['results']['bindings'][0]['x']['value'] 80 rescue 81 #pass 82 end 83 return result 84 end