Class: RDF::NTriples::Format
- Defined in:
- lib/rdf/ntriples/format.rb
Overview
N-Triples format specification.
Note: Latest standards activities treat N-Triples as a subset of Turtle. This includes text/ntriples+turtle mime type and a new default encoding of utf-8.
Class Method Summary collapse
-
.detect(sample) ⇒ Boolean
Sample detection to see if it matches N-Triples.
Methods inherited from Format
content_type, content_types, each, file_extensions, for, reader, to_sym, writer
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rdf/ntriples/format.rb', line 34 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 |