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,61 +24,63 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll #:nodoc:
|
27
|
-
module
|
27
|
+
module JekyllRdf #:nodoc:
|
28
|
+
module Drops #:nodoc:
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
attr_reader :sparql
|
42
|
-
|
43
|
-
def initialize(term, sparql)
|
44
|
-
super(term)
|
30
|
+
##
|
31
|
+
# Represents an RDF resource class to the Liquid template engine
|
32
|
+
#
|
33
|
+
class RdfResourceClass < RdfResource
|
45
34
|
@subClasses = []
|
46
35
|
@lock = -1
|
47
36
|
@subClassHierarchyValue = 0
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
attr_accessor :lock
|
38
|
+
attr_accessor :template
|
39
|
+
attr_accessor :alternativeTemplates
|
40
|
+
attr_accessor :subClasses
|
41
|
+
attr_accessor :subClassHierarchyValue
|
42
|
+
attr_reader :sparql
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
def initialize(term, sparql)
|
45
|
+
super(term)
|
46
|
+
@subClasses = []
|
47
|
+
@lock = -1
|
48
|
+
@subClassHierarchyValue = 0
|
49
|
+
@alternativeTemplates = []
|
50
|
+
@sparql = sparql
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return selection
|
60
|
-
end
|
53
|
+
def multiple_templates?
|
54
|
+
!@alternativeTemplates.empty?
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
57
|
+
def find_direct_subclasses
|
58
|
+
query = "SELECT ?s WHERE{ ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> #{@term.to_ntriples}}"
|
59
|
+
selection = @sparql.query(query).map{ |solution| solution.s.to_s}
|
60
|
+
return selection
|
61
|
+
end
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
63
|
+
def add_subclass(resource)
|
64
|
+
@subClasses << resource
|
65
|
+
end
|
66
|
+
|
67
|
+
def propagate_template(template, lock)
|
68
|
+
if(@lock>lock||@lock==-1)
|
69
|
+
@lock=lock
|
70
|
+
@template=template
|
71
|
+
@alternativeTemplates.clear()
|
72
|
+
subClasses.each{|sub| sub.propagate_template(template ,lock+1)}
|
73
|
+
elsif(@lock==lock)
|
74
|
+
@alternativeTemplates.push(template)
|
75
|
+
subClasses.each{|sub| sub.propagate_template(template ,lock+1)}
|
76
|
+
end
|
75
77
|
end
|
76
|
-
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def traverse_hierarchy_value(predecessorHierarchyValue)
|
80
|
+
if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops
|
81
|
+
@subClassHierarchyValue += 1
|
82
|
+
subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)}
|
83
|
+
end
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -24,43 +24,45 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
module
|
28
|
-
|
29
|
-
##
|
30
|
-
# Represents an RDF statement to the Liquid template engine
|
31
|
-
#
|
32
|
-
class RdfStatement < Liquid::Drop
|
27
|
+
module JekyllRdf
|
28
|
+
module Drops
|
33
29
|
|
34
30
|
##
|
35
|
-
#
|
31
|
+
# Represents an RDF statement to the Liquid template engine
|
36
32
|
#
|
37
|
-
|
33
|
+
class RdfStatement < Liquid::Drop
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
##
|
36
|
+
# The subject RdfTerm of this RDF statement
|
37
|
+
#
|
38
|
+
attr_reader :subject
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
##
|
41
|
+
# The predicate RdfTerm of this RDF statement
|
42
|
+
#
|
43
|
+
attr_reader :predicate
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
##
|
46
|
+
# The object RdfTerm of this RDF statement
|
47
|
+
#
|
48
|
+
attr_reader :object
|
49
|
+
|
50
|
+
##
|
51
|
+
# Create a new Jekyll::Drops::RdfStatement
|
52
|
+
#
|
53
|
+
# * +statement+ - The statement to be represented
|
54
|
+
# * +sparql+ - The SPARQL::Client which contains the +statement+
|
55
|
+
# * +site+ - The Jekyll::Site to be enriched
|
56
|
+
def initialize(statement, site)
|
57
|
+
@subject ||= Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(statement.subject, site, true)
|
58
|
+
@predicate ||= Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(statement.predicate, site, true)
|
59
|
+
@object ||= Jekyll::JekyllRdf::Drops::RdfTerm.build_term_drop(statement.object, site, true)
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
def inspect
|
63
|
+
obj_id = ('%x' % (self.object_id << 1)).to_s
|
64
|
+
return "#<RdfStatement:0x#{"0"*(14 - obj_id.length)}#{obj_id} @subject=#{subject.inspect} @predicate=#{predicate.inspect} @object=#{object.inspect}>"
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
@@ -24,83 +24,86 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
module
|
28
|
-
|
29
|
-
##
|
30
|
-
# Represents an RDF term to the Liquid template engine
|
31
|
-
#
|
32
|
-
class RdfTerm < Liquid::Drop
|
27
|
+
module JekyllRdf
|
28
|
+
module Drops
|
33
29
|
|
34
30
|
##
|
35
|
-
#
|
31
|
+
# Represents an RDF term to the Liquid template engine
|
36
32
|
#
|
37
|
-
|
33
|
+
class RdfTerm < Liquid::Drop
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
def initialize(term)
|
45
|
-
@term ||= term
|
46
|
-
end
|
35
|
+
##
|
36
|
+
# The represented RDF term
|
37
|
+
#
|
38
|
+
attr_reader :term
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
##
|
41
|
+
# Create a new Jekyll::JekyllRdf::Drops::RdfTerm
|
42
|
+
#
|
43
|
+
# * +term+ - The term to be represented
|
44
|
+
#
|
45
|
+
def initialize(term)
|
46
|
+
@term ||= term
|
47
|
+
end
|
54
48
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
##
|
50
|
+
# Function stub with no functionality. Its purpose is to keep RdfResource compatible.
|
51
|
+
#
|
52
|
+
def add_necessities (site, page)
|
53
|
+
return self
|
54
|
+
end
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
def to_s
|
69
|
-
term.to_s
|
70
|
-
end
|
56
|
+
##
|
57
|
+
# Function stub with no functionality. Its purpose is to keep RdfResource compatible.
|
58
|
+
#
|
59
|
+
def ready?
|
60
|
+
return true;
|
61
|
+
end
|
71
62
|
|
72
|
-
|
73
|
-
|
74
|
-
|
63
|
+
##
|
64
|
+
# Convert this RdfTerm into a string
|
65
|
+
# This should be:
|
66
|
+
# - for resources: the IRI
|
67
|
+
# - for literals: the literal representation e.g. "Hallo"@de or "123"^^<http://www.w3.org/2001/XMLSchema#integer>
|
68
|
+
#
|
69
|
+
def to_s
|
70
|
+
term.to_s
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
def ==(other_obj)
|
74
|
+
return self.eql? other_obj
|
75
|
+
end
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
##
|
84
|
-
# Convert an RDF term into a new Jekyll::Drops::RdfTerm
|
85
|
-
#
|
86
|
-
# * +term+ - The term to be represented
|
87
|
-
# * +site+ - The Jekyll::Site to be enriched
|
88
|
-
#
|
89
|
-
def self.build_term_drop(term, site, covered)
|
90
|
-
case term
|
91
|
-
when RDF::URI, RDF::Node
|
92
|
-
return RdfResource.new(term, site, nil, covered)
|
93
|
-
when RDF::Literal
|
94
|
-
return RdfLiteral.new(term,)
|
95
|
-
else
|
96
|
-
return nil
|
77
|
+
def eql? other_obj
|
78
|
+
return (self.to_s.eql? other_obj.to_s)&&((other_obj.class <= self.class)||(self.class <= other_obj.class)||(other_obj.class <= self.term.class))
|
97
79
|
end
|
98
|
-
end
|
99
80
|
|
100
|
-
|
101
|
-
|
102
|
-
|
81
|
+
def ===(other_obj)
|
82
|
+
return self.to_s.eql? other_obj.to_s
|
83
|
+
end
|
84
|
+
##
|
85
|
+
# Convert an RDF term into a new Jekyll::Drops::RdfTerm
|
86
|
+
#
|
87
|
+
# * +term+ - The term to be represented
|
88
|
+
# * +site+ - The Jekyll::Site to be enriched
|
89
|
+
#
|
90
|
+
def self.build_term_drop(term, site, covered)
|
91
|
+
case term
|
92
|
+
when RDF::URI, RDF::Node
|
93
|
+
return RdfResource.new(term, site, nil, covered)
|
94
|
+
when RDF::Literal
|
95
|
+
return RdfLiteral.new(term)
|
96
|
+
else
|
97
|
+
return nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def inspect
|
102
|
+
obj_id = ('%x' % (self.object_id << 1)).to_s
|
103
|
+
return "#<#{self.class.to_s.split("::")[-1]}:0x#{"0"*(14 - obj_id.length)}#{obj_id} @term=#{@term}>"
|
104
|
+
end
|
103
105
|
end
|
106
|
+
|
104
107
|
end
|
105
108
|
end
|
106
109
|
end
|
@@ -25,20 +25,19 @@
|
|
25
25
|
#
|
26
26
|
|
27
27
|
module Jekyll
|
28
|
-
module
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
module JekyllRdf
|
29
|
+
module Filter
|
30
|
+
def rdf_collection(input, predicate = nil)
|
31
|
+
input = Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'] if(input.nil? || input.class <= (Jekyll::RdfPageData))
|
32
|
+
query = "SELECT ?f WHERE{ #{input.term.to_ntriples} " <<
|
33
|
+
(predicate.nil? ? "" : " <#{rdf_resolve_prefix(predicate)}> ?coll . ?coll ") <<
|
34
|
+
" <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}"
|
35
|
+
results = []
|
36
|
+
Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).each{ |solution|
|
37
|
+
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)
|
38
|
+
}
|
39
|
+
return results
|
40
|
+
end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
43
|
-
|
44
|
-
Liquid::Template.register_filter(Jekyll::RdfCollection)
|
@@ -24,35 +24,35 @@
|
|
24
24
|
#
|
25
25
|
|
26
26
|
module Jekyll
|
27
|
-
module
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
query = "SELECT ?p ?o WHERE{ #{n_triples} ?p ?o #{query_additions()}"
|
38
|
-
solutions = sparql_client.query(query).each_with_object([]) {|solution, array|
|
39
|
-
if(/^http:\/\/www\.w3\.org\/1999\/02\/22-rdf-syntax-ns#_\d+$/.match(solution.p.to_s))
|
40
|
-
array << Jekyll::Drops::RdfTerm.build_term_drop(solution.o, Jekyll::RdfHelper::site, true).add_necessities(Jekyll::RdfHelper::site, Jekyll::RdfHelper::page)
|
27
|
+
module JekyllRdf
|
28
|
+
module Filter
|
29
|
+
def rdf_container(input, type = nil)
|
30
|
+
input = Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'] if(input.nil? || input.class <= (Jekyll::RdfPageData))
|
31
|
+
sparql_client = Jekyll::JekyllRdf::Helper::RdfHelper::sparql
|
32
|
+
n_triples = input.term.to_ntriples
|
33
|
+
if(!(valid_container?(n_triples, type)))
|
34
|
+
Jekyll.logger.error "#{n_triples} is not recognized as a container"
|
35
|
+
return []
|
41
36
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
query = "SELECT ?p ?o WHERE{ #{n_triples} ?p ?o #{query_additions()}"
|
38
|
+
solutions = sparql_client.query(query).each_with_object([]) {|solution, array|
|
39
|
+
if(/^http:\/\/www\.w3\.org\/1999\/02\/22-rdf-syntax-ns#_\d+$/.match(solution.p.to_s))
|
40
|
+
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)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
return solutions
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
private
|
47
|
+
def query_additions()
|
48
|
+
return "BIND((<http://www.w3.org/2001/XMLSchema#integer>(SUBSTR(str(?p), 45))) AS ?order) } ORDER BY ASC(?order)"
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
def valid_container?(n_triples, type = nil)
|
52
|
+
ask_query1 = "ASK WHERE {VALUES ?o {<http://www.w3.org/2000/01/rdf-schema#Container> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Alt>} #{n_triples} <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o}"
|
53
|
+
ask_query2 = "ASK WHERE {#{ n_triples } <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o. ?o <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://www.w3.org/2000/01/rdf-schema#Container>}"
|
54
|
+
return (Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_query1).true?) || (Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_query2).true?)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
57
|
-
|
58
|
-
Liquid::Template.register_filter(Jekyll::RdfContainer)
|
@@ -25,19 +25,19 @@
|
|
25
25
|
|
26
26
|
module Jekyll
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
module JekyllRdf
|
29
|
+
|
30
|
+
##
|
31
|
+
# Internal module to hold the medthod #rdf_get
|
32
|
+
#
|
33
|
+
module Filter
|
34
|
+
def rdf_get(request_uri)
|
35
|
+
request_uri = "<#{Jekyll::JekyllRdf::Helper::RdfHelper::page.data['rdf'].term.to_s}>" if (request_uri.nil? || request_uri.class <= (Jekyll::RdfPageData))
|
36
|
+
request_uri = rdf_resolve_prefix(request_uri)
|
37
|
+
ask_exist = "ASK WHERE {{<#{request_uri}> ?p ?o}UNION{?s <#{request_uri}> ?o}UNION{?s ?p <#{request_uri}>}} "
|
38
|
+
return unless (Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_exist).true?)
|
39
|
+
Jekyll::JekyllRdf::Drops::RdfResource.new(RDF::URI(request_uri), Jekyll::JekyllRdf::Helper::RdfHelper::site, Jekyll::JekyllRdf::Helper::RdfHelper::page)
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
42
|
-
|
43
|
-
Liquid::Template.register_filter(Jekyll::RdfGet)
|