Class: RDF::Vocabulary
- Extended by:
- Enumerable
- Defined in:
- vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb,
vendor/bundler/ruby/2.6.0/bundler/gems/rdf-vocab-40ca73b6634e/lib/rdf/vocab/extensions.rb,
vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocab/writer.rb
Overview
Vocabulary format specification. This can be used to generate a Ruby class definition from a loaded vocabulary.
Definitions can include recursive term definitions, when the value of a property is a blank-node term. They can also include list definitions, to provide a reasonable way to represent owl:unionOf
-type relationships.
Direct Known Subclasses
HCalendar, HCard, LOG, MD, RDFA, REI, StrictVocabulary, RDF::Vocab::DWC, RDF::Vocab::LDP, RDF::Vocab::LRMI, RDF::Vocab::MA, RDF::Vocab::MO, RDF::Vocab::OG, RDF::Vocab::OGC, RDF::Vocab::XHTML, RDF::Vocab::XHV, XML, XSD, XSI
Defined Under Namespace
Modules: Term, VocabFormatExtensions Classes: Format, Writer
Class Method Summary collapse
-
.[](property) ⇒ RDF::URI
Returns the URI for the term
property
in this vocabulary. -
.__prefix__ ⇒ Symbol
Returns a suggested CURIE/PName prefix for this vocabulary class.
-
._orig_each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
- .camelize(str) ⇒ Object protected
-
.each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
-
.each_statement {|| ... } ⇒ Object
Enumerate each statement constructed from the defined vocabulary terms.
-
.enum_for(method = :each_statement, *args) ⇒ RDF::Enumerable::Enumerator
(also: to_enum)
Return an enumerator over Statement defined for this vocabulary.
-
.expand_pname(pname) ⇒ Term
Attempt to expand a Compact IRI/PName/QName using loaded vocabularies.
-
.find(uri) ⇒ Vocabulary
Return the Vocabulary associated with a URI.
-
.find_term(uri) ⇒ Vocabulary::Term
Return the Vocabulary term associated with a URI.
-
.from_graph(graph, url: nil, class_name: nil, extra: nil) ⇒ RDF::Vocabulary
Create a vocabulary from a graph or enumerable.
-
.imported_from ⇒ Array<RDF::Vocabulary>
List of vocabularies which import this vocabulary.
-
.imports ⇒ Array<RDF::Vocabulary>
(also: __imports__)
List of vocabularies this vocabulary
owl:imports
. -
.inspect ⇒ String
Returns a developer-friendly representation of this vocabulary class.
-
.list(*values) ⇒ RDF::List
protected
Create a list of terms.
- .method_missing(property, *args, &block) ⇒ Object protected
- .ontology(*args) ⇒ Object (also: __ontology__)
-
.properties ⇒ Object
(also: __properties__)
@return [ArrayRDF::URI] a list of properties in the current vocabulary.
- .property(*args) ⇒ Object (also: term, __property__)
-
.strict? ⇒ Boolean
Is this a strict vocabulary, or a liberal vocabulary allowing arbitrary properties?.
-
.to_html(graph: nil, prefixes: nil, jsonld: nil, template: nil) ⇒ String
Generate HTML+RDFa representation, specific to vocabularies.
-
.to_iri ⇒ RDF::URI
Returns the base URI for this vocabulary class.
-
.to_s ⇒ String
Returns a string representation of this vocabulary class.
-
.to_uri ⇒ RDF::URI
Returns the base URI for this vocabulary class.
-
.value_to_html(property, value, tag) ⇒ Object
Create HTML for values (Helper method, needs to be public).
Instance Method Summary collapse
-
#[](property) ⇒ URI
Returns the URI for the term
property
in this vocabulary. -
#initialize(uri) ⇒ Vocabulary
constructor
A new instance of Vocabulary.
-
#inspect ⇒ String
Returns a developer-friendly representation of this vocabulary.
- #method_missing(property, *args, &block) ⇒ Object protected
-
#to_s ⇒ String
Returns a string representation of this vocabulary.
-
#to_uri ⇒ URI
(also: #to_iri)
Returns the base URI for this vocabulary.
Constructor Details
#initialize(uri) ⇒ Vocabulary
Returns a new instance of Vocabulary
629 630 631 632 633 634 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 629 def initialize(uri) @uri = case uri when RDF::URI then uri.to_s else RDF::URI.parse(uri.to_s) ? uri.to_s : nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(property, *args, &block) ⇒ Object (protected)
679 680 681 682 683 684 685 686 687 688 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 679 def method_missing(property, *args, &block) property = self.class.camelize(property.to_s) if %w(to_ary).include?(property.to_s) super elsif args.empty? self[property] else super end end |
Class Method Details
.[](property) ⇒ RDF::URI
Returns the URI for the term property
in this vocabulary.
340 341 342 343 344 345 346 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 340 def [](property) if props.has_key?(property.to_sym) props[property.to_sym] else Term.intern([to_s, property.to_s].join(''), vocab: self, attributes: {}) end end |
.__prefix__ ⇒ Symbol
Returns a suggested CURIE/PName prefix for this vocabulary class.
584 585 586 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 584 def __prefix__ __name__.split('::').last.downcase.to_sym end |
._orig_each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
17 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-vocab-40ca73b6634e/lib/rdf/vocab/extensions.rb', line 17 alias_method :_orig_each, :each |
.camelize(str) ⇒ Object (protected)
690 691 692 693 694 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 690 def self.camelize(str) str.split('_').inject([]) do |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) end.join end |
.each {|klass| ... } ⇒ Enumerator
Enumerates known RDF vocabulary classes.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 68 def each(&block) # This is needed since all vocabulary classes are defined using # Ruby's autoloading facility, meaning that `@@subclasses` will be # empty until each subclass has been touched or require'd. RDF::Vocab::VOCABS.each do |n, params| begin require "rdf/vocab/#{n}" rescue LoadError # Transient error warn "Failed to load #{n}" end end _orig_each(&block) end |
.each_statement {|| ... } ⇒ Object
405 406 407 408 409 410 411 412 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 405 def each_statement(&block) props.each do |name, subject| subject.each_statement(&block) end # Also include the ontology, if it's not also a property @ontology.each_statement(&block) if @ontology && @ontology != self end |
.enum_for(method = :each_statement, *args) ⇒ RDF::Enumerable::Enumerator Also known as: to_enum
Return an enumerator over Statement defined for this vocabulary.
389 390 391 392 393 394 395 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 389 def enum_for(method = :each_statement, *args) # Ensure that enumerators are, themselves, queryable this = self Enumerable::Enumerator.new do |yielder| this.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)} end end |
.expand_pname(pname) ⇒ Term
Attempt to expand a Compact IRI/PName/QName using loaded vocabularies
289 290 291 292 293 294 295 296 297 298 299 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 289 def (pname) return pname unless pname.is_a?(String) || pname.is_a?(Symbol) prefix, suffix = pname.to_s.split(":", 2) if prefix == "rdf" RDF[suffix] elsif vocab = RDF::Vocabulary.each.detect {|v| v.__name__ && v.__prefix__ == prefix.to_sym} suffix.to_s.empty? ? vocab.to_uri : vocab[suffix] else (RDF::Vocabulary.find_term(pname) rescue nil) || RDF::URI(pname, validate: true) end end |
.find(uri) ⇒ Vocabulary
Return the Vocabulary associated with a URI. Allows the trailing '/' or '#' to be excluded
306 307 308 309 310 311 312 313 314 315 316 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 306 def find(uri) uri = RDF::URI(uri) if uri.is_a?(String) return nil unless uri.uri? && uri.valid? RDF::Vocabulary.detect do |v| if uri.length >= v.to_uri.length uri.start_with?(v.to_uri) else v.to_uri.to_s.sub(%r([/#]$), '') == uri.to_s end end end |
.find_term(uri) ⇒ Vocabulary::Term
Return the Vocabulary term associated with a URI
323 324 325 326 327 328 329 330 331 332 333 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 323 def find_term(uri) uri = RDF::URI(uri) return uri if uri.is_a?(Vocabulary::Term) if vocab = find(uri) if vocab.ontology == uri vocab.ontology else vocab[uri.to_s[vocab.to_uri.to_s.length..-1].to_s] end end end |
.from_graph(graph, url: nil, class_name: nil, extra: nil) ⇒ RDF::Vocabulary
Create a vocabulary from a graph or enumerable
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 432 def from_graph(graph, url: nil, class_name: nil, extra: nil) vocab = case class_name when RDF::Vocabulary class_name.instance_variable_set(:@ontology, nil) class_name.instance_variable_set(:@properties, nil) class_name when String Object.const_set(class_name, Class.new(self.create(url))) else Class.new(self.create(url)) end ont_url = url.to_s.sub(%r([/#]$), '') term_defs = {} = {} graph.each do |statement| #next unless statement.subject.uri? if statement.subject.start_with?(url) || statement.subject == ont_url name = statement.subject.to_s[url.to_s.length..-1].to_s term = (term_defs[name.to_sym] ||= {}) else # subject is not a URI or is not associated with the vocabulary term = ([statement.subject] ||= {}) end key = case statement.predicate when RDF.type then :type when RDF::RDFS.comment then :comment when RDF::RDFS.domain then :domain when RDF::RDFS.isDefinedBy then :isDefinedBy when RDF::RDFS.label then :label when RDF::RDFS.range then :range when RDF::RDFS.subClassOf then :subClassOf when RDF::RDFS.subPropertyOf then :subPropertyOf when RDF::URI("http://schema.org/domainIncludes") then :domainIncludes when RDF::URI("http://schema.org/rangeIncludes") then :rangeIncludes when RDF::URI("http://www.w3.org/2002/07/owl#allValuesFrom") then :allValuesFrom when RDF::URI("http://www.w3.org/2002/07/owl#cardinality") then :cardinality when RDF::URI("http://www.w3.org/2002/07/owl#equivalentClass") then :equivalentClass when RDF::URI("http://www.w3.org/2002/07/owl#equivalentProperty") then :equivalentProperty when RDF::URI("http://www.w3.org/2002/07/owl#intersectionOf") then :intersectionOf when RDF::URI("http://www.w3.org/2002/07/owl#inverseOf") then :inverseOf when RDF::URI("http://www.w3.org/2002/07/owl#maxCardinality") then :maxCardinality when RDF::URI("http://www.w3.org/2002/07/owl#minCardinality") then :minCardinality when RDF::URI("http://www.w3.org/2002/07/owl#onProperty") then :onProperty when RDF::URI("http://www.w3.org/2002/07/owl#someValuesFrom") then :someValuesFrom when RDF::URI("http://www.w3.org/2002/07/owl#unionOf") then :unionOf when RDF::URI("http://www.w3.org/2004/02/skos/core#altLabel") then :altLabel when RDF::URI("http://www.w3.org/2004/02/skos/core#broader") then :broader when RDF::URI("http://www.w3.org/2004/02/skos/core#definition") then :definition when RDF::URI("http://www.w3.org/2004/02/skos/core#editorialNote") then :editorialNote when RDF::URI("http://www.w3.org/2004/02/skos/core#exactMatch") then :exactMatch when RDF::URI("http://www.w3.org/2004/02/skos/core#hasTopConcept") then :hasTopConcept when RDF::URI("http://www.w3.org/2004/02/skos/core#inScheme") then :inScheme when RDF::URI("http://www.w3.org/2004/02/skos/core#member") then :member when RDF::URI("http://www.w3.org/2004/02/skos/core#narrower") then :narrower when RDF::URI("http://www.w3.org/2004/02/skos/core#notation") then :notation when RDF::URI("http://www.w3.org/2004/02/skos/core#note") then :note when RDF::URI("http://www.w3.org/2004/02/skos/core#prefLabel") then :prefLabel when RDF::URI("http://www.w3.org/2004/02/skos/core#related") then :related else statement.predicate.pname.to_sym end # Skip literals other than plain or english # This is because the ruby representation does not preserve language next if statement.object.literal? && (statement.object.language || :en).to_s !~ /^en-?/ (term[key] ||= []) << statement.object end # Create extra terms term_defs = case extra when Array extra.inject({}) {|memo, s| memo[s.to_sym] = {}; memo}.merge(term_defs) when Hash extra.merge(term_defs) else term_defs end # Pass over embedded_defs with anonymous references, once .each do |term, attributes| attributes.each do |ak, avs| # Turn embedded BNodes into either their Term definition or a List avs = [avs] unless avs.is_a?(Array) attributes[ak] = avs.map do |av| l = RDF::List.new(subject: av, graph: graph) if l.valid? RDF::List.new(subject: av) do |nl| l.each do |lv| nl << ([lv] ? Term.new(vocab: vocab, attributes: [lv]) : lv) end end elsif av.is_a?(RDF::Node) Term.new(vocab: vocab, attributes: [av]) if [av] else av end end.compact end end term_defs.each do |term, attributes| # Turn embedded BNodes into either their Term definition or a List attributes.each do |ak, avs| attributes[ak] = avs.is_a?(Array) ? (avs.map do |av| l = RDF::List.new(subject: av, graph: graph) if l.valid? RDF::List.new(subject: av) do |nl| l.each do |lv| nl << ([lv] ? Term.new(vocab: vocab, attributes: [lv]) : lv) end end elsif av.is_a?(RDF::Node) Term.new(vocab: vocab, attributes: [av]) if [av] else av end end).compact : avs end if term == :"" vocab.__ontology__ vocab, attributes else vocab.__property__ term, attributes end end vocab end |
.imported_from ⇒ Array<RDF::Vocabulary>
List of vocabularies which import this vocabulary
368 369 370 371 372 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 368 def imported_from @imported_from ||= begin RDF::Vocabulary.select {|v| v.__imports__.include?(self)} end end |
.imports ⇒ Array<RDF::Vocabulary> Also known as: __imports__
the alias <strong>imports</strong> guards against RDF::OWL.imports
returning a term, rather than an array of vocabularies
List of vocabularies this vocabulary owl:imports
353 354 355 356 357 358 359 360 361 362 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 353 def imports return [] unless self.ontology @imports ||= begin Array(self.ontology.attributes[:"owl:imports"]).map do |pn| find((pn)) rescue nil end.compact rescue KeyError [] end end |
.inspect ⇒ String
Returns a developer-friendly representation of this vocabulary class.
567 568 569 570 571 572 573 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 567 def inspect if self == Vocabulary self.to_s else sprintf("%s(%s)", superclass.to_s, to_s) end end |
.list(*values) ⇒ RDF::List (protected)
Create a list of terms
612 613 614 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 612 def list(*values) RDF::List[*values.map {|v| (v) rescue RDF::Literal(v)}] end |
.method_missing(property, *args, &block) ⇒ Object (protected)
599 600 601 602 603 604 605 606 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 599 def method_missing(property, *args, &block) property = RDF::Vocabulary.camelize(property.to_s) if args.empty? && !to_s.empty? Term.intern([to_s, property.to_s].join(''), vocab: self, attributes: {}) else super end end |
.ontology ⇒ RDF::Vocabulary::Term .ontology(name, options) ⇒ RDF::Vocabulary::Term Also known as: __ontology__
If the ontology URI has the vocabulary namespace URI as a prefix, it may also be defined using #property
or #term
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 257 def ontology(*args) case args.length when 0 @ontology else uri, = args URI.cache.delete(uri.to_s.to_sym) # Clear any previous entry # Term attributes passed in a block for lazy evaluation. This helps to avoid load-time circular dependencies @ontology = Term.intern(uri.to_s, vocab: self, attributes: ) # If the URI is the same as the vocabulary namespace, also define it as a term props[:""] ||= @ontology if self.to_s == uri.to_s @ontology end end |
.properties ⇒ Object Also known as: __properties__
@return [ArrayRDF::URI] a list of properties in the current vocabulary
277 278 279 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 277 def properties props.values end |
.property ⇒ RDF::Vocabulary::Term .property(name, options) ⇒ RDF::Vocabulary::Term Also known as: term, __property__
189 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 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 189 def property(*args) case args.length when 0 Term.intern("#{self}property", vocab: self, attributes: {}) else name = args.shift unless args.first.is_a?(Hash) = args.last if name uri_str = [to_s, name.to_s].join('') URI.cache.delete(uri_str.to_sym) # Clear any previous entry # Term attributes passed in a block for lazy evaluation. This helps to avoid load-time circular dependencies prop = Term.intern(uri_str, vocab: self, attributes: ) props[name.to_sym] = prop # If name is empty, also treat it as the ontology @ontology ||= prop if name.to_s.empty? # Define an accessor, except for problematic properties (class << self; self; end).send(:define_method, name) { prop } unless %w(property hash).include?(name.to_s) else # Define the term without a name # Term attributes passed in a block for lazy evaluation. This helps to avoid load-time circular dependencies prop = Term.new(vocab: self, attributes: ) end prop end end |
.strict? ⇒ Boolean
Is this a strict vocabulary, or a liberal vocabulary allowing arbitrary properties?
82 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 82 def strict?; false; end |
.to_html(graph: nil, prefixes: nil, jsonld: nil, template: nil) ⇒ String
Generate HTML+RDFa representation, specific to vocabularies. This uses generated JSON-LD and a Haml template.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-vocab-40ca73b6634e/lib/rdf/vocab/extensions.rb', line 276 def to_html(graph: nil, prefixes: nil, jsonld: nil, template: nil) # Find namespaces used in the vocabulary graph = RDF::Graph.new {|g| each_statement {|s| g << s}} if graph.nil? || graph.empty? # Get JSON as an object json = case jsonld when String then ::JSON.parse(File.read jsonld) when Hash then jsonld else ::JSON.parse(to_jsonld(graph: graph, prefixes: prefixes)) end raise "Expected JSON-LD data within the '@graph' key" unless json.has_key?('@graph') template ||= File.("../../../../etc/template.erb", __FILE__) prefixes = vocab_prefixes(graph).merge(prefixes || {}) prefixes[:owl] = RDF::OWL.to_uri.to_s # Make sure ontology is typed json['@graph']['@type'] ||= ['owl:Ontology'] jld_context = ::JSON::LD::Context.new.parse([json['@context'], json['@graph']['@context']]) # Expand the JSON-LD to normalize accesses = ::JSON::LD::API.(json).first .delete('@reverse') # Re-compact keys = .inject({}) do |memo, (k, v)| term = RDF::Vocabulary.find_term(k) k = term.pname if term memo.merge(k => v) end # Normalize label accessors ['rdfs:label'] ||= %w(dc:title dc11:title skos:prefLabel).inject(nil) do |memo, key| memo || [key] end || [{'@value' => json['@graph']['@id']}] %w(rdfs_classes rdfs_properties rdfs_datatypes rdfs_instances).each do |section| next unless json['@graph'][section] json['@graph'][section].each do |node| node['rdfs:label'] ||= %w(dc:title dc11:title skos:prefLabel).inject do |memo, key| memo || node[key] end || [{'@value' => node['@id']}] end end # Expand each part separately, as well. %w(rdfs_classes rdfs_properties rdfs_datatypes rdfs_instances).each do |section| next unless json['@graph'][section] = ::JSON::LD::API.(json['@graph'][section], expandContext: jld_context) # Re-compact keys [section] = .map do |node| node.inject({}) do |memo, (k, v)| term = RDF::Vocabulary.find_term(k) k = term.pname if term memo.merge(k => v) end end end # Template invoked with expanded JSON-LD with outer object including `rdfs_classes`, `rdfs_properties`, and `rdf_instances` sections. case template when /.haml$/ require 'haml' haml = Haml::Engine.new(File.read(template)) haml.render(self, ont: , context: json['@context'], prefixes: prefixes) when /.erb$/ require 'erubis' eruby = Erubis::FastEruby.new(File.read(template)) result = eruby.evaluate(binding: self, ont: , context: json['@context'], prefixes: prefixes) else raise "Unknown template type #{template}. Should have '.erb' or '.haml' extension" end end |
.to_iri ⇒ RDF::URI
Returns the base URI for this vocabulary class. For IRI compatibility
383 384 385 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 383 def to_uri RDF::URI.intern(@@uris[self].to_s) end |
.to_s ⇒ String
Returns a string representation of this vocabulary class.
418 419 420 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 418 def to_s @@uris.has_key?(self) ? @@uris[self].to_s : super end |
.to_uri ⇒ RDF::URI
Returns the base URI for this vocabulary class.
378 379 380 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 378 def to_uri RDF::URI.intern(@@uris[self].to_s) end |
.value_to_html(property, value, tag) ⇒ Object
Create HTML for values (Helper method, needs to be public)
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-vocab-40ca73b6634e/lib/rdf/vocab/extensions.rb', line 354 def value_to_html(property, value, tag) value.map do |v| %(<#{tag} property="#{property}") + if v['@value'] (v['@language'] ? %( lang="#{v['@language']}") : "") + (v['@type'] ? %( datatype="#{RDF::URI(v['@type']).pname}") : "") + %(>#{v['@value']}) elsif v['@id'] %( resource="#{RDF::URI(v['@id']).pname}">#{RDF::URI(v['@id']).pname}) else raise "Unknown value type: #{v.inspect}, #{property}" end + %(</#{tag}>) end.join("\n") end |
Instance Method Details
#[](property) ⇒ URI
Returns the URI for the term property
in this vocabulary.
641 642 643 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 641 def [](property) Term.intern([to_s, property.to_s].join(''), vocab: self.class, attributes: {}) end |
#inspect ⇒ String
Returns a developer-friendly representation of this vocabulary.
668 669 670 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 668 def inspect sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s) end |
#to_s ⇒ String
Returns a string representation of this vocabulary.
660 661 662 |
# File 'vendor/bundler/ruby/2.6.0/bundler/gems/rdf-02340e834fe8/lib/rdf/vocabulary.rb', line 660 def to_s @uri.to_s end |