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.
@@ -24,61 +24,63 @@
24
24
  #
25
25
 
26
26
  module Jekyll #:nodoc:
27
- module Drops #:nodoc:
27
+ module JekyllRdf #:nodoc:
28
+ module Drops #:nodoc:
28
29
 
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
- 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
- @alternativeTemplates = []
49
- @sparql = sparql
50
- end
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
- def multiple_templates?
53
- !@alternativeTemplates.empty?
54
- end
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
- def find_direct_subclasses
57
- query = "SELECT ?s WHERE{ ?s <http://www.w3.org/2000/01/rdf-schema#subClassOf> #{@term.to_ntriples}}"
58
- selection = @sparql.query(query).map{ |solution| solution.s.to_s}
59
- return selection
60
- end
53
+ def multiple_templates?
54
+ !@alternativeTemplates.empty?
55
+ end
61
56
 
62
- def add_subclass(resource)
63
- @subClasses << resource
64
- end
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
- def propagate_template(template, lock)
67
- if(@lock>lock||@lock==-1)
68
- @lock=lock
69
- @template=template
70
- @alternativeTemplates.clear()
71
- subClasses.each{|sub| sub.propagate_template(template ,lock+1)}
72
- elsif(@lock==lock)
73
- @alternativeTemplates.push(template)
74
- subClasses.each{|sub| sub.propagate_template(template ,lock+1)}
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
- def traverse_hierarchy_value(predecessorHierarchyValue)
79
- if(@subClassHierarchyValue + 1 >= predecessorHierarchyValue) #avoid loops
80
- @subClassHierarchyValue += 1
81
- subClasses.each{|sub| sub.traverse_hierarchy_value(@subClassHierarchyValue)}
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 Drops
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
- # The subject RdfTerm of this RDF statement
31
+ # Represents an RDF statement to the Liquid template engine
36
32
  #
37
- attr_reader :subject
33
+ class RdfStatement < Liquid::Drop
38
34
 
39
- ##
40
- # The predicate RdfTerm of this RDF statement
41
- #
42
- attr_reader :predicate
35
+ ##
36
+ # The subject RdfTerm of this RDF statement
37
+ #
38
+ attr_reader :subject
43
39
 
44
- ##
45
- # The object RdfTerm of this RDF statement
46
- #
47
- attr_reader :object
40
+ ##
41
+ # The predicate RdfTerm of this RDF statement
42
+ #
43
+ attr_reader :predicate
48
44
 
49
- ##
50
- # Create a new Jekyll::Drops::RdfStatement
51
- #
52
- # * +statement+ - The statement to be represented
53
- # * +sparql+ - The SPARQL::Client which contains the +statement+
54
- # * +site+ - The Jekyll::Site to be enriched
55
- def initialize(statement, site)
56
- @subject ||= Jekyll::Drops::RdfTerm.build_term_drop(statement.subject, site, true)
57
- @predicate ||= Jekyll::Drops::RdfTerm.build_term_drop(statement.predicate, site, true)
58
- @object ||= Jekyll::Drops::RdfTerm.build_term_drop(statement.object, site, true)
59
- end
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
- def inspect
62
- obj_id = ('%x' % (self.object_id << 1)).to_s
63
- return "#<RdfStatement:0x#{"0"*(14 - obj_id.length)}#{obj_id} @subject=#{subject.inspect} @predicate=#{predicate.inspect} @object=#{object.inspect}>"
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 Drops
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
- # The represented RDF term
31
+ # Represents an RDF term to the Liquid template engine
36
32
  #
37
- attr_reader :term
33
+ class RdfTerm < Liquid::Drop
38
34
 
39
- ##
40
- # Create a new Jekyll::Drops::RdfTerm
41
- #
42
- # * +term+ - The term to be represented
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
- # Function stub with no functionality. Its purpose is to keep RdfResource compatible.
50
- #
51
- def add_necessities (site, page)
52
- return self
53
- end
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
- # Function stub with no functionality. Its purpose is to keep RdfResource compatible.
57
- #
58
- def ready?
59
- return true;
60
- end
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
- # Convert this RdfTerm into a string
64
- # This should be:
65
- # - for resources: the IRI
66
- # - for literals: the literal representation e.g. "Hallo"@de or "123"^^<http://www.w3.org/2001/XMLSchema#integer>
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
- def ==(other_obj)
73
- return self.eql? other_obj
74
- end
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
- def eql? other_obj
77
- 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))
78
- end
73
+ def ==(other_obj)
74
+ return self.eql? other_obj
75
+ end
79
76
 
80
- def ===(other_obj)
81
- return self.to_s.eql? other_obj.to_s
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
- def inspect
101
- obj_id = ('%x' % (self.object_id << 1)).to_s
102
- return "#<#{self.class.to_s.split("::")[-1]}:0x#{"0"*(14 - obj_id.length)}#{obj_id} @term=#{@term}>"
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 RdfCollection
29
- include Jekyll::RdfPrefixResolver
30
- def rdf_collection(input, predicate = nil)
31
- input = Jekyll::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::RdfHelper::sparql.query(query).each{ |solution|
37
- results.push Jekyll::Drops::RdfTerm.build_term_drop(solution.f, Jekyll::RdfHelper::site, true).add_necessities(Jekyll::RdfHelper::site, Jekyll::RdfHelper::page)
38
- }
39
- return results
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 RdfContainer
28
- include Jekyll::RdfPrefixResolver
29
- def rdf_container(input, type = nil)
30
- input = Jekyll::RdfHelper::page.data['rdf'] if(input.nil? || input.class <= (Jekyll::RdfPageData))
31
- sparql_client = Jekyll::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 []
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
- return solutions
44
- 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::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
- def query_additions()
47
- return "BIND((<http://www.w3.org/2001/XMLSchema#integer>(SUBSTR(str(?p), 45))) AS ?order) } ORDER BY ASC(?order)"
48
- end
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
- def valid_container?(n_triples, type = nil)
51
- 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}"
52
- 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>}"
53
- return (Jekyll::RdfHelper::sparql.query(ask_query1).true?) || (Jekyll::RdfHelper::sparql.query(ask_query2).true?)
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
- # Internal module to hold the medthod #rdf_get
30
- #
31
- module RdfGet
32
- include Jekyll::RdfPrefixResolver
33
- def rdf_get(request_uri)
34
- request_uri = "<#{Jekyll::RdfHelper::page.data['rdf'].term.to_s}>" if (request_uri.nil? || request_uri.class <= (Jekyll::RdfPageData))
35
- request_uri = rdf_resolve_prefix(request_uri)
36
- ask_exist = "ASK WHERE {{<#{request_uri}> ?p ?o}UNION{?s <#{request_uri}> ?o}UNION{?s ?p <#{request_uri}>}} "
37
- return unless (Jekyll::RdfHelper::sparql.query(ask_exist).true?)
38
- Jekyll::Drops::RdfResource.new(RDF::URI(request_uri), Jekyll::RdfHelper::site, Jekyll::RdfHelper::page)
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)