jekyll-rdf 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66d828ef6b4898af8b9ddc0811421af2d96e41ee
4
- data.tar.gz: fc7354fc326c9e36728b769e79d81e26ee5b4532
3
+ metadata.gz: bb995c6b66f94be8fafd3b78c74a8bb82858c35f
4
+ data.tar.gz: 97ad76c5961a904d35919cab1e52ad81fe21aef1
5
5
  SHA512:
6
- metadata.gz: 7c8d64c1c9329ca1ad5e8a85f120f305df6db31efc9d8a9dc7365bc53c6ab93292561c6d0e6c33971e7baa0379ef95c24680b1505f62998d11457a1556519a62
7
- data.tar.gz: 21977963369705d6aa26501f024fd3568737f2d6cfe90da764e3385557f7d840369e8ff3c73f6d6c7a7f3430d523802e3f0ab4e666b60e2bc808a75cf6905cb1
6
+ metadata.gz: a4a626bbd804965f6e5259750ee6458ef9250cbe79f7d5b5cb7f94952b701b73bd7496ffed8296e825f2db68abd42ccfba16d5eed511d5b787d13438fcf68fbf
7
+ data.tar.gz: e772f781b9ff347c466baa0caa8848d832ce898415feca39d95c63066e7c7567973cdb7f98b21ff83e90dbbcc1407abca6f9b8420c7b0456892b1f450e8dfca3
data/lib/jekyll-rdf.rb CHANGED
@@ -30,14 +30,16 @@ require 'jekyll'
30
30
  require 'linkeddata'
31
31
  require 'sparql'
32
32
 
33
-
34
33
  require 'jekyll/drops/rdf_term'
35
34
  require 'jekyll/drops/rdf_statement'
36
35
  require 'jekyll/drops/rdf_literal'
37
36
  require 'jekyll/drops/rdf_resource'
37
+ require 'jekyll/drops/rdf_resource_class'
38
+ require 'jekyll/exceptions/NoPrefixMapped'
39
+ require 'jekyll/exceptions/NoPrefixesDefined'
40
+ require 'jekyll/exceptions/UnMarkedUri'
38
41
  require 'jekyll/filters/rdf_sparql_query'
39
42
  require 'jekyll/filters/rdf_property'
40
- require 'jekyll/filters/rdf_property_list'
41
43
  require 'jekyll/rdf_main_generator'
42
44
  require 'jekyll/rdf_page_data'
43
45
  require 'jekyll/rdf_template_mapper'
@@ -34,7 +34,7 @@ module Jekyll
34
34
  ##
35
35
  # Return a user-facing string representing this RdfLiteral
36
36
  #
37
- def name
37
+ def literal
38
38
  term.to_s
39
39
  end
40
40
 
@@ -1,6 +1,6 @@
1
1
  ##
2
2
  # MIT License
3
- #
3
+ #
4
4
  # Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi,
5
5
  # Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg
6
6
  #
@@ -41,6 +41,16 @@ module Jekyll #:nodoc:
41
41
  #
42
42
  attr_accessor :page
43
43
 
44
+ ##
45
+ # The relative path to the location on the disk where this resource is rendered to
46
+ #
47
+ attr_reader :render_path
48
+
49
+ ##
50
+ #
51
+ #
52
+ attr_accessor :subResources
53
+
44
54
  ##
45
55
  # Return a list of Jekyll::Drops::RdfStatements whose subject, predicate or object is the RDF resource represented by the receiver
46
56
  #
@@ -76,52 +86,20 @@ module Jekyll #:nodoc:
76
86
  @filename ||= generate_file_name(domain_name, baseurl)
77
87
  end
78
88
 
79
- ##
80
- # types finds the type and superclasses of the resource
81
- #
82
- def types
83
- @types ||= begin
84
- types = [ term.to_s ]
89
+ def directClasses
90
+ @directClasses ||= begin
91
+ classes=[]
85
92
  selection = statements_as(:subject).select{ |s| s.predicate.term.to_s=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }
86
93
  unless selection.empty?
87
- t = selection.first
88
- if selection.count > 1
89
- Jekyll.logger.warn "Resource #{name} has multiple RDFS types. Will use #{t.object.term.to_s} for template mapping. "
90
- end
91
- types << t.object.term.to_s
92
- t = t.object
93
- s = t.super_class
94
- while s
95
- types << s.term.to_s
96
- s = s.super_class
97
- end
94
+ selection.each{|s| classes << s.object.term.to_s}
98
95
  end
99
- types
96
+ classes.uniq!
97
+ classes
100
98
  end
101
99
  end
102
100
 
103
- ##
104
- # Return the first super class resource of the receiver or nil, if no super class resource can be found
105
- #
106
- def super_class
107
- selection = statements_as(:subject).select{ |s| s.predicate.term.to_s=="http://www.w3.org/2000/01/rdf-schema#subClassOf" }
108
- unless selection.empty?
109
- super_class = selection.first
110
- if selection.count > 1
111
- Jekyll.logger.warn "Type #{name} has multiple RDFS super classes. Will use #{super_class.object.term.to_s} for template mapping. "
112
- end
113
- super_class.object
114
- end
115
- end
116
-
117
- ##
118
- # Return a user-facing string representing this RdfResource
119
- #
120
- def name
121
- @name ||= begin
122
- n = statements_as(:subject).find{ |s| s.predicate.term.to_s=="http://xmlns.com/foaf/0.1/name" }
123
- n ? n.object.name : term.to_s
124
- end
101
+ def iri
102
+ term.to_s
125
103
  end
126
104
 
127
105
  ##
@@ -160,29 +138,42 @@ module Jekyll #:nodoc:
160
138
  file_name = ""
161
139
  uri[0] = nil
162
140
  uri[2] = nil
163
- uri[5] = uri[5].sub(baseurl,'')
141
+ if(uri[5].length > baseurl.length)
142
+ if(uri[5][0..(baseurl.length)].eql? (baseurl + "/"))
143
+ uri[5] = uri[5][(baseurl.length)..-1]
144
+ end
145
+ elsif(uri[5].eql?(baseurl))
146
+ uri[5] = nil
147
+ end
164
148
  end
165
149
  (0..8).each do |i|
166
- if uri[i]
150
+ if !(uri[i].nil?)
167
151
  case i
168
- when 2
169
- file_name += "#{uri[i].gsub('.','/')}/"
152
+ when 5
153
+ file_name += "#{uri[i][1..-1]}/"
170
154
  when 8
171
- file_name = file_name[0..-2]
172
- file_name += "##{uri[i]}"
155
+ file_name += "#/#{uri[i]}"
173
156
  else
174
- file_name += "#{uri[i]}/"
157
+ file_name += "#{uri[i]}/"
175
158
  end
176
159
  end
177
160
  end
178
161
  unless file_name[-1] == '/'
179
162
  file_name += '/'
180
163
  end
181
- file_name += 'index.html'
182
- file_name.gsub('//','/')
183
- rescue URI::InvalidURIError
184
- file_name = "rdfsites/blanknode/#{term.to_s}/index.html"
164
+ rescue URI::InvalidURIError #unclean coding: blanknodes are recognized through errors
165
+ file_name = "rdfsites/blanknode/#{term.to_s}/"
166
+ end
167
+ file_name = file_name.gsub('_','_u')
168
+ file_name = file_name.gsub('//','/') # needs a better regex to include /// ////...
169
+ file_name = file_name.gsub(':','_D')
170
+ file_name = file_name.strip
171
+ if(file_name[-2..-1] == "#/")
172
+ file_name = file_name[0..-3]
185
173
  end
174
+ file_name += 'index.html'
175
+ @render_path = file_name
176
+ file_name
186
177
  end
187
178
 
188
179
  end
@@ -0,0 +1,83 @@
1
+ ##
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi,
5
+ # Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #
25
+
26
+ module Jekyll #:nodoc:
27
+ module Drops #:nodoc:
28
+
29
+ ##
30
+ # Represents an RDF resource class to the Liquid template engine
31
+ #
32
+ class RdfResourceClass < RdfResource
33
+ @subClasses = []
34
+ @lock = -1
35
+ @subClassHierarchyValue = 0
36
+ attr_accessor :lock
37
+ attr_accessor :template
38
+ attr_accessor :alternativeTemplates
39
+ attr_accessor :subClasses
40
+ attr_accessor :subClassHierarchyValue
41
+
42
+ def initialize(term, graph)
43
+ super(term, graph)
44
+ @subClasses = []
45
+ @lock = -1
46
+ @subClassHierarchyValue = 0
47
+ @alternativeTemplates = []
48
+ end
49
+
50
+ def multipleTemplates?
51
+ !@alternativeTemplates.empty?
52
+ end
53
+
54
+ def findDirectSubClasses
55
+ selection = statements_as(:object).select{ |s| s.predicate.term.to_s=="http://www.w3.org/2000/01/rdf-schema#subClassOf" }
56
+ return selection
57
+ end
58
+
59
+ def addSubClass(resource)
60
+ @subClasses << resource
61
+ end
62
+
63
+ def propagateTemplate(template, lock)
64
+ if(@lock>lock||@lock==-1)
65
+ @lock=lock
66
+ @template=template
67
+ @alternativeTemplates.clear()
68
+ subClasses.each{|sub| sub.propagateTemplate(template ,lock+1)}
69
+ elsif(@lock==lock)
70
+ @alternativeTemplates.push(template)
71
+ subClasses.each{|sub| sub.propagateTemplate(template ,lock+1)}
72
+ end
73
+ end
74
+
75
+ def traverseHierarchyValue(predecessorHierarchyValue)
76
+ if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops
77
+ @subClassHierarchyValue += 1
78
+ subClasses.each{|sub| sub.traverseHierarchyValue(@subClassHierarchyValue)}
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -53,10 +53,13 @@ module Jekyll
53
53
  end
54
54
 
55
55
  ##
56
- # Convert this RdfTerm into a human-readable string
56
+ # Convert this RdfTerm into a string
57
+ # This should be:
58
+ # - for resoruces: the IRI
59
+ # - for literals: the literal representation e.g. "Hallo"@de or "123"^^<http://www.w3.org/2001/XMLSchema#integer>
57
60
  #
58
61
  def to_s
59
- name
62
+ term.to_s
60
63
  end
61
64
 
62
65
  ##
@@ -0,0 +1,7 @@
1
+ class NoPrefixMapped < StandardError
2
+ attr_accessor :prefix, :property
3
+ def initialize property, layout, prefix
4
+ @prefix, @property = prefix, property
5
+ super("Their is no mapping defined for #{prefix} in context to #{property}\n in layout: '#{layout}'.")
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class NoPrefixesDefined < StandardError
2
+ def initialize x, layout
3
+ super("No Prefixes are defined when #{x} gets passed in \n layout: '#{layout}'.")
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class UnMarkedUri < StandardError
2
+ def initialize uri, layout
3
+ super("The URI #{uri} is not correctly marked. Pls use the form <#{uri}> instead.\nFound in layout: '#{layout}'.")
4
+ end
5
+ end
@@ -29,28 +29,61 @@ module Jekyll
29
29
  # Internal module to hold the medthod #rdf_property
30
30
  #
31
31
  module RdfProperty
32
-
33
32
  ##
34
33
  # Computes all objects for which statements exist containing the given subject and predicate and returns any of them
35
34
  #
36
35
  # * +input+ - is the subject of the statements to be matched
37
36
  # * +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 returned (both in case a language is supplied and in case is not supplied) is undefined
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
39
  #
40
- def rdf_property(input, predicate, lang = nil)
40
+ def rdf_property(input, predicate, lang = nil, list = false)
41
41
  return input unless input.is_a?(Jekyll::Drops::RdfResource)
42
42
  begin
43
- results = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == predicate }
44
- lang ||= input.site.config['jekyll_rdf']['language']
45
- if results.count > 1 && results.first.object.term.is_a?(RDF::Term) && lang != nil
46
- p = results.find{ |s| s.object.term.language == lang.to_sym }
43
+ predicate = rdf_resolve_prefix(input, predicate)
44
+ result = input.statements_as_subject.select{ |s| s.predicate.term.to_s == predicate }
45
+ if lang != nil
46
+ if lang == 'cfg'
47
+ lang = input.site.config['jekyll_rdf']['language']
48
+ end
49
+ result = result.select{ |s|
50
+ if(s.object.term.is_a?(RDF::Literal))
51
+ s.object.term.language == lang.to_sym
52
+ else
53
+ false
54
+ end
55
+ }
56
+ end
57
+ return unless !result.empty?
58
+ if(list)
59
+ return result.map{|p|
60
+ p.object.to_s
61
+ }
62
+ else
63
+ return (result.first.object).to_s
47
64
  end
48
- p = results.first unless p
49
- return unless p
50
- (p.object.name).to_s
51
65
  end
52
66
  end
53
67
 
68
+ private
69
+ def rdf_resolve_prefix(input, predicate)
70
+ if(predicate[0] == "<" && predicate[-1] == ">")
71
+ return predicate[1..-2]
72
+ end
73
+ 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
74
+ if((arr[1].include? (":")) || (arr[1][0..1].eql?("//")))
75
+ raise UnMarkedUri.new(predicate, input.page.data['template'])
76
+ end
77
+ if(!input.page.data["rdf_prefixes"].nil?)
78
+ if(!input.page.data["rdf_prefix_map"][arr[0]].nil?)
79
+ return arr[1].prepend(input.page.data["rdf_prefix_map"][arr[0]])
80
+ else
81
+ raise NoPrefixMapped.new(predicate, input.page.data['template'], arr[0])
82
+ end
83
+ else
84
+ raise NoPrefixesDefined.new(predicate, input.page.data['template'])
85
+ end
86
+ end
54
87
  end
55
88
  end
56
89
 
@@ -40,14 +40,25 @@ module Jekyll
40
40
  def sparql_query(input, query)
41
41
  return input unless input.is_a?(Jekyll::Drops::RdfResource)
42
42
  query.gsub!('?resourceUri', "<#{input.term.to_s}>")
43
+ if(!input.page.data["rdf_prefixes"].nil?)
44
+ query = query.prepend(" ").prepend(input.page.data["rdf_prefixes"])
45
+ end
43
46
  begin
47
+ input.site.data['sparql']
44
48
  result = input.site.data['sparql'].query(query).map do |solution|
45
49
  hsh = solution.to_hash
46
50
  hsh.update(hsh){ |k,v| Jekyll::Drops::RdfTerm.build_term_drop(v, input.graph, input.site) }
47
51
  hsh.collect{|k,v| [k.to_s, v]}.to_h
48
52
  end
49
53
  return result
54
+ rescue SPARQL::Client::ClientError => ce
55
+ Jekyll.logger.error("client error experienced: \n #{query} \n Error Message: #{ce.message}")
56
+ rescue SPARQL::MalformedQuery => mq
57
+ Jekyll.logger.error("malformed query found: \n #{query} \n Error Message: #{mq.message}")
58
+ rescue Exception => e
59
+ Jekyll.logger.error("unknown Exception of class: #{e.class} in sparql_query \n Query: #{query} \nMessage: #{e.message}")
50
60
  end
61
+ return []
51
62
  end
52
63
 
53
64
  end
@@ -39,7 +39,26 @@ module Jekyll
39
39
  # * +site+ - The Jekyll::Site whose #data is to be enriched
40
40
  #
41
41
  def generate(site)
42
- config = site.config.fetch('jekyll_rdf')
42
+
43
+ begin
44
+ config = site.config.fetch('jekyll_rdf')
45
+ rescue Exception
46
+ Jekyll.logger.error("You've included Jekyll-RDF, but it is not configured. Aborting the jekyll-rdf plugin.")
47
+ return
48
+ end
49
+
50
+ global_config = Jekyll.configuration({})
51
+
52
+ #small fix because global_config doesn't work in a test enviorment
53
+ if(!global_config.key? "url")
54
+ global_config["url"] = site.config["url"]
55
+ global_config["baseurl"] = site.config["baseurl"]
56
+ end
57
+
58
+ if(config.key? "template_mapping")
59
+ Jekyll.logger.error("Outdated format in _config.yml:\n 'template_mapping' detected but the following keys must be used now instead:\n instance_template_mappings -> maps single resources to single layouts\n class_template_mappings -> maps entire classes of resources to layouts\nJekyll-RDF wont render any pages for #{site.source}")
60
+ return
61
+ end
43
62
 
44
63
  graph = RDF::Graph.load(config['path'])
45
64
  sparql = SPARQL::Client.new(graph)
@@ -50,13 +69,50 @@ module Jekyll
50
69
  site.data['sparql'] = sparql
51
70
  site.data['resources'] = []
52
71
 
53
- mapper = Jekyll::RdfTemplateMapper.new(config['template_mappings'], config['default_template'])
54
-
55
- # create RDF pages for each URI
72
+ #parse resources
73
+ pageResources={};
74
+ blanknodes=[]
56
75
  resources.each do |uri|
57
76
  resource = Jekyll::Drops::RdfResource.new(uri, graph)
58
- site.pages << RdfPageData.new(site, site.source, resource, mapper)
77
+ if(uri.instance_of? RDF::URI)
78
+ uriString = uri.to_s
79
+ if((uriString.include? "#") && (uriString.index("#") < (uriString.length - 1))) #sorting in uris with a #
80
+ preSufUri = uriString.split("#")
81
+ if(!pageResources.key? preSufUri[0])
82
+ pageResources[preSufUri[0]] = {}
83
+ end
84
+ pageResources[preSufUri[0]][preSufUri[1]] = resource
85
+ elsif #sorting in uris without a #
86
+ if(!pageResources.key? uriString)
87
+ pageResources[uriString]={}
88
+ end
89
+ pageResources[uriString]['./'] = resource
90
+ end
91
+ elsif(uri.instance_of? RDF::Node)
92
+ blanknodes << resource
93
+ end
59
94
  end
95
+
96
+ mapper = Jekyll::RdfTemplateMapper.new(config['instance_template_mappings'], config['class_template_mappings'], config['default_template'], graph, sparql)
97
+
98
+ # create RDF pages for each URI
99
+ pageResources.each{|uri, entry|
100
+ if(entry['./'].nil?)
101
+ if(config['render_orphaned_uris'])
102
+ entry.each{|name, resource|
103
+ site.pages << RdfPageData.new(site, site.source, resource, mapper, global_config)
104
+ }
105
+ end
106
+ else
107
+ resource = entry.delete('./')
108
+ resource.subResources = entry
109
+ site.pages << RdfPageData.new(site, site.source, resource, mapper, global_config)
110
+ end
111
+ }
112
+
113
+ blanknodes.each{|resource|
114
+ site.pages << RdfPageData.new(site, site.source, resource, mapper, global_config)
115
+ }
60
116
  end
61
117
 
62
118
  ##
@@ -37,19 +37,37 @@ module Jekyll
37
37
  # * +resource+ - The RDF resource for which the page is rendered
38
38
  # * +mapper+ - The layout-mapping
39
39
  #
40
- def initialize(site, base, resource, mapper)
40
+ def initialize(site, base, resource, mapper, config)
41
41
  @site = site
42
42
  @base = base
43
43
  @dir = ""
44
- @name = resource.filename(URI::split(site.config['url'])[2], site.config['baseurl'])
44
+ @name = resource.filename(URI::split(config['url'])[2], config['baseurl'])
45
45
  self.process(@name)
46
46
 
47
47
  template = mapper.map(resource)
48
48
  self.read_yaml(File.join(base, '_layouts'), template)
49
-
50
- self.data['title'] = resource.name
49
+ self.data['title'] = resource.iri
51
50
  self.data['rdf'] = resource
52
-
51
+ self.data['template'] = template
52
+ if(!resource.subResources.nil?)
53
+ self.data['sub_rdf'] = resource.subResources.values
54
+ self.data['sub_rdf'].each { |res|
55
+ res.page = self
56
+ res.site = site
57
+ }
58
+ end
59
+ if !self.data["rdf_prefix_path"].nil?
60
+ begin
61
+ prefixFile=File.new(File.join(base, 'rdf-data', self.data["rdf_prefix_path"].strip)).readlines
62
+ self.data["rdf_prefixes"] = prefixFile.join(" ")
63
+ self.data["rdf_prefix_map"] = Hash[ *(prefixFile.collect { |v|
64
+ arr = v.split(":",2)
65
+ [arr[0][7..-1].strip, arr[1].strip[1..-2]]
66
+ }.flatten)]
67
+ rescue Errno::ENOENT => ex
68
+ Jekyll.logger.error("context: #{resource} template: #{template} file not found: #{File.join(base, 'rdf-data', self.data["rdf_prefix_path"])}")
69
+ end
70
+ end
53
71
  resource.page = self
54
72
  resource.site = site
55
73
  site.data['resources'] << resource
@@ -31,21 +31,53 @@ module Jekyll
31
31
  class RdfTemplateMapper
32
32
 
33
33
  ##
34
- # A Hash mapping a type resource to a template name
34
+ # A Hash mapping a resource to a template name
35
35
  attr_accessor :resources_to_templates
36
36
 
37
37
  ##
38
38
  # Default template name
39
39
  attr_accessor :default_template
40
40
 
41
+ ##
42
+ # A Hash mapping a type resource to a template name
43
+ attr_accessor :classes_to_templates
44
+
45
+ attr_accessor :classResources
46
+
41
47
  ##
42
48
  # Create a new Jekyll::RdfTemplateMapper
43
49
  #
44
50
  # * +resources_to_templates+ - A Hash mapping a type resource to a template name
45
51
  # * +default_template+ - Default template name
46
- def initialize(resources_to_templates, default_template)
52
+ def initialize(resources_to_templates, classes_to_templates, default_template, graph, sparql)
47
53
  @resources_to_templates = resources_to_templates
48
54
  @default_template = default_template
55
+ @classes_to_templates = classes_to_templates
56
+
57
+ @classResources = {}
58
+ classRecognitionQuery = "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}}"
59
+ classSearchResults = sparql.query(classRecognitionQuery).map{ |sol| sol[:resourceUri] }.reject do |s| # Reject literals
60
+ s.class <= RDF::Literal
61
+ end.select do |s| # Select URIs and blank nodes in case of include_blank
62
+ true || s.class == RDF::URI
63
+ end
64
+
65
+ classSearchResults.each do |uri|
66
+ classResources[uri.to_s]=Jekyll::Drops::RdfResourceClass.new(uri, graph)
67
+ end
68
+
69
+ classResources.each{|key, value|
70
+ value.findDirectSubClasses.each{|s|
71
+ value.addSubClass(classResources[s.subject.term.to_s])
72
+ }
73
+ }
74
+
75
+ if(classes_to_templates.is_a?(Hash))
76
+ classes_to_templates.each{|key, value|
77
+ classResources[key].propagateTemplate(value,0)
78
+ classResources[key].traverseHierarchyValue(0);
79
+ }
80
+ end
49
81
  end
50
82
 
51
83
  ##
@@ -53,13 +85,39 @@ module Jekyll
53
85
  #
54
86
  # Returns the template name of one of the +resource+'s types, if available. Returns the default template name otherwise.
55
87
  def map(resource)
56
- resource.types.each do |type|
57
- tmpl = resources_to_templates ? resources_to_templates[type] : nil
58
- return tmpl unless tmpl.nil?
88
+ tmpl = resources_to_templates ? resources_to_templates[resource.term.to_s] : nil
89
+ lock = -1
90
+ hier = -1
91
+ warnMultTempl = false
92
+ duplicateLevelTempl = []
93
+ if(tmpl.nil?)
94
+ resource.directClasses.each do |classUri|
95
+ classRes = classResources[classUri]
96
+ if((classRes.lock <= lock || lock == -1) && !classRes.template.nil?)
97
+ if(classRes.subClassHierarchyValue > hier)
98
+ Jekyll.logger.info("classMapped: #{classUri} : #{resource.term.to_s} : #{classResources[classUri].template}")
99
+ lock = classRes.lock
100
+ tmpl = classRes.template
101
+ hier = classRes.subClassHierarchyValue
102
+ warnMultTempl = false
103
+ duplicateLevelTempl.clear.push(tmpl)
104
+ if(classRes.multipleTemplates?)
105
+ warnMultTempl = true
106
+ duplicateLevelTempl.concat(classRes.alternativeTemplates)
107
+ end
108
+ elsif(classRes.subClassHierarchyValue == hier)
109
+ warnMultTempl = true
110
+ duplicateLevelTempl.push(classRes.template)
111
+ end
112
+ end unless classRes.nil?
113
+ end
114
+ if(warnMultTempl)
115
+ Jekyll.logger.warn("Warning: multiple possible templates for #{resource.term.to_s}: #{duplicateLevelTempl.uniq.join(', ')}")
116
+ end
59
117
  end
118
+ return tmpl unless tmpl.nil?
60
119
  return default_template
61
120
  end
62
-
63
121
  end
64
122
 
65
123
  end
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: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elias Saalmann
@@ -11,10 +11,12 @@ authors:
11
11
  - Maxi Bornmann
12
12
  - Georg Hackel
13
13
  - Eric Füg
14
+ - Sebastian Zänker
15
+ - Natanael Arndt
14
16
  autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
- date: 2016-06-10 00:00:00.000000000 Z
19
+ date: 2017-03-29 00:00:00.000000000 Z
18
20
  dependencies:
19
21
  - !ruby/object:Gem::Dependency
20
22
  name: linkeddata
@@ -64,14 +66,14 @@ dependencies:
64
66
  requirements:
65
67
  - - "~>"
66
68
  - !ruby/object:Gem::Version
67
- version: '10.1'
69
+ version: '10.4'
68
70
  type: :runtime
69
71
  prerelease: false
70
72
  version_requirements: !ruby/object:Gem::Requirement
71
73
  requirements:
72
74
  - - "~>"
73
75
  - !ruby/object:Gem::Version
74
- version: '10.1'
76
+ version: '10.4'
75
77
  - !ruby/object:Gem::Dependency
76
78
  name: coveralls
77
79
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +145,7 @@ dependencies:
143
145
  - !ruby/object:Gem::Version
144
146
  version: '3.4'
145
147
  description: Generate static sites with Jekyll based on RDF data
146
- email: mail@esaalmann.de
148
+ email: arndt@informatik.uni-leipzig.de
147
149
  executables: []
148
150
  extensions: []
149
151
  extra_rdoc_files: []
@@ -151,15 +153,18 @@ files:
151
153
  - lib/jekyll-rdf.rb
152
154
  - lib/jekyll/drops/rdf_literal.rb
153
155
  - lib/jekyll/drops/rdf_resource.rb
156
+ - lib/jekyll/drops/rdf_resource_class.rb
154
157
  - lib/jekyll/drops/rdf_statement.rb
155
158
  - lib/jekyll/drops/rdf_term.rb
159
+ - lib/jekyll/exceptions/NoPrefixMapped.rb
160
+ - lib/jekyll/exceptions/NoPrefixesDefined.rb
161
+ - lib/jekyll/exceptions/UnMarkedUri.rb
156
162
  - lib/jekyll/filters/rdf_property.rb
157
- - lib/jekyll/filters/rdf_property_list.rb
158
163
  - lib/jekyll/filters/rdf_sparql_query.rb
159
164
  - lib/jekyll/rdf_main_generator.rb
160
165
  - lib/jekyll/rdf_page_data.rb
161
166
  - lib/jekyll/rdf_template_mapper.rb
162
- homepage: http://pcai042.informatik.uni-leipzig.de/~dtp16/
167
+ homepage: https://github.com/white-gecko/jekyll-rdf
163
168
  licenses:
164
169
  - MIT
165
170
  metadata: {}
@@ -179,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
184
  version: '0'
180
185
  requirements: []
181
186
  rubyforge_project:
182
- rubygems_version: 2.4.5
187
+ rubygems_version: 2.2.2
183
188
  signing_key:
184
189
  specification_version: 4
185
190
  summary: Hypertext Publication System for Templates Resource Rendering
@@ -1,58 +0,0 @@
1
- ##
2
- # MIT License
3
- #
4
- # Copyright (c) 2016 Elias Saalmann, Christian Frommert, Simon Jakobi,
5
- # Arne Jonas Präger, Maxi Bornmann, Georg Hackel, Eric Füg
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in all
15
- # copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- # SOFTWARE.
24
- #
25
-
26
- module Jekyll
27
-
28
- ##
29
- # Internal module to hold the method #rdf_property
30
- #
31
- module RdfPropertyList
32
-
33
- ##
34
- # Computes all objects for which statements exist containing the given subject and predicate and returns an Array of them
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 the returned objects. If 'cfg' is specified the preferred language is provides by the site configuration _config.yml
39
- #
40
- def rdf_property_list(input, predicate, lang = nil)
41
- return input unless input.is_a?(Jekyll::Drops::RdfResource)
42
- begin
43
- result = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == predicate } # select all matching statements with given predicate
44
- if lang != nil
45
- if lang == 'cfg'
46
- lang = input.site.config['jekyll_rdf']['language']
47
- end
48
- result = result.select{ |s| s.object.term.language == lang.to_sym } # select all statements with matching language
49
- end
50
- return unless result
51
- result.map{|p| p.object.name}
52
- end
53
- end
54
-
55
- end
56
- end
57
-
58
- Liquid::Template.register_filter(Jekyll::RdfPropertyList)