Skip to content

Commit

Permalink
Don't auto detect N3 format, as it's too easily confused with Turtle.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Nov 2, 2013
1 parent 3ef6f3f commit d4f9b49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
25 changes: 0 additions & 25 deletions lib/rdf/n3/format.rb
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/format_spec.rb
Expand Up @@ -29,8 +29,8 @@
:n3 => "@prefix foo: <bar> .\nfoo:bar = {<a> <b> <c>} .",
: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

Expand All @@ -53,8 +53,8 @@
:n3 => "@prefix foo: <bar> .\nfoo:bar = {<a> <b> <c>} .",
: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

Expand Down

0 comments on commit d4f9b49

Please sign in to comment.