jekyll-rdf 1.0.1 → 1.1.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: 110cb3800452fb5622a7f01dd39c367ed6d4a181
4
- data.tar.gz: d7bd153e3055b51569e85fcaae039db8b44e60ad
3
+ metadata.gz: d437bb55ab5b1de0a9ab46821413726b54f999cd
4
+ data.tar.gz: 06cacb32344903476f740d2e2c94417128bbf4ac
5
5
  SHA512:
6
- metadata.gz: 8ace2caa161e8103fdb6d2de6f60fb570a0103fba2c9e6a16e571e68fbab0ba67d7a6d865d97aa5fa470d851998edaa60853015278824b74660c60dc7596c2ee
7
- data.tar.gz: eeef2100f84e9d3b2272ed15e41f95f8386d8319e87068102ea29d50dd529c1ab35cbea5c48e0a4761511b0aef64fa98e6f082389a48bf8ac67deca61cdbb08c
6
+ metadata.gz: ac26c4881a6e16baf237ddca55ccddd118277c206350b848f11ba4224b10fb03f878049d60d770c81f362a465149aae46e967e5634d323133a73dc4d196e509d
7
+ data.tar.gz: 339fd31d9dd6345d0f7a422f1d4af3ae00b6eda2e51c168867818bd69be29a3ec53748eca3e4bb0daaec08867be15ba5266abe0207127d52983e23df0cf389ec
@@ -1,19 +1,23 @@
1
- module Jekyll
2
- module Drops
1
+ module Jekyll #:nodoc:
2
+ module Drops #:nodoc:
3
+
4
+ ##
5
+ # Represents an RDF resource to the Liquid template engine
6
+ #
3
7
  class RdfResource < RdfTerm
4
-
8
+
5
9
  ##
6
10
  # The Jekyll::Site of this Jekyll::Drops::RdfResource
7
11
  #
8
12
  attr_accessor :site
9
-
13
+
10
14
  ##
11
15
  # The Jekyll::RdfPageData of this Jekyll::Drops::RdfResource
12
16
  #
13
17
  attr_accessor :page
14
18
 
15
19
  ##
16
- # Return a list of Jekyll::Drops::RdfStatements whose subject, predicate or object is the RDF resource represented by the receiver
20
+ # Return a list of Jekyll::Drops::RdfStatements whose subject, predicate or object is the RDF resource represented by the receiver
17
21
  #
18
22
  def statements
19
23
  @statements ||= statements_as_subject + statements_as_predicate + statements_as_object
@@ -53,14 +57,18 @@ module Jekyll
53
57
  def types
54
58
  @types ||= begin
55
59
  types = [ term.to_s ]
56
- t = statements_as(:subject).find{ |s| s.predicate.term.to_s=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }
57
- if t
60
+ selection = statements_as(:subject).select{ |s| s.predicate.term.to_s=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }
61
+ unless selection.empty?
62
+ t = selection.first
63
+ if selection.count > 1
64
+ Jekyll.logger.warn "Resource #{name} has multiple RDFS types. Will use #{t.object.term.to_s} for template mapping. "
65
+ end
58
66
  types << t.object.term.to_s
59
67
  t = t.object
60
- while t.super_class
61
- s = t.super_class
68
+ s = t.super_class
69
+ while s
62
70
  types << s.term.to_s
63
- t = s
71
+ s = s.super_class
64
72
  end
65
73
  end
66
74
  types
@@ -71,9 +79,13 @@ module Jekyll
71
79
  # Return the first super class resource of the receiver or nil, if no super class resource can be found
72
80
  #
73
81
  def super_class
74
- s = statements_as(:subject).find{ |s| s.predicate.term.to_s=="http://www.w3.org/2000/01/rdf-schema#subClassOf" }
75
- if s
76
- s.object
82
+ selection = statements_as(:subject).select{ |s| s.predicate.term.to_s=="http://www.w3.org/2000/01/rdf-schema#subClassOf" }
83
+ unless selection.empty?
84
+ super_class = selection.first
85
+ if selection.count > 1
86
+ Jekyll.logger.warn "Type #{name} has multiple RDFS super classes. Will use #{super_class.object.term.to_s} for template mapping. "
87
+ end
88
+ super_class.object
77
89
  end
78
90
  end
79
91
 
@@ -86,14 +98,14 @@ module Jekyll
86
98
  n ? n.object.name : term.to_s
87
99
  end
88
100
  end
89
-
101
+
90
102
  ##
91
103
  # Return the URL of the page representing this RdfResource
92
104
  #
93
105
  def page_url
94
106
  page ? page.url.chomp('index.html') : term.to_s
95
107
  end
96
-
108
+
97
109
  ##
98
110
  # Return a list of RDF statements where the represented RDF resource plays a role
99
111
  # * +role+ - which role the represented RDF resource should play:
@@ -1,14 +1,24 @@
1
1
  module Jekyll
2
+
3
+ ##
4
+ # Internal module to hold the medthod #rdf_property
5
+ #
2
6
  module RdfProperty
3
7
 
4
- def rdf_property(input, params)
8
+ ##
9
+ # Computes all objects for which statements exist containing the given subject and predicate and returns any of them
10
+ #
11
+ # * +input+ - is the subject of the statements to be matched
12
+ # * +predicate+ - is the predicate of the statements to be matched
13
+ # * +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
14
+ #
15
+ def rdf_property(input, predicate, lang = nil)
5
16
  return input unless input.is_a?(Jekyll::Drops::RdfResource)
6
17
  begin
7
- params = params.split(",")
8
- results = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == params[0] }
9
- lang = params[1] || input.site.config['language']
10
- if results.count > 1 && results.first.object.term.is_a?(RDF::Term)
11
- p = results.find{ |s| s.object.term.language == lang }
18
+ results = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == predicate }
19
+ lang ||= input.site.config['jekyll_rdf']['language']
20
+ if results.count > 1 && results.first.object.term.is_a?(RDF::Term) && lang != nil
21
+ p = results.find{ |s| s.object.term.language == lang.to_sym }
12
22
  end
13
23
  p = results.first unless p
14
24
  return unless p
@@ -1,12 +1,29 @@
1
1
  module Jekyll
2
+
3
+ ##
4
+ # Internal module to hold the method #rdf_property
5
+ #
2
6
  module RdfPropertyList
3
7
 
4
- def rdf_property_list(input, property)
8
+ ##
9
+ # Computes all objects for which statements exist containing the given subject and predicate and returns an Array of them
10
+ #
11
+ # * +input+ - is the subject of the statements to be matched
12
+ # * +predicate+ - is the predicate of the statements to be matched
13
+ # * +lang+ - (optional) preferred language of the returned objects. If 'cfg' is specified the preferred language is provides by the site configuration _config.yml
14
+ #
15
+ def rdf_property_list(input, predicate, lang = nil)
5
16
  return input unless input.is_a?(Jekyll::Drops::RdfResource)
6
17
  begin
7
- result = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == property }.map{|p| p.object.name}
18
+ result = input.page.data['rdf'].statements_as_subject.select{ |s| s.predicate.term.to_s == predicate } # select all matching statements with given predicate
19
+ if lang != nil
20
+ if lang == 'cfg'
21
+ lang = input.site.config['jekyll_rdf']['language']
22
+ end
23
+ result = result.select{ |s| s.object.term.language == lang.to_sym } # select all statements with matching language
24
+ end
8
25
  return unless result
9
- result
26
+ result.map{|p| p.object.name}
10
27
  end
11
28
  end
12
29
 
@@ -1,6 +1,17 @@
1
1
  module Jekyll
2
+
3
+ ##
4
+ # Internal module to hold the medthod #sparql_query
5
+ #
2
6
  module RdfSparqlQuery
3
7
 
8
+ ##
9
+ # Executes a SPARQL query. The supplied query is augmented by replacing each occurence of '?resourceUri' by the URI of the context RDF resource.
10
+ # Returns an Array of bindings. Each binding is a Hash mapping variables to their values.
11
+ #
12
+ # * +input+ - the context RDF resource
13
+ # * +query+ - the SPARQL query
14
+ #
4
15
  def sparql_query(input, query)
5
16
  return input unless input.is_a?(Jekyll::Drops::RdfResource)
6
17
  query.gsub!('?resourceUri', "<#{input.term.to_s}>")
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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elias Saalmann