Class: RDF::Raptor::Turtle::Format

Inherits:
Format
  • Object
show all
Extended by:
Format
Defined in:
lib/rdf/raptor/turtle.rb

Overview

Turtle format specification.

Examples:

Obtaining a Turtle format class

RDF::Format.for(:turtle)       #=> RDF::Raptor::Turtle::Format
RDF::Format.for("input.ttl")
RDF::Format.for(file_name:      "input.ttl")
RDF::Format.for(file_extension: "ttl")
RDF::Format.for(content_type:   "text/turtle")

Class Method Summary collapse

Methods included from Format

detect, rapper_format

Class Method Details

.detect(sample) ⇒ Boolean

Sample detection to see if it matches Turtle (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 (~ 1K) of input.

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rdf/raptor/turtle.rb', line 53

def self.detect(sample)
  !!sample.match(%r(
    (?:@(base|prefix)) |                                            # Turtle keywords
    ["']{3} |                                                       # STRING_LITERAL_LONG_SINGLE_QUOTE/2
    "[^"]*"^^ | "[^"]*"@ |                                          # Typed/Language literals
    (?:
      (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))\s*[,;]) ||
      (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))){3}
    )
  )mx) && !(
    sample.match(%r([{}])) ||                                       # TriG
    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

.symbolsObject



71
72
73
# File 'lib/rdf/raptor/turtle.rb', line 71

def self.symbols
  [:turtle, :ttl]
end