Class: RDF::NQuads::Format

Inherits:
Format show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/nquads.rb

Overview

N-Quads format specification.

Examples:

Obtaining an NQuads format class

RDF::Format.for(:nquads)     #=> RDF::NQuads::Format
RDF::Format.for("etc/doap.nq")
RDF::Format.for(file_name:      "etc/doap.nq")
RDF::Format.for(file_extension: "nq")
RDF::Format.for(content_type:   "application/n-quads")

See Also:

Since:

  • 0.4.0

Class Method Summary collapse

Methods inherited from Format

accept_type, accept_types, cli_commands, content_encoding, content_type, content_types, each, file_extension, file_extensions, for, reader, reader_symbols, reader_types, require, symbols, to_sym, writer, writer_symbols, writer_types

Class Method Details

.detect(sample) ⇒ Boolean

Sample detection to see if it matches N-Quads (or N-Triples)

Use a text sample to detect the format of an input file. Sub-classes implement a matcher sufficient to detect probably format matches, including disambiguating between other similar formats.

Parameters:

  • sample (String)

    Beginning several bytes (about 1K) of input.

Returns:

  • (Boolean)

Since:

  • 0.4.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/nquads.rb', line 38

def self.detect(sample)
  !!sample.match(%r(
    (?:\s*(?:<[^>]*>) | (?:_:\w+))                          # Subject
    \s*
    (?:\s*<[^>]*>)                                          # Predicate
    \s*
    (?:(?:<[^>]*>) | (?:_:\w+) | (?:"[^"\n]*"(?:^^|@\S+)?)) # Object
    \s*
    (?:\s*(?:<[^>]*>) | (?:_:\w+))                          # Graph Name
    \s*\.
  )x) && !(
    sample.match(%r(@(base|prefix|keywords)|\{)) ||         # Not Turtle/N3/TriG
    sample.match(%r(<(html|rdf))i)                          # Not HTML or XML
  )
end

.nameObject

Human readable name for this format

Since:

  • 0.4.0



55
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-491e9bb5b443/lib/rdf/nquads.rb', line 55

def self.name; "N-Quads"; end