Class: YAML_LD::API
- Inherits:
-
JSON::LD::API
- Object
- JSON::LD::API
- YAML_LD::API
- Defined in:
- vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb
Overview
A YAML-LD processor based on JSON-LD.
Constant Summary collapse
- LINK_REL_CONTEXT =
The following constants are used to reduce object allocations
%w(rel http://www.w3.org/ns/yaml-ld#context).freeze
- LINK_REL_ALTERNATE =
%w(rel alternate).freeze
- LINK_TYPE_JSONLD =
%w(type application/ld+yaml).freeze
Constants inherited from JSON::LD::API
JSON::LD::API::JSON_LD_PROCESSING_MODES, JSON::LD::API::OPEN_OPTS
Constants included from RDF::Util::Logger
Constants included from JSON::LD::Compact
JSON::LD::Compact::CONTAINER_MAPPING_LANGUAGE_INDEX_ID_TYPE, JSON::LD::Compact::EXPANDED_PROPERTY_DIRECTION_INDEX_LANGUAGE_VALUE
Constants included from JSON::LD::Expand
JSON::LD::Expand::CONTAINER_INDEX_ID_TYPE, JSON::LD::Expand::KEYS_INCLUDED_TYPE_REVERSE, JSON::LD::Expand::KEYS_SET_LIST_INDEX, JSON::LD::Expand::KEYS_VALUE_LANGUAGE_TYPE_INDEX_DIRECTION, JSON::LD::Expand::KEY_ID
Instance Attribute Summary
Attributes inherited from JSON::LD::API
#context, #input, #namer, #value
Class Method Summary collapse
-
.compact(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ String
Compacts the given input according to the steps in the Compaction Algorithm.
-
.documentLoader(url, extractAllScripts: false, profile: nil, requestProfile: nil, **options) {|remote_document| ... } ⇒ Object
Default document loader for YAML_LD.
-
.expand(input, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld, RDF::URI| ... } ⇒ String
Expands the given input according to the steps in the Expansion Algorithm.
-
.flatten(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ Object, Hash
This algorithm flattens an expanded YAML-LD document by collecting all properties of a node in a single object and labeling all blank nodes with blank node identifiers.
-
.frame(input, frame, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ Object, Hash
Frames the given input using the frame according to the steps in the Framing Algorithm.
-
.fromRdf(input, useRdfType: false, useNativeTypes: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|jsonld| ... } ⇒ Object, Hash
Take an ordered list of RDF::Statements and turn them into a JSON-LD document.
-
.serializer(object, *args, **options) ⇒ Object
The default serializer for serialzing Ruby Objects to JSON.
-
.toRdf(input, expanded: false, documentLoader: self.method(:documentLoader), **options) {|statement| ... } ⇒ RDF::Enumerable
Processes the input according to the RDF Conversion Algorithm, calling the provided callback for each triple generated.
Methods inherited from JSON::LD::API
loadRemoteDocument, load_html, validate_input
Methods included from RDF::Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Methods included from JSON::LD::Frame
#cleanup_null, #cleanup_preserve, #count_blank_node_identifiers, #count_blank_node_identifiers_internal, #frame, #prune_bnodes, #remove_dependents
Methods included from JSON::LD::Utils
#add_value, #as_array, #as_resource, #blank_node?, #compare_values, #graph?, #has_value?, #index?, #list?, #node?, #node_or_ref?, #node_reference?, #property?, #simple_graph?, #value?
Methods included from JSON::LD::FromRDF
Methods included from JSON::LD::Flatten
#create_annotations, #create_node_map, #rename_bnodes
Methods included from JSON::LD::ToRDF
#item_to_rdf, #node, #parse_list
Methods included from JSON::LD::Compact
Methods included from JSON::LD::Expand
Class Method Details
.compact(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ String
Compacts the given input according to the steps in the Compaction Algorithm. The input must be copied, compacted and returned if there are no errors. If the compaction fails, an appropirate exception must be thrown.
If no context is provided, the input document is compacted using the top-level context of the document
The resulting Hash
is either returned or yielded, if a block is given.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 111 def self.compact(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **, &block) JSON::LD::API.compact(input, context, expanded: , allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', serializer: serializer, **, &block) end |
.documentLoader(url, extractAllScripts: false, profile: nil, requestProfile: nil, **options) {|remote_document| ... } ⇒ Object
Default document loader for YAML_LD.
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 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 293 def self.documentLoader(url, extractAllScripts: false, profile: nil, requestProfile: nil, **, &block) if url.respond_to?(:read) base_uri = [:base] base_uri ||= url.base_uri if url.respond_to?(:base_uri) content_type = [:content_type] content_type ||= url.content_type if url.respond_to?(:content_type) context_url = if url.respond_to?(:links) && url.links && # Any JSON type other than ld+json (content_type == 'application/json' || content_type.match?(%r(application/(^ld)+json))) link = url.links.find_link(JSON::LD::API::LINK_REL_CONTEXT) link.href if link elsif url.respond_to?(:links) && url.links && # Any YAML type content_type.match?(%r(application/(\w+\+)*yaml)) link = url.links.find_link(LINK_REL_CONTEXT) link.href if link end content = case content_type when nil, %r(application/(\w+\+)*yaml) # Parse YAML Representation.load(url.read, filename: url.to_s, **) else url.read end block.call(RemoteDocument.new(content, documentUrl: base_uri, contentType: content_type, contextUrl: context_url)) elsif url.to_s.match?(/\.yaml\w*$/) || content_type.to_s.match?(%r(application/(\w+\+)*yaml)) # Parse YAML content = Representation.load(RDF::Util::File.open_file(url.to_s).read, filename: url.to_s, **) block.call(RemoteDocument.new(content, documentUrl: base_uri, contentType: content_type, contextUrl: context_url)) else RDF::Util::File.open_file(url, **, &block) end end |
.expand(input, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld, RDF::URI| ... } ⇒ String
Expands the given input according to the steps in the Expansion Algorithm. The input must be copied, expanded and returned if there are no errors. If the expansion fails, an appropriate exception must be thrown.
The resulting Array
either returned or yielded
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 71 def self.(input, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **, &block) JSON::LD::API.(input, allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', serializer: serializer, **, &block) end |
.flatten(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ Object, Hash
This algorithm flattens an expanded YAML-LD document by collecting all properties of a node in a single object and labeling all blank nodes with blank node identifiers. This resulting uniform shape of the document, may drastically simplify the code required to process YAML-LD data in certain applications.
The resulting Array
is either returned, or yielded if a block is given.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 152 def self.flatten(input, context, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **, &block) JSON::LD::API.flatten(input, context, expanded: , allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', serializer: serializer, **, &block) end |
.frame(input, frame, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|yamlld| ... } ⇒ Object, Hash
Frames the given input using the frame according to the steps in the Framing Algorithm. The input is used to build the framed output and is returned if there are no errors. If there are no matches for the frame, null must be returned. Exceptions must be thrown if there are errors.
The resulting Array
is either returned, or yielded if a block is given.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 198 def self.frame(input, frame, expanded: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **, &block) JSON::LD::API.frame(input, frame, expanded: , allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', serializer: serializer, **, &block) end |
.fromRdf(input, useRdfType: false, useNativeTypes: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **options) {|jsonld| ... } ⇒ Object, Hash
Take an ordered list of RDF::Statements and turn them into a JSON-LD document.
The resulting Array
is either returned or yielded, if a block is given.
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 263 def self.fromRdf(input, useRdfType: false, useNativeTypes: false, documentLoader: self.method(:documentLoader), serializer: self.method(:serializer), **, &block) JSON::LD::API.fromRdf(input, allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', serializer: serializer, useRdfType: useRdfType, useNativeTypes: useNativeTypes, **, &block) end |
.serializer(object, *args, **options) ⇒ Object
The default serializer for serialzing Ruby Objects to JSON.
Defaults to MultiJson.dump
347 348 349 350 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 347 def self.serializer(object, *args, **) # de-alias any objects to avoid the use of aliases and anchors "%YAML 1.2\n" + Representation.dump(object, **) end |
.toRdf(input, expanded: false, documentLoader: self.method(:documentLoader), **options) {|statement| ... } ⇒ RDF::Enumerable
Processes the input according to the RDF Conversion Algorithm, calling the provided callback for each triple generated.
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'vendor/bundler/ruby/3.2.0/bundler/gems/yaml-ld-3ed3ab5619d8/lib/yaml_ld/api.rb', line 228 def self.toRdf(input, expanded: false, documentLoader: self.method(:documentLoader), **, &block) JSON::LD::API.toRdf(input, expanded: , allowed_content_types: %r(application/(.+\+)?yaml), documentLoader: documentLoader, extendedRepresentation: [:extendedYAML], processingMode: 'json-ld-1.1', **, &block) end |