jekyll-rdf 3.1.1.pre.develop.671 → 3.1.1.pre.develop.688
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jekyll/drops/rdf_resource_class.rb +46 -36
- data/lib/jekyll/helper/rdf_class_extraction.rb +141 -27
- data/lib/jekyll/rdf_main_generator.rb +1 -1
- data/lib/jekyll/rdf_template_mapper.rb +10 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df5e7aac5e8663115d1b4bb44af2118aaf039e6811f092eaecaffaac288894a7
|
4
|
+
data.tar.gz: 272573d89b48aca124e020ffff44bf413f32b080ea3a3bbe0f48506b86e207ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a52a3d34008e4bdaf2ed2920829958b5931c07d40302cb571d086f6b8db940a2e5bcb21478767dc8e64632319e33311f5bbe60143a1f28b4581a8709e424f493
|
7
|
+
data.tar.gz: 02d6617ec2837a621d0d351e73020389c8f2bd2c935b07d6cea97249a05162e49841285eaa23f46865f5dd59d4c8ce9da68668949568eaa7683bff3923fff6e5
|
@@ -31,58 +31,68 @@ module Jekyll #:nodoc:
|
|
31
31
|
# Represents an RDF resource class to the Liquid template engine
|
32
32
|
#
|
33
33
|
class RdfResourceClass < RdfResource
|
34
|
-
@subClasses = []
|
35
|
-
@lock = -1
|
36
|
-
@subClassHierarchyValue = 0
|
37
34
|
attr_accessor :lock
|
35
|
+
attr_reader :distance #distance to next class with template
|
38
36
|
attr_accessor :template
|
39
|
-
attr_accessor :
|
40
|
-
attr_accessor :
|
41
|
-
|
42
|
-
attr_reader :sparql
|
37
|
+
attr_accessor :path
|
38
|
+
attr_accessor :base # important for template mapping
|
39
|
+
# true if _config.yml assigned this class a template
|
43
40
|
|
44
|
-
def initialize(term,
|
41
|
+
def initialize(term, base = false)
|
45
42
|
super(term)
|
46
|
-
@
|
43
|
+
@base = base
|
47
44
|
@lock = -1
|
48
|
-
@
|
49
|
-
@
|
50
|
-
@sparql = sparql
|
45
|
+
@lockNumber = 0
|
46
|
+
@distance = 0
|
51
47
|
end
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
query = "SELECT ?s WHERE{
|
59
|
-
selection =
|
49
|
+
##
|
50
|
+
# Returns all classes from which +term+ directly inherited
|
51
|
+
#
|
52
|
+
def find_direct_superclasses
|
53
|
+
return @superclasses unless @superclasses.nil?
|
54
|
+
query = "SELECT ?s WHERE{ #{@term.to_ntriples} <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?s }"
|
55
|
+
selection = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.
|
56
|
+
query(query).map{ |solution| solution.s.to_s}
|
57
|
+
@superclasses = selection
|
60
58
|
return selection
|
61
59
|
end
|
62
60
|
|
63
|
-
|
64
|
-
|
61
|
+
##
|
62
|
+
# Propagate the current template to the parent of the breadth-first search
|
63
|
+
# in RdfClassExtraction.request_class_template.
|
64
|
+
#
|
65
|
+
def propagate_template(distance)
|
66
|
+
@distance = distance
|
67
|
+
return if @path.nil?
|
68
|
+
return unless @path.template.nil?
|
69
|
+
@path.template = @template
|
70
|
+
@path.propagate_template(distance +1)
|
65
71
|
end
|
66
72
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
elsif(@lock==lock)
|
74
|
-
@alternativeTemplates.push(template)
|
75
|
-
subClasses.each{|sub| sub.propagate_template(template ,lock+1)}
|
76
|
-
end
|
73
|
+
##
|
74
|
+
# Returns the beginning of the path leading to the found template
|
75
|
+
#
|
76
|
+
def get_path_root
|
77
|
+
return self if @path.nil?
|
78
|
+
@path.get_path_root
|
77
79
|
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
##
|
82
|
+
# Checks if this instance was already added to the breadth-first search
|
83
|
+
# in RdfClassExtraction.request_class_template.
|
84
|
+
#
|
85
|
+
def add? lock_number
|
86
|
+
if @lock_number != lock_number
|
87
|
+
# used to recognize different searchpasses of request_class_template
|
88
|
+
@lock_number = lock_number
|
89
|
+
@lock = -1
|
90
|
+
true
|
91
|
+
else
|
92
|
+
false
|
83
93
|
end
|
84
94
|
end
|
85
|
-
end
|
95
|
+
end #RdfResourceClass
|
86
96
|
end
|
87
97
|
end
|
88
98
|
end
|
@@ -2,47 +2,161 @@ module Jekyll
|
|
2
2
|
module JekyllRdf
|
3
3
|
module Helper
|
4
4
|
module RdfClassExtraction
|
5
|
+
|
5
6
|
private
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
|
8
|
+
##
|
9
|
+
# Instantiate all rdf:class'es with an template mapped in +classes_to_templates+.
|
10
|
+
# +classes_to_templates+ A hash that contains string representations of class resources
|
11
|
+
# as keys and maps these to a template.
|
12
|
+
#
|
13
|
+
def create_resource_class(classes_to_templates)
|
14
|
+
if(classes_to_templates.is_a?(Hash))
|
15
|
+
classes_to_templates.each{|uri, template|
|
16
|
+
@classResources[uri] = Jekyll::JekyllRdf::Drops::
|
17
|
+
RdfResourceClass.new(RDF::URI(uri), true)
|
18
|
+
@classResources[uri].template = template
|
19
|
+
}
|
12
20
|
end
|
13
|
-
return class_search_results
|
14
21
|
end
|
15
22
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
##
|
24
|
+
# Returns to a RdfResource a template through its rdf:type
|
25
|
+
# +resource+ the resource a template is searched for.
|
26
|
+
#
|
27
|
+
def request_class_template resource
|
28
|
+
return nil if resource.direct_classes.empty?
|
29
|
+
direct_classes = resource.direct_classes
|
30
|
+
#hash template and determine if we used these classes before
|
31
|
+
hash_str = direct_classes.sort!.join(", ")
|
32
|
+
return @template_cache[hash_str] unless @template_cache[hash_str].nil?
|
33
|
+
#start searching
|
34
|
+
lock = -1
|
35
|
+
count = 0
|
36
|
+
next_increase = -1
|
37
|
+
lock_number = rand
|
38
|
+
min_template_lock = @stop_object #ruby does not have MAX_VALUE
|
39
|
+
min_class = nil
|
40
|
+
class_list = direct_classes.map{|uri|
|
41
|
+
@classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri))
|
42
|
+
@classResources[uri].path = nil
|
43
|
+
@classResources[uri]
|
44
|
+
}
|
45
|
+
alternatives = []
|
46
|
+
class_list.each{|class_resource|
|
47
|
+
if(next_increase <= count) # the next level of the breadth-first search
|
48
|
+
if ((min_template_lock <= lock) && (lock >= 0)) # if (distance to next template is smaller than current search radius) && (we checked all immediate classes)
|
49
|
+
return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str)
|
50
|
+
end
|
51
|
+
alternatives.clear()
|
52
|
+
lock += 1
|
53
|
+
next_increase = class_list.length
|
54
|
+
end
|
20
55
|
|
21
|
-
|
22
|
-
|
23
|
-
|
56
|
+
if !class_resource.template.nil? && min_template_lock > lock - 1 + class_resource.distance
|
57
|
+
min_template_lock = lock - 1
|
58
|
+
min_class = class_resource
|
59
|
+
end
|
60
|
+
|
61
|
+
class_resource.find_direct_superclasses.each{ |uri|
|
62
|
+
@classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri))
|
63
|
+
if(!@classResources[uri].template.nil?) # do not search in paths you previously found
|
64
|
+
if @classResources[uri].base
|
65
|
+
if(!min_class.nil? && min_template_lock == lock) #min_class could contain a previously found class with equal distance
|
66
|
+
alternatives.push @classResources[uri] unless min_class.eql? @classResources[uri]
|
67
|
+
else
|
68
|
+
min_template_lock = lock
|
69
|
+
min_class = @classResources[uri]
|
70
|
+
end
|
71
|
+
@classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph
|
72
|
+
elsif min_template_lock > (lock + @classResources[uri].distance) # you found a branch that was used earlier
|
73
|
+
# note template but search further unitl (min_template_lock <= lock) && (lock >= 1) is satisfied
|
74
|
+
@classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph
|
75
|
+
min_template_lock = lock + @classResources[uri].distance
|
76
|
+
min_class = @classResources[uri]
|
77
|
+
elsif min_template_lock == (lock + @classResources[uri].distance)
|
78
|
+
alternatives.push @classResources[uri] unless min_class.eql? @classResources[uri]
|
79
|
+
end
|
80
|
+
elsif(@classResources[uri].add?(lock_number)) # not a previously searched resource without a template
|
81
|
+
@classResources[uri].path = class_resource # <- this might be valnuable to cyclic inheritance in the graph
|
82
|
+
class_list.push(@classResources[uri])
|
83
|
+
@classResources[uri].lock = lock
|
84
|
+
end
|
24
85
|
}
|
86
|
+
count += 1
|
25
87
|
}
|
88
|
+
|
89
|
+
unless min_class.nil?
|
90
|
+
return extract_template(find_highlevel_inheritance(min_class, alternatives, resource), hash_str)
|
91
|
+
end
|
92
|
+
return nil
|
26
93
|
end
|
27
94
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
95
|
+
##
|
96
|
+
# Returns the template stored in the input resource +class_resource+
|
97
|
+
# and caches it with +hash_str+ as key.
|
98
|
+
#
|
99
|
+
def extract_template class_resource, hash_str
|
100
|
+
class_resource.propagate_template(class_resource.distance)
|
101
|
+
return (@template_cache[hash_str] = class_resource.get_path_root.template)
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Returns the most specific class resource from +class_list+ based on
|
106
|
+
# +current_best+.
|
107
|
+
# +resource+ is the original input of request_class_template.
|
108
|
+
#
|
109
|
+
def find_highlevel_inheritance current_best, class_list, resource #check at the end of the search for direct inheritance on highest level
|
110
|
+
class_list.each{|resource|
|
111
|
+
resource.find_direct_superclasses.each{|uri|
|
112
|
+
@classResources[uri] ||= Jekyll::JekyllRdf::Drops::RdfResourceClass.new(RDF::URI(uri))
|
113
|
+
@classResources[uri].path = resource
|
114
|
+
} if resource.base
|
115
|
+
}
|
116
|
+
# this is valnuable to cyclic inheritance
|
117
|
+
while(class_list.include?(current_best.path))
|
118
|
+
slice = class_list.index(current_best)
|
119
|
+
# parent alternatives are no real alternatives
|
120
|
+
class_list.slice!(slice) unless slice.nil?
|
121
|
+
current_best = current_best.path
|
36
122
|
end
|
123
|
+
return consistence_templates(current_best, class_list, resource) unless class_list.empty?
|
124
|
+
return current_best
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Add a warning for a class having multiple possible templates
|
129
|
+
# The warnings are then later displayed with print_warnings
|
130
|
+
# +classRes+ and +alternatives+ make up a list of class resources which
|
131
|
+
# are all equally valid choices for request_class_template
|
132
|
+
# +resource+ is the original input of request_class_template.
|
133
|
+
#
|
134
|
+
def consistence_templates(classRes, alternatives, resource)
|
135
|
+
hash_str = alternatives.push(classRes).
|
136
|
+
map {|x|
|
137
|
+
x.template
|
138
|
+
}.
|
139
|
+
sort!.join(", ")
|
140
|
+
begin
|
141
|
+
@consistence[hash_str] = []
|
142
|
+
@consistence[hash_str].push(classRes)
|
143
|
+
@consistence[hash_str].push([])
|
144
|
+
end if @consistence[hash_str].nil?
|
145
|
+
@consistence[hash_str][1].push(resource) # using a hash ensures that a warning is printed only once for each combination of templates
|
146
|
+
# and for each resource at most once
|
147
|
+
@consistence[hash_str][0]
|
37
148
|
end
|
38
149
|
|
39
|
-
|
40
|
-
|
41
|
-
|
150
|
+
##
|
151
|
+
# used to escape loops without an if-statement
|
152
|
+
#
|
153
|
+
class StopObject
|
154
|
+
def > object
|
155
|
+
true
|
42
156
|
end
|
43
157
|
|
44
|
-
def
|
45
|
-
|
158
|
+
def <= object
|
159
|
+
false
|
46
160
|
end
|
47
161
|
end
|
48
162
|
end
|
@@ -82,7 +82,7 @@ module Jekyll
|
|
82
82
|
|
83
83
|
parse_resources(resources)
|
84
84
|
|
85
|
-
mapper = Jekyll::RdfTemplateMapper.new(@config['instance_template_mappings'], @config['class_template_mappings'], @config['default_template']
|
85
|
+
mapper = Jekyll::RdfTemplateMapper.new(@config['instance_template_mappings'], @config['class_template_mappings'], @config['default_template'])
|
86
86
|
|
87
87
|
prepare_pages(site, mapper)
|
88
88
|
|
@@ -37,14 +37,15 @@ module Jekyll
|
|
37
37
|
#
|
38
38
|
# * +resources_to_templates+ - A Hash mapping a type resource to a template name
|
39
39
|
# * +default_template+ - Default template name
|
40
|
-
def initialize(resources_to_templates, classes_to_templates, default_template
|
40
|
+
def initialize(resources_to_templates, classes_to_templates, default_template)
|
41
41
|
@resources_to_templates = resources_to_templates
|
42
42
|
@default_template = default_template
|
43
|
-
@classes_to_templates = classes_to_templates
|
44
43
|
@classResources = {}
|
45
|
-
@
|
46
|
-
|
47
|
-
|
44
|
+
@consistence = {} #ensures that the same template is chosen for each combination of templates
|
45
|
+
@template_cache = {}
|
46
|
+
@stop_object = StopObject.new
|
47
|
+
|
48
|
+
create_resource_class(classes_to_templates)
|
48
49
|
end
|
49
50
|
|
50
51
|
##
|
@@ -53,45 +54,17 @@ module Jekyll
|
|
53
54
|
# Returns the template name of one of the +resource+'s types, if available. Returns the default template name otherwise.
|
54
55
|
def map(resource)
|
55
56
|
tmpl = @resources_to_templates ? @resources_to_templates[resource.term.to_s] : nil
|
56
|
-
|
57
|
-
hier = -1
|
58
|
-
duplicate_level_templ = []
|
59
|
-
resource.direct_classes.each do |classUri|
|
60
|
-
classRes = @classResources[classUri]
|
61
|
-
if((classRes.lock <= lock || lock == -1) && !classRes.template.nil?)
|
62
|
-
if(classRes.subClassHierarchyValue > hier)
|
63
|
-
lock = classRes.lock
|
64
|
-
tmpl = classRes.template
|
65
|
-
hier = classRes.subClassHierarchyValue
|
66
|
-
duplicate_level_templ.clear.push(tmpl)
|
67
|
-
if(classRes.multiple_templates?)
|
68
|
-
duplicate_level_templ.concat(classRes.alternativeTemplates)
|
69
|
-
end
|
70
|
-
elsif(classRes.subClassHierarchyValue == hier)
|
71
|
-
duplicate_level_templ.push(classRes.template)
|
72
|
-
end
|
73
|
-
end unless classRes.nil?
|
74
|
-
end if(tmpl.nil?)
|
75
|
-
add_warning(duplicate_level_templ.uniq, resource.iri) if (duplicate_level_templ.length > 1) && (Jekyll.env.eql? "development")
|
57
|
+
tmpl = request_class_template(resource) if tmpl.nil?
|
76
58
|
return tmpl unless tmpl.nil?
|
77
59
|
return @default_template
|
78
60
|
end
|
79
61
|
|
80
62
|
##
|
81
|
-
#
|
82
|
-
# The warnings are then later displayed with print_warnings
|
63
|
+
# outputs all warnings prepared by RdfClassExtraction.consistence_templates
|
83
64
|
#
|
84
|
-
def add_warning(keys, iri)
|
85
|
-
keys.sort!
|
86
|
-
key = keys.join(', ')
|
87
|
-
@warnings[key] = [] if @warnings[key].nil? # using a hash ensures that a warning is printed only once for each combination of templates
|
88
|
-
# and for each resource at most once
|
89
|
-
@warnings[key].push(iri) unless @warnings[key].include? iri
|
90
|
-
end
|
91
|
-
|
92
65
|
def print_warnings
|
93
|
-
@
|
94
|
-
Jekyll.logger.warn("Warning: multiple possible templates for resources #{
|
66
|
+
@consistence.each{ |key, template_class_store|
|
67
|
+
Jekyll.logger.warn("Warning: multiple possible templates for resources #{template_class_store[1].join(", ")}\nPossible Templates: #{key}")
|
95
68
|
true
|
96
69
|
}
|
97
70
|
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: 3.1.1.pre.develop.
|
4
|
+
version: 3.1.1.pre.develop.688
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elias Saalmann
|
@@ -18,7 +18,7 @@ authors:
|
|
18
18
|
autorequire:
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
|
-
date: 2019-02-
|
21
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: net-http-persistent
|