Module: Jekyll::JekyllRdf::Filter
- Includes:
- Helper::FilterHelper, Helper::PrefixSolver
- Defined in:
- lib/jekyll/filters/rdf_get.rb,
lib/jekyll/filters/rdf_property.rb,
lib/jekyll/filters/rdf_container.rb,
lib/jekyll/filters/rdf_collection.rb,
lib/jekyll/filters/rdf_sparql_query.rb,
lib/jekyll/helper/rdf_filter_helper.rb,
lib/jekyll/filters/rdf_debug_message.rb
Overview
Internal module to hold the medthod #rdf_message
Instance Method Summary collapse
- #rdf_collection(input, predicate = nil) ⇒ Object
- #rdf_container(input, predicate = nil) ⇒ Object
-
#rdf_debug_message(message, logLevel = "info") ⇒ Object
:nodoc:.
- #rdf_get(request_uri) ⇒ Object
- #rdf_inverse_property(input, predicate, list = false) ⇒ Object
-
#rdf_property(input, predicate, lang = nil, list = false) ⇒ Object
Computes all objects for which statements exist containing the given subject and predicate and returns any of them.
-
#sparql_query(resource = nil, query) ⇒ Object
Executes a SPARQL query.
Instance Method Details
#rdf_collection(input, predicate = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jekyll/filters/rdf_collection.rb', line 30 def rdf_collection(input, predicate = nil) input = rdf_page_to_resource(input) return unless valid_resource?(input) input = to_string_wrap(input) query = "SELECT ?f WHERE{ #{input} " << (predicate.nil? ? "" : " #{rdf_resolve_prefix(predicate)} ?coll . ?coll ") << " <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>* ?r. ?r <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> ?f}" results = [] Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).each{ |solution| results.push Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(solution.f, Jekyll::JekyllRdf::Helper::RdfHelper::site, true).add_necessities(Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page) } return results end |
#rdf_container(input, predicate = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jekyll/filters/rdf_container.rb', line 29 def rdf_container(input, predicate = nil) input = rdf_page_to_resource(input) return unless valid_resource?(input) sparql_client = Jekyll::JekyllRdf::Helper::RdfHelper::sparql n_triples = to_string_wrap(input) query = "SELECT ?p ?o WHERE{ #{n_triples} " << (predicate.nil? ? "" : " #{rdf_resolve_prefix(predicate)} ?container . ?container ") << " ?p ?o #{query_additions()}" solutions = sparql_client.query(query).each_with_object([]) {|solution, array| if(/^http:\/\/www\.w3\.org\/1999\/02\/22-rdf-syntax-ns#_\d+$/.match(solution.p.to_s)) array << Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(solution.o, Jekyll::JekyllRdf::Helper::RdfHelper::site, true).add_necessities(Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page) end } return solutions end |
#rdf_debug_message(message, logLevel = "info") ⇒ Object
:nodoc:
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jekyll/filters/rdf_debug_message.rb', line 9 def (, logLevel = "info") #:nodoc: case logLevel when "info" Jekyll.logger.info when "warn" Jekyll.logger.warn when "error" Jekyll.logger.error when "debug" Jekyll.logger.debug else Jekyll.logger.info "NoLevel: #{}" end end |
#rdf_get(request_uri) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/jekyll/filters/rdf_get.rb', line 34 def rdf_get(request_uri) return request_uri if request_uri.class <= Jekyll::JekyllRdf::Drops::RdfResource request_uri = to_string_wrap(rdf_page_to_resource(request_uri)) return unless valid_resource?(request_uri) && (!request_uri[0..1].eql? "_:") request_uri = rdf_resolve_prefix(request_uri) Jekyll::JekyllRdf::Helper::RdfHelper.resources(request_uri[1..-2]) end |
#rdf_inverse_property(input, predicate, list = false) ⇒ Object
44 45 46 |
# File 'lib/jekyll/filters/rdf_property.rb', line 44 def rdf_inverse_property(input, predicate, list = false) return map_predicate(input, predicate, nil, list, true) end |
#rdf_property(input, predicate, lang = nil, list = false) ⇒ Object
Computes all objects for which statements exist containing the given subject and predicate and returns any of them
-
input
- is the subject of the statements to be matched -
predicate
- is the predicate of the statements to be matched -
lang
- (optional) preferred language of a the returned object. The precise implementation of choosing which object to return (both in case a language is supplied and in case is not supplied) is undefined -
list
- (optional) decides the format of the return value. If set to true it returns an array, otherwise it returns a singleton String containing a URI.
40 41 42 |
# File 'lib/jekyll/filters/rdf_property.rb', line 40 def rdf_property(input, predicate, lang = nil, list = false) return map_predicate(input, predicate, lang, list) end |
#sparql_query(resource = nil, query) ⇒ Object
Executes a SPARQL query. The supplied query is augmented by replacing each occurence of ‘?resourceUri’ by the URI of the context RDF resource. Returns an Array of bindings. Each binding is a Hash mapping variables to their values.
-
input
- the context RDF resource -
query
- the SPARQL query
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 |
# File 'lib/jekyll/filters/rdf_sparql_query.rb', line 40 def sparql_query(resource = nil, query) query = prepare_query(resource, query) return if query.nil? begin result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query) if (result.class == RDF::Graph) return Jekyll::JekyllRdf::Drops::RdfGraph.new(result) end result.map! do |solution| hsh = solution.to_h hsh.update(hsh){ |k,v| Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(v, Jekyll::JekyllRdf::Helper::RdfHelper::site, true).add_necessities(Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page)} hsh.collect{|k,v| [k.to_s, v]}.to_h end return result rescue SPARQL::Client::ClientError => ce Jekyll.logger.error("client error experienced: \n #{query} \n Error Message: #{ce.}") raise if Jekyll.env.eql? "development" rescue SPARQL::MalformedQuery => mq Jekyll.logger.error("malformed query found: \n #{query} \n Error Message: #{mq.}") raise if Jekyll.env.eql? "development" rescue Exception => e Jekyll.logger.error("unknown Exception of class: #{e.class} in sparql_query \n Query: #{query} \nMessage: #{e.} \nTrace #{e.backtrace.drop(1).map{|s| "\t#{s}"}.join("\n")}") raise if Jekyll.env.eql? "development" end return [] end |