Module: RDF

Defined in:
lib/rdf.rb,
lib/rdf/cli.rb,
lib/rdf/util.rb,
lib/rdf/query.rb,
lib/rdf/format.rb,
lib/rdf/nquads.rb,
lib/rdf/reader.rb,
lib/rdf/writer.rb,
lib/rdf/version.rb,
lib/rdf/ntriples.rb,
lib/rdf/changeset.rb,
lib/rdf/model/uri.rb,
lib/rdf/util/file.rb,
lib/rdf/util/uuid.rb,
lib/rdf/vocab/owl.rb,
lib/rdf/vocab/xsd.rb,
lib/rdf/model/list.rb,
lib/rdf/model/node.rb,
lib/rdf/model/term.rb,
lib/rdf/repository.rb,
lib/rdf/util/cache.rb,
lib/rdf/vocab/rdfs.rb,
lib/rdf/vocab/rdfv.rb,
lib/rdf/vocabulary.rb,
lib/rdf/model/graph.rb,
lib/rdf/model/value.rb,
lib/rdf/transaction.rb,
lib/rdf/util/logger.rb,
lib/rdf/vocab/writer.rb,
lib/rdf/mixin/durable.rb,
lib/rdf/mixin/mutable.rb,
lib/rdf/model/dataset.rb,
lib/rdf/model/literal.rb,
lib/rdf/query/pattern.rb,
lib/rdf/util/aliasing.rb,
lib/rdf/mixin/readable.rb,
lib/rdf/mixin/writable.rb,
lib/rdf/model/resource.rb,
lib/rdf/util/coercions.rb,
lib/rdf/mixin/countable.rb,
lib/rdf/mixin/indexable.rb,
lib/rdf/mixin/queryable.rb,
lib/rdf/model/statement.rb,
lib/rdf/query/solutions.rb,
lib/rdf/mixin/enumerable.rb,
lib/rdf/mixin/enumerator.rb,
lib/rdf/mixin/type_check.rb,
lib/rdf/mixin/transactable.rb,
lib/rdf/model/literal/date.rb,
lib/rdf/model/literal/time.rb,
lib/rdf/model/literal/token.rb,
lib/rdf/model/literal/double.rb,
lib/rdf/model/literal/boolean.rb,
lib/rdf/model/literal/decimal.rb,
lib/rdf/model/literal/integer.rb,
lib/rdf/model/literal/numeric.rb,
lib/rdf/model/literal/datetime.rb,
lib/rdf/query/hash_pattern_normalizer.rb

Defined Under Namespace

Modules: Countable, Durable, Enumerable, Indexable, Mutable, NQuads, NTriples, Queryable, Readable, Resource, Term, Transactable, TypeCheck, Util, VERSION, Value, Writable Classes: CLI, Changeset, Dataset, Format, FormatError, Graph, List, Literal, Node, OWL, Query, RDFS, RDFV, Reader, ReaderError, Repository, Statement, StrictVocabulary, Transaction, URI, Vocabulary, Writer, WriterError, XSD

Constant Summary collapse

VOCABS =
{
  owl: {uri: "http://www.w3.org/2002/07/owl#", class_name: "OWL"},
  rdfs: {uri: "http://www.w3.org/2000/01/rdf-schema#", class_name: "RDFS"},
  rdfv: {uri: "http://www.w3.org/1999/02/22-rdf-syntax-ns#", class_name: "RDFV"},
  xsd: {uri: "http://www.w3.org/2001/XMLSchema#", class_name: "XSD"},
}
RDF_N_REGEXP =
%r{_\d+}.freeze
IRI =

RDF::IRI is a synonym for RDF::URI

URI

Class Method Summary collapse

Class Method Details

.[](property) ⇒ #to_s, URI

Returns:

  • (#to_s)

    property

  • (URI)

239
240
241
# File 'lib/rdf.rb', line 239

def self.[](property)
  property.to_s.match?(%r{_\d+}) ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV[property]
end

.configObject

Note:

cache configurations must be set before initial use, when the caches are allocated.

Configuration, used open for configuring constants used within the codebase.

Defaults:

  • cache_size: -1
  • uri_cache_size: cache_size
  • node_cache_size: cache_size

Examples:

set default cache size to be at most 10,000 entries


RDF.config.cache_size = 10_000

set cache size for interned URIs to 5,000 entries


RDF.config.uri_cache_size = 5_000

Returns:

  • (Object)

See Also:

  • RDF::Util::Cache.new

102
103
104
# File 'lib/rdf.rb', line 102

def self.config
  @config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
end

.enum_for(method = :each_statement, *args) ⇒ RDF::Enumerable::Enumerator Also known as: to_enum

Return an enumerator over Statement defined for this vocabulary.

Returns:

See Also:

  • Object#enum_for

247
248
249
250
251
252
# File 'lib/rdf.rb', line 247

def self.enum_for(method = :each_statement, *args)
  # Ensure that enumerators are, themselves, queryable
  Enumerable::Enumerator.new do |yielder|
    RDF::RDFV.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)}
  end
end

.Graph(**options, &block) ⇒ RDF::Graph

Alias for RDF::Graph.new.

Parameters:

  • graph_name (RDF::Resource)

    The graph_name from the associated Queryable associated with this graph as provided with the :data option (only for Queryable instances supporting named graphs).

  • data (RDF::Queryable)

    (RDF::Repository.new) Storage behind this graph.

Returns:


157
158
159
# File 'lib/rdf.rb', line 157

def self.Graph(**options, &block)
  Graph.new(**options, &block)
end

.ListRDF::URI .List(*args) ⇒ RDF::List .List(array) ⇒ RDF::List .List(list) ⇒ RDF::List

Overloads:


176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rdf.rb', line 176

def self.List(*args)
  case
  when args.empty?
    RDF[:List]
  when args.length == 1 && args.first.is_a?(RDF::List)
    args.first
  when args.length == 1 && args.first.is_a?(Array)
    List[*args.first]
  else
    List[*args]
  end
end

.Literal(literal, **options) ⇒ RDF::Literal

Alias for RDF::Literal.new.

Parameters:

  • value (Object)
  • language (Symbol)

    (nil) Language is downcased to ensure proper matching

  • lexical (String)

    (nil) Supplied lexical representation of this literal, otherwise it comes from transforming value to a string form..

  • datatype (URI)

    (nil)

  • validate (Boolean)

    (false)

  • canonicalize (Boolean)

    (false)

Returns:


145
146
147
148
149
150
# File 'lib/rdf.rb', line 145

def self.Literal(literal, **options)
  case literal
    when RDF::Literal then literal
    else Literal.new(literal, **options)
  end
end

.method_missing(property, *args, &block) ⇒ Object

Delegate other methods to RDF::RDFV


267
268
269
270
271
272
273
274
# File 'lib/rdf.rb', line 267

def self.method_missing(property, *args, &block)
  if args.empty?
    # Special-case rdf:_n for all integers
    RDF_N_REGEXP.match?(property) ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV.send(property)
  else
    super
  end
end

.Node(*args) ⇒ RDF::Node

Alias for RDF::Node.new.

Parameters:

  • id (#to_s)

Returns:


120
121
122
# File 'lib/rdf.rb', line 120

def self.Node(*args)
  Node.new(*args)
end

.Resource(*args) ⇒ RDF::Resource

Alias for RDF::Resource.new.

Returns:


111
112
113
# File 'lib/rdf.rb', line 111

def self.Resource(*args)
  Resource.new(*args)
end

.respond_to?(method, include_all = false) ⇒ Boolean

respond to module or RDFV

Returns:

  • (Boolean)

259
260
261
# File 'lib/rdf.rb', line 259

def self.respond_to?(method, include_all = false)
  super || RDF::RDFV.respond_to?(method, include_all)
end

.StatementRDF::URI .Statement(**options) ⇒ RDF::Statement .Statement(subject, predicate, object, **options) ⇒ RDF::Statement

Overloads:


210
211
212
213
214
215
216
# File 'lib/rdf.rb', line 210

def self.Statement(*args, **options)
  if args.empty? && options.empty?
    RDF[:Statement]
  else
    Statement.new(*args, **options)
  end
end

.StrictVocabulary(uri) ⇒ Class

Alias for RDF::StrictVocabulary.create.

Parameters:

Returns:

  • (Class)

232
233
234
# File 'lib/rdf.rb', line 232

def self.StrictVocabulary(uri)
  StrictVocabulary.create(uri)
end

.URI(*args) ⇒ RDF::URI

Cast to a URI. If already a URI, return the passed argument.

Returns:


129
130
131
132
133
134
135
136
137
138
# File 'lib/rdf.rb', line 129

def self.URI(*args)
  if args.first.respond_to?(:to_uri)
    args.first.to_uri
  elsif args.first.is_a?(Hash)
    URI.new(**args.first)
  else
    opts = args.last.is_a?(Hash) ? args.pop : {}
    URI.new(*args, **opts)
  end
end

.Vocabulary(uri) ⇒ Class

Alias for RDF::Vocabulary.create.

Parameters:

Returns:

  • (Class)

223
224
225
# File 'lib/rdf.rb', line 223

def self.Vocabulary(uri)
  Vocabulary.create(uri)
end