From d4f9b491e04a588875a05208ee5033fa60281686 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 1 Nov 2013 17:20:07 -0700 Subject: [PATCH] Don't auto detect N3 format, as it's too easily confused with Turtle. --- lib/rdf/n3/format.rb | 25 ------------------------- spec/format_spec.rb | 8 ++++---- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/lib/rdf/n3/format.rb b/lib/rdf/n3/format.rb index ec6f876..5a09135 100644 --- a/lib/rdf/n3/format.rb +++ b/lib/rdf/n3/format.rb @@ -22,31 +22,6 @@ class Format < RDF::Format reader { RDF::N3::Reader } writer { RDF::N3::Writer } - - ## - # Sample detection to see if it matches N3 (or N-Triples or Turtle) - # - # 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 (~ 1K) of input. - # @return [Boolean] - def self.detect(sample) - !!sample.match(%r( - (?:@(base|prefix|keywords)) | # N3 keywords - "{3} | # Multi-line quotes - "[^"]*"^^ | "[^"]*"@ | # Typed/Language literals - (?: - (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))\s*[,;]) || - (?:\s*(?:(?:<[^>]*>) | (?:\w*:\w+) | (?:"[^"]*"))){3} - ) - )mx) && !( - 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 end # Alias for N3 format diff --git a/spec/format_spec.rb b/spec/format_spec.rb index f0f4630..6d2d28c 100644 --- a/spec/format_spec.rb +++ b/spec/format_spec.rb @@ -29,8 +29,8 @@ :n3 => "@prefix foo: .\nfoo:bar = { } .", :default_prefix => ':a :b :c .', }.each do |sym, str| - it "detects #{sym}" do - @format_class.for {str}.should == @format_class + it "does not detect #{sym}" do + expect(@format_class.for {str}).not_to eq @format_class end end @@ -53,8 +53,8 @@ :n3 => "@prefix foo: .\nfoo:bar = { } .", :default_prefix => ':a :b :c .', }.each do |sym, str| - it "detects #{sym}" do - @format_class.detect(str).should be_true + it "does not detect #{sym}" do + expect(@format_class.detect(str)).not_to be_true end end