Class: Jekyll::JekyllRdf::Drops::RdfResource

Inherits:
RdfTerm
  • Object
show all
Defined in:
lib/jekyll/drops/rdf_resource.rb

Overview

Represents an RDF resource to the Liquid template engine

Direct Known Subclasses

RdfResourceClass

Instance Attribute Summary collapse

Attributes inherited from RdfTerm

#term

Instance Method Summary collapse

Methods inherited from RdfTerm

#==, #===, build_term_drop, #eql?, #to_s

Constructor Details

#initialize(term, site = nil, page = nil) ⇒ RdfResource

Returns a new instance of RdfResource.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jekyll/drops/rdf_resource.rb', line 53

def initialize(term, site = nil, page = nil)
  super(term)
  if(site.is_a?(Jekyll::Site))
    @site = site
  end
  if(page.is_a?(Jekyll::Page))
    @page = page
  end
  @subResources = {}
  @iri = term.to_s
  @blank = false
  begin
    @iri = ""
    @blank = true
  end if (@iri.length > 1 && (@iri[0..1].eql? "_:")) || (term.class <= RDF::Node)
end

Instance Attribute Details

#pageObject

The Jekyll::Page of this Jekyll::JekyllRdf::Drops::RdfResource



43
44
45
# File 'lib/jekyll/drops/rdf_resource.rb', line 43

def page
  @page
end

#siteObject

The Jekyll::Site of this Jekyll::JekyllRdf::Drops::RdfResource



38
39
40
# File 'lib/jekyll/drops/rdf_resource.rb', line 38

def site
  @site
end

#subResourcesObject

Returns the value of attribute subResources.



48
49
50
# File 'lib/jekyll/drops/rdf_resource.rb', line 48

def subResources
  @subResources
end

Instance Method Details

#add_necessities(site, page) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/jekyll/drops/rdf_resource.rb', line 70

def add_necessities(site, page)
  if(site.is_a?(Jekyll::Site))
    @site ||= site
  end
  if(page.is_a?(Jekyll::Page))
    @page ||= page
  end
  return self
end

#blank?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/jekyll/drops/rdf_resource.rb', line 176

def blank?
  @blank
end

#coveredObject

Returns true if the resource base containes this resource



87
88
89
90
91
92
93
94
95
96
# File 'lib/jekyll/drops/rdf_resource.rb', line 87

def covered
  return @covered unless @covered.nil?
  ask_exist = "ASK WHERE {{#{term.to_ntriples} ?p ?o}UNION{?s #{term.to_ntriples} ?o}UNION{?s ?p #{term.to_ntriples}}} "
  @covered = Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(ask_exist)
  if(@covered.instance_of? RDF::Literal::Boolean)
    @covered = @covered.true?
  else
    @covered = false || @covered   #take care of compatibility with virtuoso
  end
end

#direct_classesObject



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jekyll/drops/rdf_resource.rb', line 141

def direct_classes
  @direct_classes ||= begin
    classes=[]
    selection = statements_as(:subject).select{ |s| s.predicate.term.to_s=="http://www.w3.org/1999/02/22-rdf-syntax-ns#type" }
    unless selection.empty?
      selection.each{|s| classes << s.object.term.to_s}
    end
    classes.uniq!
    classes
  end
end

#filedirObject



135
136
137
138
139
# File 'lib/jekyll/drops/rdf_resource.rb', line 135

def filedir
  return @filedir unless @filedir.nil?
  generate_file_name()
  @filedir
end

#filenameObject

Return a filename corresponding to the RDF resource represented by the receiver. The mapping between RDF resources and filenames should be bijective.



129
130
131
132
133
# File 'lib/jekyll/drops/rdf_resource.rb', line 129

def filename
  return @filename unless @filename.nil?
  generate_file_name()
  @filename
end

#inspectObject



223
224
225
226
# File 'lib/jekyll/drops/rdf_resource.rb', line 223

def inspect
  obj_id = ('%x' % (self.object_id << 1)).to_s
  return "#<RdfResource:0x#{"0"*(14 - obj_id.length)}#{obj_id} @iri=#{iri} @subResources=[#{subResources.map { |x| x.inspect}.join(", ")}]>"
end

#iriObject



172
173
174
# File 'lib/jekyll/drops/rdf_resource.rb', line 172

def iri
  @iri
end

#page_urlObject

Return the URL of the page representing this RdfResource



156
157
158
159
160
161
# File 'lib/jekyll/drops/rdf_resource.rb', line 156

def page_url
  return @page_url.dup unless @page_url.nil?
  generate_file_name()
  #duplicate so outside sources do not edit this property
  @page_url.dup
end

#ready?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/jekyll/drops/rdf_resource.rb', line 80

def ready?
  return (@site.is_a?(Jekyll::Site)||@page.is_a?(Jekyll::Page))
end

#render_pathObject

Return the path to the page representing this RdfResource



166
167
168
169
170
# File 'lib/jekyll/drops/rdf_resource.rb', line 166

def render_path
  return @render_path.dup unless @page_url.nil?
  generate_file_name()
  @render_path.dup
end

#rendered?Boolean

Returns a true if this resource has a Jekyll::Page representation.

Returns:

  • (Boolean)


231
232
233
234
235
236
237
# File 'lib/jekyll/drops/rdf_resource.rb', line 231

def rendered?
  return @rendered unless @rendered.nil?
  @rendered = Jekyll::JekyllRdf::Helper::RdfHelper.site.pages.any?{|page|
    (filedir.eql? page.dir) && (filename.eql? page.name)
  }
  return @rendered
end

#statementsObject

Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose subject, predicate or object is the RDF resource represented by the receiver



101
102
103
# File 'lib/jekyll/drops/rdf_resource.rb', line 101

def statements
  @statements ||= statements_as_subject + statements_as_predicate + statements_as_object
end

#statements_as(role) ⇒ Object

Return a list of RDF statements where the represented RDF resource plays a role

  • role - which role the represented RDF resource should play:

    :subject

    Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose subject is the RDF resource represented by the receiver

    :predicate

    Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose predicate is the RDF resource represented by the receiver

    :object

    Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose object is the RDF resource represented by the receiver



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/jekyll/drops/rdf_resource.rb', line 190

def statements_as(role)
  if(!term.to_s[0..1].eql? "_:")
    input_uri = "<#{term.to_s}>"
  elsif(:predicate.eql? role)
    return []
  else
    input_uri = term.to_s
  end

  case role
  when :subject
    query = "SELECT ?p ?o ?dt ?lit ?lang WHERE{ #{input_uri} ?p ?o BIND(datatype(?o) AS ?dt) BIND(isLiteral(?o) AS ?lit) BIND(lang(?o) AS ?lang)}"
    Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution|
      check = check_solution(solution)
      create_statement(term.to_s, solution.p, solution.o, solution.lit, check[:lang], check[:data_type])
    end
  when :predicate
    query = "SELECT ?s ?o ?dt ?lit ?lang WHERE{ ?s #{input_uri} ?o BIND(datatype(?o) AS ?dt) BIND(isLiteral(?o) AS ?lit) BIND(lang(?o) AS ?lang)}"
    Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution|
      check = check_solution(solution)
      create_statement(solution.s, term.to_s, solution.o, solution.lit, check[:lang], check[:data_type])
    end
  when :object
    query = "SELECT ?s ?p WHERE{ ?s ?p #{input_uri}}"
    Jekyll::JekyllRdf::Helper::RdfHelper::sparql.query(query).map do |solution|
      create_statement( solution.s, solution.p, term.to_s)
    end
  else
    Jekyll.logger.error "Not existing role found in #{term.to_s}"
    return
  end
end

#statements_as_objectObject

Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose object is the RDF resource represented by the receiver



122
123
124
# File 'lib/jekyll/drops/rdf_resource.rb', line 122

def statements_as_object
  @statements_as_object ||= statements_as :object
end

#statements_as_predicateObject

Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose predicate is the RDF resource represented by the receiver



115
116
117
# File 'lib/jekyll/drops/rdf_resource.rb', line 115

def statements_as_predicate
  @statements_as_predicate ||= statements_as :predicate
end

#statements_as_subjectObject

Return a list of Jekyll::JekyllRdf::Drops::RdfStatements whose subject is the RDF resource represented by the receiver



108
109
110
# File 'lib/jekyll/drops/rdf_resource.rb', line 108

def statements_as_subject
  @statements_as_subject ||= statements_as :subject
end