Class: RDF::TriG::Format
- Inherits:
-
Format
- Object
- Format
- RDF::TriG::Format
- Defined in:
- lib/rdf/trig/format.rb
Overview
TriG format specification.
Class Method Summary collapse
-
.detect(sample) ⇒ Boolean
Sample detection to see if it matches TriG.
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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File '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 |