Class: RDF::TriG::Format

Inherits:
Format show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trig-ccb51eff7022/lib/rdf/trig/format.rb

Overview

TriG format specification.

Examples:

Obtaining an TriG format class

RDF::Format.for("etc/foaf.trig")
RDF::Format.for(:file_name      => "etc/foaf.trig")
RDF::Format.for(file_extension: "trig")
RDF::Format.for(:content_type   => "application/trig")

Obtaining serialization format MIME types

RDF::Format.content_types      #=> {"application/trig" => [RDF::TriG::Format]}

Obtaining serialization format file extension mappings

RDF::Format.file_extensions    #=> {trig: "application/trig"}

See Also:

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, name, reader, reader_symbols, reader_types, require, symbols, to_sym, uri, uris, writer, writer_symbols, writer_types

Class Method Details

.detect(sample) ⇒ Boolean

Sample detection to see if it matches TriG

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 (~ 1K) of input.

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-trig-ccb51eff7022/lib/rdf/trig/format.rb', line 37

def self.detect(sample)
  !!sample.match(%r(
    (?:
      (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*")))?           # IRIref
      \s*\{                                                         # Graph Start
      (?:
        (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))\s*[,;]) ||
        (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:["']+[^"']*["']+))){3}
      )*                                                            # triples
      [\s\.]*\}\s*                                                  # Graph end
    )
  )mx) && !(
    sample.match(%r(@keywords|=)) ||                                # N3
    sample.match(%r(<(?:\/|html|rdf))i) ||                          # HTML, RDF/XML
    sample.match(%r(^(?:\s*<[^>]*>){4}.*\.\s*$)) ||                 # N-Quads
    sample.match(%r("@(context|subject|iri)"))                      # JSON-LD
  )
end