Class: RDF::NTriples::Format

Inherits:
Format show all
Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/ntriples/format.rb

Overview

N-Triples format specification.

Note: Latest standards activities treat N-Triples as a subset of Turtle. This includes application/n-triples mime type and a new default encoding of utf-8.

Examples:

Obtaining an NTriples format class

RDF::Format.for(:ntriples)     #=> RDF::NTriples::Format
RDF::Format.for("etc/doap.nt")
RDF::Format.for(file_name:      "etc/doap.nt")
RDF::Format.for(file_extension: "nt")
RDF::Format.for(content_type:   "application/n-triples")

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, 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-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)


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/ntriples/format.rb', line 34

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

.nameObject

Human readable name for this format



49
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-da525ad24ff7/lib/rdf/ntriples/format.rb', line 49

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