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, line 57 def _pprint(l) col = l.map{ |x| x.length }.max + 3 # [len(x) for x in l]) + 3 padded = l.map{|x| x.ljust(col) } #.join('') #print textwrap(padded).join('\n') line = '' num = 70 padded.each{|x| line.length < num ? line+=x : begin puts line; line=x end } 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, line 38 def _uri_to_name(uri) usplit = URI(uri) #urlsplit(uri) if usplit.fragment != nil return usplit.fragment else #return pathsplit(usplit.path)[-1] return usplit.path.split('/')[-1] end 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, line 73 def get_value_for_URI(sd, uri, predicate) result = nil query = "SELECT * WHERE { <#{uri}> <#{predicate}> ?x }" begin qj = SPARQL.new(sd, query) #puts "qj.json = " + str(qj.json) result = qj.json['results']['bindings'][0]['x']['value'] rescue #pass end return result end