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.
@@ -0,0 +1,59 @@
1
+ module Jekyll
2
+ module JekyllRdf
3
+ module Helper
4
+ module RdfPageHelper
5
+ private
6
+ ##
7
+ # sets @template to the path of a fitting layout
8
+ # it will set @complete to false if no fitting template is found
9
+ # * +resource+ - the resource that will be mapped to a template
10
+ # * +mapper+ - the mapper that provides the resource mappings
11
+ def map_template(resource, mapper)
12
+ @template = mapper.map(resource)
13
+ if(@template.nil?)
14
+ Jekyll.logger.warn("Resource #{resource} not rendered: No fitting template or default template found.")
15
+ @complete = false
16
+ end
17
+ end
18
+
19
+ ##
20
+ # loads the data from the yaml-frontmatter and extends page.data with three key value pairs:
21
+ # -title -> contains the resource.iri
22
+ # -rdf -> contains the resource itself
23
+ # -template -> contains the path to the currenly used template
24
+ def load_data(site)
25
+ self.read_yaml(File.join(@base, '_layouts'), @template)
26
+ self.data['title'] = @resource.iri
27
+ self.data['rdf'] = @resource
28
+ self.data['template'] = @template
29
+ if(!@resource.subResources.nil?)
30
+ self.data['sub_rdf'] = @resource.subResources.values
31
+ self.data['sub_rdf'].each { |res|
32
+ res.page = self
33
+ res.site = site
34
+ }
35
+ end
36
+ end
37
+
38
+ ##
39
+ # loads the prefix data passed in the layout yaml-frontmatter into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"]
40
+ def load_prefixes
41
+ if !self.data["rdf_prefix_path"].nil?
42
+ begin
43
+ prefix_file=File.new(File.join(@base, 'rdf-data', self.data["rdf_prefix_path"].strip)).readlines
44
+ self.data["rdf_prefixes"] = prefix_file.join(" ")
45
+ self.data["rdf_prefix_map"] = Hash[ *(prefix_file.collect { |v|
46
+ arr = v.split(":",2)
47
+ [arr[0][7..-1].strip, arr[1].strip[1..-2]]
48
+ }.flatten)]
49
+ rescue Errno::ENOENT => ex
50
+ Jekyll.logger.error("context: #{@resource} template: #{@template} file not found: #{File.join(@base, 'rdf-data', self.data["rdf_prefix_path"])}")
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+
@@ -24,5 +24,5 @@
24
24
 
25
25
 
26
26
  Jekyll::Hooks.register :pages, :pre_render do |page|
27
- Jekyll::RdfHelper::page = page
27
+ Jekyll::JekyllRdf::Helper::RdfHelper::page = page
28
28
  end
@@ -32,7 +32,7 @@ module Jekyll
32
32
  class RdfMainGenerator < Jekyll::Generator
33
33
  safe true
34
34
  priority :highest
35
- include Jekyll::RdfGeneratorHelper
35
+ include Jekyll::JekyllRdf::Helper::RdfGeneratorHelper
36
36
 
37
37
  ##
38
38
  # #generate performs the enrichment of a Jekyll::Site with rdf triples
@@ -52,8 +52,8 @@ module Jekyll
52
52
  graph = RDF::Graph.load(@config['path'])
53
53
  sparql = SPARQL::Client.new(graph)
54
54
 
55
- Jekyll::RdfHelper::sparql = sparql
56
- Jekyll::RdfHelper::site = site
55
+ Jekyll::JekyllRdf::Helper::RdfHelper::sparql = sparql
56
+ Jekyll::JekyllRdf::Helper::RdfHelper::site = site
57
57
 
58
58
  # restrict RDF graph with restriction
59
59
  resources = extract_resources(@config['restriction'], @config['include_blank'], sparql)
@@ -29,7 +29,7 @@ module Jekyll
29
29
  # JekyllRdf::RdfPageData creates pages for each RDF resource using a given template
30
30
  #
31
31
  class RdfPageData < Jekyll::Page
32
- include Jekyll::RdfPageHelper
32
+ include Jekyll::JekyllRdf::Helper::RdfPageHelper
33
33
  attr_reader :complete
34
34
 
35
35
  ##
@@ -44,7 +44,7 @@ module Jekyll
44
44
 
45
45
  attr_accessor :classResources
46
46
 
47
- include Jekyll::RdfClassExtraction
47
+ include Jekyll::JekyllRdf::Helper::RdfClassExtraction
48
48
 
49
49
  ##
50
50
  # Create a new Jekyll::RdfTemplateMapper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.develop.334
4
+ version: 3.0.0.pre.develop.343
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elias Saalmann
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2017-11-10 00:00:00.000000000 Z
20
+ date: 2017-12-05 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: linkeddata
@@ -172,13 +172,13 @@ files:
172
172
  - lib/jekyll/filters/rdf_property.rb
173
173
  - lib/jekyll/filters/rdf_resolve_prefix.rb
174
174
  - lib/jekyll/filters/rdf_sparql_query.rb
175
+ - lib/jekyll/helper/rdf_class_extraction.rb
175
176
  - lib/jekyll/helper/rdf_general_helper.rb
177
+ - lib/jekyll/helper/rdf_generator_helper.rb
178
+ - lib/jekyll/helper/rdf_page_helper.rb
176
179
  - lib/jekyll/hooks/rdf_page_pointer.rb
177
- - lib/jekyll/rdf_class_extraction.rb
178
- - lib/jekyll/rdf_generator_helper.rb
179
180
  - lib/jekyll/rdf_main_generator.rb
180
181
  - lib/jekyll/rdf_page_data.rb
181
- - lib/jekyll/rdf_page_helper.rb
182
182
  - lib/jekyll/rdf_template_mapper.rb
183
183
  homepage: https://github.com/white-gecko/jekyll-rdf
184
184
  licenses:
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: 1.3.1
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.7.2
203
+ rubygems_version: 2.7.3
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Hypertext Publication System for Templated Resource Rendering
@@ -1,47 +0,0 @@
1
- module Jekyll
2
- module RdfClassExtraction
3
- private
4
- def search_for_classes(sparql)
5
- 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}}"
6
- class_search_results = sparql.query(class_recognition_query).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals
7
- s.class <= RDF::Literal
8
- end.select do |s| # Select URIs and blank nodes in case of include_blank
9
- s.class <=RDF::Node || s.class <= RDF::URI
10
- end
11
- return class_search_results
12
- end
13
-
14
- def create_resource_class(class_search_results, sparql)
15
- class_search_results.each do |uri|
16
- @classResources[uri.to_s]=Jekyll::Drops::RdfResourceClass.new(uri, sparql)
17
- end
18
-
19
- @classResources.each{|key, value|
20
- value.find_direct_subclasses.each{|s|
21
- value.add_subclass(@classResources[s])
22
- }
23
- }
24
- end
25
-
26
- def assign_class_templates(classes_to_templates)
27
- if(classes_to_templates.is_a?(Hash))
28
- @classResources.default = StopObject.new
29
- classes_to_templates.each{|key, value|
30
- @classResources[key].propagate_template(value,0)
31
- @classResources[key].traverse_hierarchy_value(0);
32
- }
33
- @classResources.default = nil
34
- end
35
- end
36
-
37
- class StopObject #unfortunately next does not work in this setup, it avoids to have "if" in every iteration
38
- def propagate_template(template, lock)
39
- return
40
- end
41
-
42
- def traverse_hierarchy_value(predecessorHierarchyValue)
43
- return
44
- end
45
- end
46
- end
47
- end
@@ -1,120 +0,0 @@
1
- module Jekyll
2
- module RdfGeneratorHelper
3
- private
4
- def prepare_pages (site, mapper)
5
- @pageResources.each{|uri, entry|
6
- resource = entry.delete('./')
7
- resource.subResources = entry
8
- create_page(site, resource, mapper, @global_config)
9
- }
10
-
11
- @blanknodes.each{|resource|
12
- create_page(site, resource, mapper, @global_config)
13
- }
14
- end
15
-
16
- def parse_resources (resources)
17
- @pageResources={}
18
- @blanknodes=[]
19
- resources.each do |uri|
20
- resource = Jekyll::Drops::RdfResource.new(uri, nil, nil, true)
21
- if(uri.instance_of? RDF::URI)
22
- uriString = uri.to_s
23
- if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a #
24
- preSufUri = uriString.split("#")
25
- if(!@pageResources.key? preSufUri[0])
26
- @pageResources[preSufUri[0]] = {}
27
- end
28
- @pageResources[preSufUri[0]][preSufUri[1]] = resource
29
- else #sorting in uris without a #
30
- if(!@pageResources.key? uriString)
31
- @pageResources[uriString]={}
32
- end
33
- @pageResources[uriString]['./'] = resource
34
- end
35
- elsif(uri.instance_of? RDF::Node)
36
- @blanknodes << resource
37
- end
38
-
39
- # give parents to orphaned resources
40
- @pageResources.each_key{|key|
41
- @pageResources[key]['./'] = Jekyll::Drops::RdfResource.new(RDF::URI(key)) if @pageResources[key]['./'].nil?
42
- }
43
- end
44
- end
45
-
46
- def load_config (site)
47
- begin
48
- @config = site.config.fetch('jekyll_rdf')
49
- rescue KeyError => e
50
- Jekyll.logger.error("You've included Jekyll-RDF, but it is not configured. Aborting the jekyll-rdf plugin.")
51
- return false
52
- end
53
-
54
- @global_config = Jekyll.configuration({})
55
-
56
- #small fix because global_config doesn't work in a test enviorment
57
- if(!@global_config.key? "url")
58
- @global_config["url"] = site.config["url"]
59
- @global_config["baseurl"] = site.config["baseurl"]
60
- end
61
- return true
62
- end
63
- ##
64
- # #extract_resources returns resources from an RDF Sparql endpoint.
65
- #
66
- # Literals are omitted.
67
- # Blank nodes are only returned if +include_blank+ is true.
68
- # Duplicate nodes are removed.
69
- #
70
- # * +selection+ - choose any of the following:
71
- # nil ::
72
- # no restrictions, return subjects, predicates, objects
73
- # "subjects" ::
74
- # return only subjects
75
- # "predicates" ::
76
- # return only predicates
77
- # "objects" ::
78
- # return only objects
79
- # Otherwise ::
80
- # consider +selection+ to be a SPARQL query and return answer set to this SPARQL query
81
- # * +include_blank+ - If true, blank nodes are also returned, otherwise blank nodes are omitted
82
- # * +sparql+ - The SPARQL client to run queries against
83
- #
84
- def extract_resources(selection, include_blank, sparql)
85
-
86
- case selection
87
- when nil # Config parameter not present
88
- object_resources = extract_resources("objects", include_blank, sparql)
89
- subject_resources = extract_resources("subjects", include_blank, sparql)
90
- predicate_resources = extract_resources("predicates", include_blank, sparql)
91
- return object_resources.concat(subject_resources).concat(predicate_resources).uniq
92
- when "objects"
93
- query = "SELECT ?resourceUri WHERE{?s ?p ?resourceUri}"
94
- when "subjects"
95
- query = "SELECT ?resourceUri WHERE{?resourceUri ?p ?o}"
96
- when "predicates"
97
- query = "SELECT ?resourceUri WHERE{?s ?resourceUri ?o}"
98
- else
99
- # Custom query
100
- query = selection
101
- end
102
- sparql.query(query).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals
103
- s.class <= RDF::Literal
104
- end.select do |s| # Select URIs and blank nodes in case of include_blank
105
- include_blank || s.class == RDF::URI
106
- end.uniq
107
- end
108
-
109
- def create_page(site, resource, mapper, global_config)
110
- page = RdfPageData.new(site, site.source, resource, mapper, global_config)
111
- if(page.complete)
112
- site.pages << page
113
- resource.add_necessities(site, page)
114
- resource.subResources.each {|key, value|
115
- value.add_necessities(site, page)
116
- } unless resource.subResources.nil?
117
- end
118
- end
119
- end
120
- end
@@ -1,54 +0,0 @@
1
- module Jekyll
2
- module RdfPageHelper
3
- private
4
- ##
5
- # sets @template to the path of a fitting layout
6
- # it will set @complete to false if no fitting template is found
7
- # * +resource+ - the resource that will be mapped to a template
8
- # * +mapper+ - the mapper that provides the resource mappings
9
- def map_template(resource, mapper)
10
- @template = mapper.map(resource)
11
- if(@template.nil?)
12
- Jekyll.logger.warn("Resource #{resource} not rendered: No fitting template or default template found.")
13
- @complete = false
14
- end
15
- end
16
-
17
- ##
18
- # loads the data from the yaml-frontmatter and extends page.data with three key value pairs:
19
- # -title -> contains the resource.iri
20
- # -rdf -> contains the resource itself
21
- # -template -> contains the path to the currenly used template
22
- def load_data(site)
23
- self.read_yaml(File.join(@base, '_layouts'), @template)
24
- self.data['title'] = @resource.iri
25
- self.data['rdf'] = @resource
26
- self.data['template'] = @template
27
- if(!@resource.subResources.nil?)
28
- self.data['sub_rdf'] = @resource.subResources.values
29
- self.data['sub_rdf'].each { |res|
30
- res.page = self
31
- res.site = site
32
- }
33
- end
34
- end
35
-
36
- ##
37
- # loads the prefix data passed in the layout yaml-frontmatter into page.data["rdf_prefixes"] and page.data["rdf_prefix_map"]
38
- def load_prefixes
39
- if !self.data["rdf_prefix_path"].nil?
40
- begin
41
- prefix_file=File.new(File.join(@base, 'rdf-data', self.data["rdf_prefix_path"].strip)).readlines
42
- self.data["rdf_prefixes"] = prefix_file.join(" ")
43
- self.data["rdf_prefix_map"] = Hash[ *(prefix_file.collect { |v|
44
- arr = v.split(":",2)
45
- [arr[0][7..-1].strip, arr[1].strip[1..-2]]
46
- }.flatten)]
47
- rescue Errno::ENOENT => ex
48
- Jekyll.logger.error("context: #{@resource} template: #{@template} file not found: #{File.join(@base, 'rdf-data', self.data["rdf_prefix_path"])}")
49
- end
50
- end
51
- end
52
- end
53
- end
54
-