jekyll-rdf 3.0.0.pre.develop.334 → 3.0.0.pre.develop.343
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-rdf.rb +5 -3
- data/lib/jekyll/drops/rdf_literal.rb +12 -10
- data/lib/jekyll/drops/rdf_resource.rb +213 -210
- data/lib/jekyll/drops/rdf_resource_class.rb +47 -45
- data/lib/jekyll/drops/rdf_statement.rb +32 -30
- data/lib/jekyll/drops/rdf_term.rb +67 -64
- data/lib/jekyll/filters/rdf_collection.rb +13 -14
- data/lib/jekyll/filters/rdf_container.rb +26 -26
- data/lib/jekyll/filters/rdf_get.rb +13 -13
- data/lib/jekyll/filters/rdf_property.rb +75 -76
- data/lib/jekyll/filters/rdf_resolve_prefix.rb +18 -16
- data/lib/jekyll/filters/rdf_sparql_query.rb +41 -42
- data/lib/jekyll/helper/rdf_class_extraction.rb +51 -0
- data/lib/jekyll/helper/rdf_general_helper.rb +26 -22
- data/lib/jekyll/helper/rdf_generator_helper.rb +124 -0
- data/lib/jekyll/helper/rdf_page_helper.rb +59 -0
- data/lib/jekyll/hooks/rdf_page_pointer.rb +1 -1
- data/lib/jekyll/rdf_main_generator.rb +3 -3
- data/lib/jekyll/rdf_page_data.rb +1 -1
- data/lib/jekyll/rdf_template_mapper.rb +1 -1
- metadata +6 -6
- data/lib/jekyll/rdf_class_extraction.rb +0 -47
- data/lib/jekyll/rdf_generator_helper.rb +0 -120
- data/lib/jekyll/rdf_page_helper.rb +0 -54
@@ -24,97 +24,96 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
|
28
|
-
##
|
29
|
-
# Internal module to hold the medthod #rdf_property
|
30
|
-
#
|
31
|
-
module RdfProperty
|
32
|
-
include Jekyll::RdfPrefixResolver
|
27
|
+
module JekyllRdf
|
33
28
|
##
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# * +input+ - is the subject of the statements to be matched
|
37
|
-
# * +predicate+ - is the predicate of the statements to be matched
|
38
|
-
# * +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
|
39
|
-
# * +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.
|
29
|
+
# Internal module to hold the medthod #rdf_property
|
40
30
|
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
31
|
+
module Filter
|
32
|
+
##
|
33
|
+
# Computes all objects for which statements exist containing the given subject and predicate and returns any of them
|
34
|
+
#
|
35
|
+
# * +input+ - is the subject of the statements to be matched
|
36
|
+
# * +predicate+ - is the predicate of the statements to be matched
|
37
|
+
# * +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
|
38
|
+
# * +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.
|
39
|
+
#
|
40
|
+
def rdf_property(input, predicate, lang = nil, list = false)
|
41
|
+
return map_predicate(input, predicate, lang, list)
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
input = Jekyll::RdfHelper::page.data['rdf'] if(input.nil? || input.class <= (Jekyll::RdfPageData))
|
52
|
-
return input unless input.is_a?(Jekyll::Drops::RdfResource)
|
53
|
-
predicate = rdf_resolve_prefix(predicate)
|
54
|
-
result = filter_statements(input.term.to_ntriples, predicate, inverse, lang)
|
55
|
-
return unless !result.empty?
|
56
|
-
if(list)
|
57
|
-
return result
|
58
|
-
else
|
59
|
-
return result.first
|
44
|
+
def rdf_inverse_property(input, predicate, list = false)
|
45
|
+
return map_predicate(input, predicate, nil, list, true)
|
60
46
|
end
|
61
|
-
end
|
62
47
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
48
|
+
private
|
49
|
+
def map_predicate(input, predicate, lang = nil, list = false, inverse = false)
|
50
|
+
input = Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'] if(input.nil? || input.class <= (Jekyll::RdfPageData))
|
51
|
+
return input unless input.is_a?(Jekyll::JekyllRdf::Drops::RdfResource)
|
52
|
+
predicate = rdf_resolve_prefix(predicate)
|
53
|
+
result = filter_statements(input.term.to_ntriples, predicate, inverse, lang)
|
54
|
+
return unless !result.empty?
|
55
|
+
if(list)
|
56
|
+
return result
|
57
|
+
else
|
58
|
+
return result.first
|
59
|
+
end
|
72
60
|
end
|
73
61
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
62
|
+
def filter_statements(n_triples, predicate, inverse = false, lang = nil)
|
63
|
+
client = Jekyll::JekyllRdf::Helper::RdfHelper::sparql
|
64
|
+
query = ""
|
65
|
+
if (lang.eql? 'cfg')
|
66
|
+
lang_query = "FILTER(lang(?o) = '#{Jekyll::JekyllRdf::Helper::RdfHelper::site.config['jekyll_rdf']['language']}')"
|
67
|
+
elsif lang.nil?
|
68
|
+
lang_query = ""
|
69
|
+
else
|
70
|
+
lang_query = "FILTER(lang(?o) = '#{lang}')"
|
79
71
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
72
|
+
|
73
|
+
if(inverse)
|
74
|
+
query = "SELECT ?s WHERE{ ?s <#{predicate}> #{n_triples} }"
|
75
|
+
result = client.query(query).map do |solution|
|
76
|
+
subject = RDF::URI(solution.s)
|
77
|
+
Jekyll::JekyllRdf::Drops::RdfResource.new(subject, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, true)
|
78
|
+
end
|
79
|
+
else
|
80
|
+
query = "SELECT ?o ?dt ?lit ?lang WHERE{ #{n_triples} <#{predicate}> ?o BIND(datatype(?o) AS ?dt) BIND(isLiteral(?o) AS ?lit) BIND(lang(?o) AS ?lang) #{lang_query} }"
|
81
|
+
result = client.query(query).map do |solution|
|
82
|
+
dist_literal_resource(solution)
|
83
|
+
end
|
84
84
|
end
|
85
|
+
return result
|
85
86
|
end
|
86
|
-
return result
|
87
|
-
end
|
88
87
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
88
|
+
##
|
89
|
+
# Distinguishes the solution between an Literal and a Resource
|
90
|
+
#
|
91
|
+
def dist_literal_resource(solution)
|
92
|
+
if solution.lit.true?
|
93
|
+
check = check_solution(solution)
|
94
|
+
object = RDF::Literal(solution.o, language: check[:lang], datatype: RDF::URI(check[:dataType]))
|
95
|
+
result = Jekyll::JekyllRdf::Drops::RdfLiteral.new(object)
|
96
|
+
else
|
97
|
+
object = RDF::URI(solution.o)
|
98
|
+
result = Jekyll::JekyllRdf::Drops::RdfResource.new(object, Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page, true)
|
99
|
+
end
|
100
|
+
return result
|
100
101
|
end
|
101
|
-
return result
|
102
|
-
end
|
103
102
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
103
|
+
##
|
104
|
+
# check what language and datatype the passed literal has
|
105
|
+
#
|
106
|
+
def check_solution(solution)
|
107
|
+
result = {:lang => nil, :dataType => nil}
|
108
|
+
if((solution.bound?(:lang)) && (!solution.lang.to_s.eql?("")))
|
109
|
+
result[:lang] = solution.lang.to_s.to_sym
|
110
|
+
end
|
111
|
+
if(solution.bound? :dt)
|
112
|
+
result[:dataType] = solution.dt
|
113
|
+
end
|
114
|
+
return result
|
114
115
|
end
|
115
|
-
return result
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
Liquid::Template.register_filter(Jekyll::RdfProperty)
|
@@ -24,24 +24,26 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
module
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if(!Jekyll::RdfHelper::page.data["
|
39
|
-
|
27
|
+
module JekyllRdf
|
28
|
+
module Filter
|
29
|
+
private
|
30
|
+
def rdf_resolve_prefix(predicate)
|
31
|
+
if(predicate[0] == "<" && predicate[-1] == ">")
|
32
|
+
return predicate[1..-2]
|
33
|
+
end
|
34
|
+
arr=predicate.split(":",2) #bad regex, would also devide 'http://example....' into 'http' and '//example....',even though it is already a complete URI; if 'PREFIX http: <http://...> is defined, 'http' in 'http://example....' could be mistaken for a prefix
|
35
|
+
if((arr[1].include? (":")) || (arr[1][0..1].eql?("//")))
|
36
|
+
raise UnMarkedUri.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template'])
|
37
|
+
end
|
38
|
+
if(!Jekyll::JekyllRdf::Helper::RdfHelper::page.data["rdf_prefixes"].nil?)
|
39
|
+
if(!Jekyll::JekyllRdf::Helper::RdfHelper::page.data["rdf_prefix_map"][arr[0]].nil?)
|
40
|
+
return arr[1].prepend(Jekyll::JekyllRdf::Helper::RdfHelper::page.data["rdf_prefix_map"][arr[0]])
|
41
|
+
else
|
42
|
+
raise NoPrefixMapped.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template'], arr[0])
|
43
|
+
end
|
40
44
|
else
|
41
|
-
raise
|
45
|
+
raise NoPrefixesDefined.new(predicate, Jekyll::JekyllRdf::Helper::RdfHelper::page.data['template'])
|
42
46
|
end
|
43
|
-
else
|
44
|
-
raise NoPrefixesDefined.new(predicate, Jekyll::RdfHelper::page.data['template'])
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -24,54 +24,53 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
|
28
|
-
##
|
29
|
-
# Internal module to hold the medthod #sparql_query
|
30
|
-
#
|
31
|
-
module RdfSparqlQuery
|
32
|
-
include Jekyll::RdfPrefixResolver
|
27
|
+
module JekyllRdf
|
33
28
|
##
|
34
|
-
#
|
35
|
-
# Returns an Array of bindings. Each binding is a Hash mapping variables to their values.
|
36
|
-
#
|
37
|
-
# * +input+ - the context RDF resource
|
38
|
-
# * +query+ - the SPARQL query
|
29
|
+
# Internal module to hold the medthod #sparql_query
|
39
30
|
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
module Filter
|
32
|
+
|
33
|
+
##
|
34
|
+
# Executes a SPARQL query. The supplied query is augmented by replacing each occurence of '?resourceUri' by the URI of the context RDF resource.
|
35
|
+
# Returns an Array of bindings. Each binding is a Hash mapping variables to their values.
|
36
|
+
#
|
37
|
+
# * +input+ - the context RDF resource
|
38
|
+
# * +query+ - the SPARQL query
|
39
|
+
#
|
40
|
+
def sparql_query(resource = nil, query)
|
41
|
+
if(resource.nil? || resource.class <= (Jekyll::RdfPageData))
|
42
|
+
query.gsub!('?resourceUri', "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term}>")
|
43
|
+
elsif(resource.class <= Array)
|
44
|
+
resource.each_with_index do |uri, index|
|
45
|
+
if(uri.class <= Jekyll::JekyllRdf::Drops::RdfResource)
|
46
|
+
query.gsub!("?resourceUri_#{index}", uri.term.to_ntriples)
|
47
|
+
else
|
48
|
+
query.gsub!("?resourceUri_#{index}", "<#{rdf_resolve_prefix(uri.to_s)}>")
|
49
|
+
end
|
49
50
|
end
|
51
|
+
else
|
52
|
+
query.gsub!('?resourceUri', "<#{resource}>")
|
50
53
|
end
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
if(!Jekyll::RdfHelper::page.data["rdf_prefixes"].nil?)
|
55
|
-
query = query.prepend(" ").prepend(Jekyll::RdfHelper::page.data["rdf_prefixes"])
|
56
|
-
end
|
57
|
-
begin
|
58
|
-
result = Jekyll::RdfHelper::sparql.query(query).map do |solution|
|
59
|
-
hsh = solution.to_h
|
60
|
-
hsh.update(hsh){ |k,v| Jekyll::Drops::RdfTerm.build_term_drop(v, Jekyll::RdfHelper::site, true).add_necessities(Jekyll::RdfHelper::site, Jekyll::RdfHelper::page)}
|
61
|
-
hsh.collect{|k,v| [k.to_s, v]}.to_h
|
54
|
+
if(!Jekyll::JekyllRdf::Helper::RdfHelper::page.data["rdf_prefixes"].nil?)
|
55
|
+
query = query.prepend(" ").prepend(Jekyll::JekyllRdf::Helper::RdfHelper::page.data["rdf_prefixes"])
|
62
56
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
begin
|
58
|
+
result = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution|
|
59
|
+
hsh = solution.to_h
|
60
|
+
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)}
|
61
|
+
hsh.collect{|k,v| [k.to_s, v]}.to_h
|
62
|
+
end
|
63
|
+
return result
|
64
|
+
rescue SPARQL::Client::ClientError => ce
|
65
|
+
Jekyll.logger.error("client error experienced: \n #{query} \n Error Message: #{ce.message}")
|
66
|
+
rescue SPARQL::MalformedQuery => mq
|
67
|
+
Jekyll.logger.error("malformed query found: \n #{query} \n Error Message: #{mq.message}")
|
68
|
+
rescue Exception => e
|
69
|
+
Jekyll.logger.error("unknown Exception of class: #{e.class} in sparql_query \n Query: #{query} \nMessage: #{e.message} \nTrace #{e.backtrace.drop(1).map{|s| "\t#{s}"}.join("\n")}")
|
70
|
+
end
|
71
|
+
return []
|
70
72
|
end
|
71
|
-
return []
|
72
|
-
end
|
73
73
|
|
74
|
+
end
|
74
75
|
end
|
75
76
|
end
|
76
|
-
|
77
|
-
Liquid::Template.register_filter(Jekyll::RdfSparqlQuery)
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module JekyllRdf
|
3
|
+
module Helper
|
4
|
+
module RdfClassExtraction
|
5
|
+
private
|
6
|
+
def search_for_classes(sparql)
|
7
|
+
class_recognition_query = "SELECT DISTINCT ?resourceUri WHERE{ {?resourceUri <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o} UNION{ ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?resourceUri} UNION{ ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?resourceUri}}"
|
8
|
+
class_search_results = sparql.query(class_recognition_query).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals
|
9
|
+
s.class <= RDF::Literal
|
10
|
+
end.select do |s| # Select URIs and blank nodes in case of include_blank
|
11
|
+
s.class <=RDF::Node || s.class <= RDF::URI
|
12
|
+
end
|
13
|
+
return class_search_results
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_resource_class(class_search_results, sparql)
|
17
|
+
class_search_results.each do |uri|
|
18
|
+
@classResources[uri.to_s]=Jekyll::JekyllRdf::Drops::RdfResourceClass.new(uri, sparql)
|
19
|
+
end
|
20
|
+
|
21
|
+
@classResources.each{|key, value|
|
22
|
+
value.find_direct_subclasses.each{|s|
|
23
|
+
value.add_subclass(@classResources[s])
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def assign_class_templates(classes_to_templates)
|
29
|
+
if(classes_to_templates.is_a?(Hash))
|
30
|
+
@classResources.default = StopObject.new
|
31
|
+
classes_to_templates.each{|key, value|
|
32
|
+
@classResources[key].propagate_template(value,0)
|
33
|
+
@classResources[key].traverse_hierarchy_value(0);
|
34
|
+
}
|
35
|
+
@classResources.default = nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration
|
40
|
+
def propagate_template(template, lock)
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
def traverse_hierarchy_value(predecessorHierarchyValue)
|
45
|
+
return
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -23,33 +23,37 @@
|
|
23
23
|
#
|
24
24
|
|
25
25
|
module Jekyll
|
26
|
+
module JekyllRdf
|
27
|
+
module Helper
|
28
|
+
##
|
29
|
+
# Internal module to hold support for functionalities like submitting sparql queries
|
30
|
+
#
|
31
|
+
module RdfHelper
|
32
|
+
def self.sparql= sparql
|
33
|
+
@@sparql = sparql
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
module RdfHelper
|
31
|
-
def self.sparql= sparql
|
32
|
-
@@sparql = sparql
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.sparql
|
36
|
-
@@sparql
|
37
|
-
end
|
36
|
+
def self.sparql
|
37
|
+
@@sparql
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def self.site= site
|
41
|
+
@@site = site
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def self.site
|
45
|
+
@@site
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def self.page= page
|
49
|
+
@@page = page
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def self.page
|
53
|
+
@@page
|
54
|
+
end
|
55
|
+
end
|
53
56
|
end
|
57
|
+
|
54
58
|
end
|
55
59
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module JekyllRdf
|
3
|
+
module Helper
|
4
|
+
module RdfGeneratorHelper
|
5
|
+
private
|
6
|
+
def prepare_pages (site, mapper)
|
7
|
+
@pageResources.each{|uri, entry|
|
8
|
+
resource = entry.delete('./')
|
9
|
+
resource.subResources = entry
|
10
|
+
create_page(site, resource, mapper, @global_config)
|
11
|
+
}
|
12
|
+
|
13
|
+
@blanknodes.each{|resource|
|
14
|
+
create_page(site, resource, mapper, @global_config)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_resources (resources)
|
19
|
+
@pageResources={};
|
20
|
+
@blanknodes=[]
|
21
|
+
resources.each do |uri|
|
22
|
+
resource = Jekyll::JekyllRdf::Drops::RdfResource.new(uri)
|
23
|
+
if(uri.instance_of? RDF::URI)
|
24
|
+
uriString = uri.to_s
|
25
|
+
if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a #
|
26
|
+
preSufUri = uriString.split("#")
|
27
|
+
if(!@pageResources.key? preSufUri[0])
|
28
|
+
@pageResources[preSufUri[0]] = {}
|
29
|
+
end
|
30
|
+
@pageResources[preSufUri[0]][preSufUri[1]] = resource
|
31
|
+
else #sorting in uris without a #
|
32
|
+
if(!@pageResources.key? uriString)
|
33
|
+
@pageResources[uriString]={}
|
34
|
+
end
|
35
|
+
@pageResources[uriString]['./'] = resource
|
36
|
+
end
|
37
|
+
elsif(uri.instance_of? RDF::Node)
|
38
|
+
@blanknodes << resource
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# give parents to orphaned resources
|
42
|
+
@pageResources.each_key{|key|
|
43
|
+
@pageResources[key]['./'] = Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(key)) if @pageResources[key]['./'].nil?
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_config (site)
|
48
|
+
begin
|
49
|
+
@config = site.config.fetch('jekyll_rdf')
|
50
|
+
rescue KeyError => e
|
51
|
+
Jekyll.logger.error("You've included Jekyll-RDF, but it is not configured. Aborting the jekyll-rdf plugin.")
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
|
55
|
+
@global_config = Jekyll.configuration({})
|
56
|
+
|
57
|
+
#small fix because global_config doesn't work in a test enviorment
|
58
|
+
if(!@global_config.key? "url")
|
59
|
+
@global_config["url"] = site.config["url"]
|
60
|
+
@global_config["baseurl"] = site.config["baseurl"]
|
61
|
+
end
|
62
|
+
return true
|
63
|
+
end
|
64
|
+
##
|
65
|
+
# #extract_resources returns resources from an RDF Sparql endpoint.
|
66
|
+
#
|
67
|
+
# Literals are omitted.
|
68
|
+
# Blank nodes are only returned if +include_blank+ is true.
|
69
|
+
# Duplicate nodes are removed.
|
70
|
+
#
|
71
|
+
# * +selection+ - choose any of the following:
|
72
|
+
# nil ::
|
73
|
+
# no restrictions, return subjects, predicates, objects
|
74
|
+
# "subjects" ::
|
75
|
+
# return only subjects
|
76
|
+
# "predicates" ::
|
77
|
+
# return only predicates
|
78
|
+
# "objects" ::
|
79
|
+
# return only objects
|
80
|
+
# Otherwise ::
|
81
|
+
# consider +selection+ to be a SPARQL query and return answer set to this SPARQL query
|
82
|
+
# * +include_blank+ - If true, blank nodes are also returned, otherwise blank nodes are omitted
|
83
|
+
# * +sparql+ - The SPARQL client to run queries against
|
84
|
+
#
|
85
|
+
def extract_resources(selection, include_blank, sparql)
|
86
|
+
|
87
|
+
case selection
|
88
|
+
when nil # Config parameter not present
|
89
|
+
object_resources = extract_resources("objects", include_blank, sparql)
|
90
|
+
subject_resources = extract_resources("subjects", include_blank, sparql)
|
91
|
+
predicate_resources = extract_resources("predicates", include_blank, sparql)
|
92
|
+
return object_resources.concat(subject_resources).concat(predicate_resources).uniq
|
93
|
+
when "objects"
|
94
|
+
query = "SELECT ?resourceUri WHERE{?s ?p ?resourceUri}"
|
95
|
+
when "subjects"
|
96
|
+
query = "SELECT ?resourceUri WHERE{?resourceUri ?p ?o}"
|
97
|
+
when "predicates"
|
98
|
+
query = "SELECT ?resourceUri WHERE{?s ?resourceUri ?o}"
|
99
|
+
else
|
100
|
+
# Custom query
|
101
|
+
query = selection
|
102
|
+
end
|
103
|
+
sparql.query(query).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals
|
104
|
+
s.class <= RDF::Literal
|
105
|
+
end.select do |s| # Select URIs and blank nodes in case of include_blank
|
106
|
+
include_blank || s.class == RDF::URI
|
107
|
+
end.uniq
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_page(site, resource, mapper, global_config)
|
111
|
+
page = RdfPageData.new(site, site.source, resource, mapper, global_config)
|
112
|
+
if(page.complete)
|
113
|
+
site.pages << page
|
114
|
+
resource.add_necessities(site, page)
|
115
|
+
resource.subResources.each {|key, value|
|
116
|
+
value.add_necessities(site, page)
|
117
|
+
} unless resource.subResources.nil?
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|