Sha256: b691dddc7df369815c90fd6688cf514c15af1743ba1e1ca78a35c30e2f7f6e1c

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

module RDF::NTriples
  ##
  # 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.
  #
  # @example 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")
  #   RDF::Format.for(:content_type   => "text/plain")
  #
  # @see http://www.w3.org/TR/rdf-testcases/#ntriples
  class Format < RDF::Format
    content_type     'application/n-triples', :extension => :nt, :alias => ['text/plain']
    content_encoding 'utf-8'

    reader { RDF::NTriples::Reader }
    writer { RDF::NTriples::Writer }
    
    ##
    # 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.
    #
    # @param [String] sample Beginning several bytes (about 1K) of input.
    # @return [Boolean]
    def self.detect(sample)
      !!sample.match(%r(
        (?:(?:<[^>]*>) | (?:_:\w+))                             # Subject
        \s*
        (?:<[^>]*>)                                             # Predicate
        \s*
        (?:(?:<[^>]*>) | (?:_:\w+) | (?:"[^"\n]*"(?:^^|@\S+)?)) # Object
        \s*\.
      )mx) && !(
        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

    # Human readable name for this format
    def self.name; "N-Triples"; end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rdf-1.1.0.p0 lib/rdf/ntriples/format.rb
rdf-1.0.4 lib/rdf/ntriples/format.rb
rdf-1.0.3 lib/rdf/ntriples/format.rb
rdf-1.0.2 lib/rdf/ntriples/format.rb
rdf-1.0.1 lib/rdf/ntriples/format.rb
rdf-1.0.0 lib/rdf/ntriples/format.rb
rdf-0.3.11.1 lib/rdf/ntriples/format.rb
rdf-0.3.11 lib/rdf/ntriples/format.rb
rdf-0.3.10 lib/rdf/ntriples/format.rb
rdf-0.3.9 lib/rdf/ntriples/format.rb
rdf-0.3.8 lib/rdf/ntriples/format.rb
rdf-0.3.7 lib/rdf/ntriples/format.rb