rdf-n3 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +0 -1
- data/History.md +6 -1
- data/README.md +15 -1
- data/Rakefile +1 -28
- data/VERSION +1 -1
- data/lib/rdf/n3/format.rb +6 -2
- data/lib/rdf/n3/reader/bnf-rules.n3 +134 -0
- data/lib/rdf/n3/reader/n3-selectors.n3 +0 -0
- data/lib/rdf/n3/reader/n3.n3 +261 -0
- data/lib/rdf/n3/reader/parser.rb +1 -1
- data/rdf-n3.gemspec +411 -603
- data/script/build_meta +20 -13
- data/script/parse +2 -2
- data/script/yard-to-rubyforge +2 -0
- data/spec/.gitignore +1 -0
- data/spec/cwm_spec.rb +8 -13
- data/spec/cwm_test.rb +76 -0
- data/spec/format_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/swap_spec.rb +35 -31
- data/spec/swap_test.rb +79 -0
- data/spec/turtle_spec.rb +13 -19
- data/spec/turtle_test.rb +98 -0
- data/spec/writer_spec.rb +7 -10
- metadata +38 -228
- data/.gitignore +0 -5
- data/spec/rdf_helper.rb +0 -226
- data/spec/swap_test/animal.rdf +0 -17
- data/spec/swap_test/anon-prop.n3 +0 -14
- data/spec/swap_test/anonymous_loop.n3 +0 -2
- data/spec/swap_test/contexts.n3 +0 -16
- data/spec/swap_test/daml-pref.n3 +0 -10
- data/spec/swap_test/i18n/hiragana.n3 +0 -22
- data/spec/swap_test/i18n/n3string.n3 +0 -4
- data/spec/swap_test/list/itemType.rdf +0 -12
- data/spec/swap_test/lists-simple.n3 +0 -40
- data/spec/swap_test/lists.n3 +0 -35
- data/spec/swap_test/n3/n3parser.tests_n3_10001.nt +0 -3
- data/spec/swap_test/n3/n3parser.tests_n3_10002.nt +0 -7
- data/spec/swap_test/n3/n3parser.tests_n3_10003.nt +0 -3
- data/spec/swap_test/n3/n3parser.tests_n3_10004.nt +0 -119
- data/spec/swap_test/n3/n3parser.tests_n3_10005.nt +0 -3
- data/spec/swap_test/n3/n3parser.tests_n3_10006.nt +0 -225
- data/spec/swap_test/n3/n3parser.tests_n3_10007.nt +0 -79
- data/spec/swap_test/n3/n3parser.tests_n3_10008.nt +0 -5
- data/spec/swap_test/n3/n3parser.tests_n3_10009.nt +0 -13
- data/spec/swap_test/n3/n3parser.tests_n3_10010.nt +0 -21
- data/spec/swap_test/n3/n3parser.tests_n3_10011.nt +0 -9
- data/spec/swap_test/n3/n3parser.tests_n3_10012.nt +0 -53
- data/spec/swap_test/n3/n3parser.tests_n3_10013.nt +0 -19
- data/spec/swap_test/n3/n3parser.tests_n3_10014.nt +0 -103
- data/spec/swap_test/n3/n3parser.tests_n3_10015.nt +0 -103
- data/spec/swap_test/n3/n3parser.tests_n3_10016.nt +0 -3
- data/spec/swap_test/n3/n3parser.tests_n3_10017.nt +0 -151
- data/spec/swap_test/n3/n3parser.tests_n3_10018.nt +0 -9
- data/spec/swap_test/n3/n3parser.tests_n3_10019.nt +0 -3
- data/spec/swap_test/n3/n3parser.tests_n3_10020.nt +0 -13
- data/spec/swap_test/n3parser.tests +0 -160
- data/spec/swap_test/n3parser.yml +0 -174
- data/spec/swap_test/nodeID/classes.n3 +0 -9
- data/spec/swap_test/nodeID/classes.ref.rdf +0 -15
- data/spec/swap_test/nodeID/ex1.rdf +0 -15
- data/spec/swap_test/norm/fix.rdf +0 -33
- data/spec/swap_test/owl-ex.rdf +0 -150
- data/spec/swap_test/ref/animal.n3 +0 -11
- data/spec/swap_test/ref/anon-prop-1.n3 +0 -8
- data/spec/swap_test/ref/anonymous_loop.ref +0 -7
- data/spec/swap_test/ref/bnode.n3 +0 -6
- data/spec/swap_test/ref/bnode.rdf +0 -16
- data/spec/swap_test/ref/colon-in-uri.n3 +0 -15
- data/spec/swap_test/ref/contexts-1.n3 +0 -12
- data/spec/swap_test/ref/daml-ex.n3 +0 -103
- data/spec/swap_test/ref/daml-ont.n3 +0 -289
- data/spec/swap_test/ref/djb1a-out.n3 +0 -4
- data/spec/swap_test/ref/dot-dash.n3 +0 -8
- data/spec/swap_test/ref/in-xml-t.n3 +0 -4
- data/spec/swap_test/ref/itemType.n3 +0 -9
- data/spec/swap_test/ref/keywords1.n3 +0 -11
- data/spec/swap_test/ref/keywords2.n3 +0 -11
- data/spec/swap_test/ref/lists-simple-1.rdf +0 -108
- data/spec/swap_test/ref/lists.n3 +0 -43
- data/spec/swap_test/ref/lstring-out.n3 +0 -20
- data/spec/swap_test/ref/n3string.n3 +0 -13
- data/spec/swap_test/ref/no-last-nl.n3 +0 -3
- data/spec/swap_test/ref/numbers.n3 +0 -18
- data/spec/swap_test/ref/path1.n3 +0 -8
- data/spec/swap_test/ref/path2.n3 +0 -39
- data/spec/swap_test/ref/prefix1.rdf +0 -31
- data/spec/swap_test/ref/prefix2.rdf +0 -33
- data/spec/swap_test/ref/prefix3.rdf +0 -31
- data/spec/swap_test/ref/rdf-redefine.rdf +0 -11
- data/spec/swap_test/ref/reluri-1.rdf +0 -18
- data/spec/swap_test/ref/strquot.n3 +0 -22
- data/spec/swap_test/ref/strquot_a.n3 +0 -23
- data/spec/swap_test/ref/xml-base3.n3 +0 -5
- data/spec/swap_test/ref/xml-redefine.rdf +0 -20
- data/spec/swap_test/ref/xml-redefine2.rdf +0 -23
- data/spec/swap_test/ref/xml-syntax-basic-serialization.rdf +0 -10
- data/spec/swap_test/ref/xmllit.nt +0 -3
- data/spec/swap_test/regression.n3 +0 -231
- data/spec/swap_test/regression.yml +0 -256
- data/spec/swap_test/reluri-1.n3 +0 -10
- data/spec/swap_test/strquot.n3 +0 -23
- data/spec/swap_test/syntax/colon-in-uri.rdf +0 -27
- data/spec/swap_test/syntax/djb1a.n3 +0 -3
- data/spec/swap_test/syntax/dot-dash.n3 +0 -15
- data/spec/swap_test/syntax/equals1.n3 +0 -1
- data/spec/swap_test/syntax/equals2.n3 +0 -1
- data/spec/swap_test/syntax/keywords1.n3 +0 -17
- data/spec/swap_test/syntax/keywords2.n3 +0 -18
- data/spec/swap_test/syntax/lstring.n3 +0 -26
- data/spec/swap_test/syntax/neg-formula-predicate.n3 +0 -1
- data/spec/swap_test/syntax/neg-keywords3.n3 +0 -1
- data/spec/swap_test/syntax/neg-literal-predicate.n3 +0 -1
- data/spec/swap_test/syntax/neg-single-quote.n3 +0 -1
- data/spec/swap_test/syntax/neg-thisadoc.n3 +0 -1
- data/spec/swap_test/syntax/no-last-nl.n3 +0 -2
- data/spec/swap_test/syntax/numbers.n3 +0 -26
- data/spec/swap_test/syntax/path1.n3 +0 -23
- data/spec/swap_test/syntax/path2.n3 +0 -31
- data/spec/swap_test/syntax/qvars1.n3 +0 -19
- data/spec/swap_test/syntax/qvars2.n3 +0 -19
- data/spec/swap_test/syntax/this-quantifiers.n3 +0 -164
- data/spec/swap_test/syntax/this-rules.n3 +0 -43
- data/spec/swap_test/syntax/too-nested.n3 +0 -25
- data/spec/swap_test/syntax/trailing-semicolon.n3 +0 -12
- data/spec/swap_test/syntax/zero-objects.n3 +0 -1
- data/spec/swap_test/syntax/zero-predicates.n3 +0 -3
- data/spec/swap_test/tests-work.txt +0 -25
- data/spec/swap_test/xml-syntax/basic-serialization.n3 +0 -8
- data/spec/swap_test/xml-syntax/in-xml.xml +0 -13
- data/spec/swap_test/xml-syntax/non-ascii-pred.rdf +0 -14
- data/spec/swap_test/xml-syntax/rdf_prefix.n3 +0 -2
- data/spec/swap_test/xml-syntax/xml_prefix.n3 +0 -7
- data/spec/swap_test/xml-syntax/xml_prefix2.n3 +0 -9
- data/spec/swap_test/xml-syntax/xmlbase3.rdf +0 -10
- data/spec/swap_test/xml-syntax/xmllit.rdf +0 -33
- data/spec/turtle/README.txt +0 -20
- data/spec/turtle/bad-00.ttl +0 -2
- data/spec/turtle/bad-01.ttl +0 -3
- data/spec/turtle/bad-02.ttl +0 -3
- data/spec/turtle/bad-03.ttl +0 -3
- data/spec/turtle/bad-04.ttl +0 -3
- data/spec/turtle/bad-05.ttl +0 -4
- data/spec/turtle/bad-06.ttl +0 -3
- data/spec/turtle/bad-07.ttl +0 -4
- data/spec/turtle/bad-08.ttl +0 -2
- data/spec/turtle/bad-09.ttl +0 -3
- data/spec/turtle/bad-10.ttl +0 -3
- data/spec/turtle/bad-11.ttl +0 -3
- data/spec/turtle/bad-12.ttl +0 -3
- data/spec/turtle/bad-13.ttl +0 -3
- data/spec/turtle/bad-14.ttl +0 -6
- data/spec/turtle/manifest-bad.ttl +0 -88
- data/spec/turtle/manifest-bad.yml +0 -91
- data/spec/turtle/manifest.ttl +0 -215
- data/spec/turtle/manifest.yml +0 -187
- data/spec/turtle/rdf-schema.out +0 -126
- data/spec/turtle/rdf-schema.ttl +0 -156
- data/spec/turtle/rdfq-results.out +0 -36
- data/spec/turtle/rdfq-results.ttl +0 -39
- data/spec/turtle/rdfs-namespace.out +0 -131
- data/spec/turtle/rdfs-namespace.ttl +0 -160
- data/spec/turtle/test-00.out +0 -1
- data/spec/turtle/test-00.ttl +0 -2
- data/spec/turtle/test-01.out +0 -3
- data/spec/turtle/test-01.ttl +0 -7
- data/spec/turtle/test-02.out +0 -3
- data/spec/turtle/test-02.ttl +0 -5
- data/spec/turtle/test-03.out +0 -3
- data/spec/turtle/test-03.ttl +0 -5
- data/spec/turtle/test-04.out +0 -2
- data/spec/turtle/test-04.ttl +0 -4
- data/spec/turtle/test-05.out +0 -4
- data/spec/turtle/test-05.ttl +0 -4
- data/spec/turtle/test-06.out +0 -1
- data/spec/turtle/test-06.ttl +0 -3
- data/spec/turtle/test-07.out +0 -5
- data/spec/turtle/test-07.ttl +0 -3
- data/spec/turtle/test-08.out +0 -1
- data/spec/turtle/test-08.ttl +0 -3
- data/spec/turtle/test-09.out +0 -4
- data/spec/turtle/test-09.ttl +0 -10
- data/spec/turtle/test-10.out +0 -5
- data/spec/turtle/test-10.ttl +0 -5
- data/spec/turtle/test-11.out +0 -4
- data/spec/turtle/test-11.ttl +0 -10
- data/spec/turtle/test-12.out +0 -4
- data/spec/turtle/test-12.ttl +0 -9
- data/spec/turtle/test-13.out +0 -2
- data/spec/turtle/test-13.ttl +0 -7
- data/spec/turtle/test-14.out +0 -10000
- data/spec/turtle/test-14.ttl +0 -10002
- data/spec/turtle/test-15.out +0 -10000
- data/spec/turtle/test-15.ttl +0 -3
- data/spec/turtle/test-16.out +0 -10000
- data/spec/turtle/test-16.ttl +0 -10002
- data/spec/turtle/test-17.out +0 -1
- data/spec/turtle/test-17.ttl +0 -6
- data/spec/turtle/test-18.out +0 -2
- data/spec/turtle/test-18.ttl +0 -9
- data/spec/turtle/test-19.out +0 -1
- data/spec/turtle/test-19.ttl +0 -4
- data/spec/turtle/test-20.out +0 -2
- data/spec/turtle/test-20.ttl +0 -6
- data/spec/turtle/test-21.out +0 -3
- data/spec/turtle/test-21.ttl +0 -4
- data/spec/turtle/test-22.out +0 -3
- data/spec/turtle/test-22.ttl +0 -4
- data/spec/turtle/test-23.out +0 -1
- data/spec/turtle/test-23.ttl +0 -3
- data/spec/turtle/test-24.out +0 -2
- data/spec/turtle/test-24.ttl +0 -3
- data/spec/turtle/test-25.out +0 -7
- data/spec/turtle/test-25.ttl +0 -14
- data/spec/turtle/test-26.out +0 -1
- data/spec/turtle/test-26.ttl +0 -4
- data/spec/turtle/test-27.out +0 -1
- data/spec/turtle/test-27.ttl +0 -5
- data/spec/turtle/test-28-out.ttl +0 -6
- data/spec/turtle/test-28.out +0 -22
- data/spec/turtle/test-28.ttl +0 -22
- data/spec/turtle/test-29.out +0 -1
- data/spec/turtle/test-29.ttl +0 -1
- data/spec/turtle/test-30.out +0 -5
- data/spec/turtle/test-30.ttl +0 -12
data/.yardopts
CHANGED
data/History.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
0.3.1
|
2
|
+
-----
|
3
|
+
* Add application/turtle, application/x-turtle, text/rdf+n3 and application/rdf+n3 as mime types
|
4
|
+
matching this format, even though only text/turtle and text/n3 are valid.
|
5
|
+
|
1
6
|
0.3.0
|
2
|
-
|
7
|
+
-----
|
3
8
|
* New Predictive-Parser based N3 Reader, substantially faster than previous Treetop-based parser
|
4
9
|
* RDF.rb 0.3.0 compatibility updates
|
5
10
|
* Remove literal_normalization and qname_hacks, add back uri_hacks (until 0.3.0)
|
data/README.md
CHANGED
@@ -69,7 +69,21 @@ results in:
|
|
69
69
|
h = RDF::Query::Variable.new(<#h>)
|
70
70
|
g = RDF::Node.new()
|
71
71
|
RDF::Statement.new(f, <#loves>, h)
|
72
|
-
|
72
|
+
|
73
|
+
Implementation Notes
|
74
|
+
--------------------
|
75
|
+
The parser is driven through a rules table contained in lib/rdf/n3/reader/meta.rb. This includes
|
76
|
+
branch rules to indicate productions to be taken based on a current production. Terminals are denoted
|
77
|
+
through a set of regular expressions used to match each type of terminal.
|
78
|
+
|
79
|
+
The meta.rb file is generated from lib/rdf/n3/reader/n3-selectors.n3
|
80
|
+
(taken from http://www.w3.org/2000/10/swap/grammar/n3-selectors.n3) which is the result of parsing
|
81
|
+
http://www.w3.org/2000/10/swap/grammar/n3.n3 (along with bnf-rules.n3) using cwm using the following command sequence:
|
82
|
+
|
83
|
+
cwm n3.n3 bnf-rules.n3 --think --purge --data > n3-selectors.n3
|
84
|
+
|
85
|
+
n3-selectors.n3 is itself used to generate meta.rb using script/build_meta.
|
86
|
+
|
73
87
|
Dependencies
|
74
88
|
------------
|
75
89
|
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.3.0)
|
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
gemspec.homepage = "http://github.com/gkellogg/rdf-n3"
|
13
13
|
gemspec.authors = ["Gregg Kellogg"]
|
14
14
|
gemspec.add_dependency('rdf', '>= 0.3.0')
|
15
|
+
gemspec.add_development_dependency('open-uri-cached')
|
15
16
|
gemspec.add_development_dependency('rspec', '>= 2.1.0')
|
16
17
|
gemspec.add_development_dependency('rdf-spec', '>= 0.2.1')
|
17
18
|
gemspec.add_development_dependency('rdf-rdfxml', '>= 0.2.1')
|
@@ -42,32 +43,4 @@ YARD::Rake::YardocTask.new do |t|
|
|
42
43
|
t.files = %w(lib/**/*.rb README.md History.md AUTHORS VERSION) # optional
|
43
44
|
end
|
44
45
|
|
45
|
-
desc "Generate test manifest yaml"
|
46
|
-
namespace :spec do
|
47
|
-
task :prepare do
|
48
|
-
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
49
|
-
$:.unshift(File.join(File.dirname(__FILE__), 'spec'))
|
50
|
-
require 'rdf/rdfxml'
|
51
|
-
require 'rdf/n3'
|
52
|
-
require 'rdf_helper'
|
53
|
-
require 'fileutils'
|
54
|
-
|
55
|
-
yaml = File.join(SWAP_DIR, "n3parser.yml")
|
56
|
-
FileUtils.rm_f(yaml)
|
57
|
-
RdfHelper::TestCase.to_yaml(SWAP_TEST, SWAP_DIR, yaml)
|
58
|
-
|
59
|
-
yaml = File.join(SWAP_DIR, "regression.yml")
|
60
|
-
FileUtils.rm_f(yaml)
|
61
|
-
RdfHelper::TestCase.to_yaml(CWM_TEST, SWAP_DIR, yaml)
|
62
|
-
|
63
|
-
yaml = File.join(TURTLE_DIR, "manifest.yml")
|
64
|
-
FileUtils.rm_f(yaml)
|
65
|
-
RdfHelper::TestCase.to_yaml(TURTLE_TEST, TURTLE_DIR, yaml)
|
66
|
-
|
67
|
-
yaml = File.join(TURTLE_DIR, "manifest-bad.yml")
|
68
|
-
FileUtils.rm_f(yaml)
|
69
|
-
RdfHelper::TestCase.to_yaml(TURTLE_BAD_TEST, TURTLE_DIR, yaml)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
46
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/rdf/n3/format.rb
CHANGED
@@ -23,8 +23,12 @@ module RDF::N3
|
|
23
23
|
#
|
24
24
|
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
|
25
25
|
class Format < RDF::Format
|
26
|
-
content_type 'text/turtle',
|
27
|
-
content_type '
|
26
|
+
content_type 'text/turtle', :extension => :ttl
|
27
|
+
content_type 'application/turtle', :extension => :ttl
|
28
|
+
content_type 'application/x-turtle',:extension => :ttl
|
29
|
+
content_type 'text/n3', :extension => :n3
|
30
|
+
content_type 'text/rdf+n3', :extension => :n3
|
31
|
+
content_type 'application/rdf+n3', :extension => :n3
|
28
32
|
content_encoding 'utf-8'
|
29
33
|
|
30
34
|
reader { RDF::N3::Reader }
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#
|
2
|
+
# Baccus - Naur Form (BNF) vocabulary
|
3
|
+
#
|
4
|
+
|
5
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
6
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
7
|
+
@prefix bnf: <http://www.w3.org/2000/10/swap/grammar/bnf#>.
|
8
|
+
@prefix : <http://www.w3.org/2000/10/swap/grammar/bnf-rules#>.
|
9
|
+
@prefix rul: <http://www.w3.org/2000/10/swap/grammar/bnf-rules#>.
|
10
|
+
@prefix n3: <http://www.w3.org/2000/10/swap/grammar/n3#>.
|
11
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
|
12
|
+
@prefix doc: <http://www.w3.org/2000/10/swap/pim/doc#>.
|
13
|
+
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
|
14
|
+
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
|
15
|
+
@keywords a, is, of.
|
16
|
+
|
17
|
+
|
18
|
+
<> rdfs:comment
|
19
|
+
|
20
|
+
"""This set of rules process a BNF graph in its basic
|
21
|
+
cfg:mustBeOneOf BNF form and create the branching tables to drive a
|
22
|
+
predictive parser.
|
23
|
+
|
24
|
+
See also cfg2bnf.n3 which expands the shothand ontology into the basic
|
25
|
+
BNF terms.
|
26
|
+
""".
|
27
|
+
|
28
|
+
#_____________________________________
|
29
|
+
|
30
|
+
|
31
|
+
# Enumerate options:
|
32
|
+
|
33
|
+
{ ?x bnf:mustBeOneSequence ?y} => { ?x optionTail ?y }.
|
34
|
+
|
35
|
+
{?x optionTail [rdf:first ?y; rdf:rest ?z]} => {
|
36
|
+
?x bnf:branch [ bnf:sequence ?y];
|
37
|
+
optionTail ?z.
|
38
|
+
}.
|
39
|
+
|
40
|
+
{ ?x bnf:branch [bnf:sequence ?y] } => { ?y sequenceTail ?y }.
|
41
|
+
|
42
|
+
sequenceTail a log:Chaff.
|
43
|
+
optionTail a log:Chaff.
|
44
|
+
|
45
|
+
{ ?x sequenceTail [ rdf:rest ?z ] } => { ?x sequenceTail ?z }.
|
46
|
+
|
47
|
+
# What productions can follow each other?
|
48
|
+
# This is used for working out when to
|
49
|
+
|
50
|
+
{ ?x sequenceTail [ rdf:first ?y; rdf:rest [ rdf:first ?z ]] } =>
|
51
|
+
{ ?y bnf:canPrecede ?z }.
|
52
|
+
|
53
|
+
{ ?x bnf:branch [
|
54
|
+
bnf:sequence [
|
55
|
+
list:last ?y]].
|
56
|
+
?x bnf:canPrecede ?z} =>
|
57
|
+
{ ?y bnf:canPrecede ?z }.
|
58
|
+
|
59
|
+
{ ?x bnf:canPrecede ?y.
|
60
|
+
?y bnf:branch [ bnf:sequence () ].
|
61
|
+
?y bnf:canPrecede ?z.
|
62
|
+
} => {
|
63
|
+
|
64
|
+
?x bnf:canPrecede ?z.
|
65
|
+
}.
|
66
|
+
|
67
|
+
|
68
|
+
bnf:eof bnf:canStartWith "@EOFDUMMY". # @@ kludge
|
69
|
+
|
70
|
+
# Have to separate the next three rules or cwm seems to
|
71
|
+
# get screwed up and assume there is no solution @@@
|
72
|
+
|
73
|
+
{ ?x bnf:branch [bnf:sequence [ rdf:first ?y ]].
|
74
|
+
} => { ?x bnf:TEST ?y }.
|
75
|
+
|
76
|
+
{ ?x bnf:TEST ?y .
|
77
|
+
?y log:rawType log:Literal. } => { ?x bnf:canStartWithLiteral ?y }.
|
78
|
+
|
79
|
+
{ ?x bnf:canStartWithLiteral ?y .
|
80
|
+
# (?y "(.).*") string:scrape ?c # Use whole string
|
81
|
+
} => { ?y bnf:canStartWith ?y }.
|
82
|
+
|
83
|
+
#______________________________________________________________
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# Rules for determining branching
|
88
|
+
|
89
|
+
# A branch has a sequence, which is the given BNF production, and
|
90
|
+
# one or more conditions, which are the strings on which to consider
|
91
|
+
# that branch. N3 is a langauge in whch the look-ahead often is only
|
92
|
+
# one character, and may allways be a constsnt string rather than a
|
93
|
+
# regexp (check).
|
94
|
+
|
95
|
+
# A branchTail is a sequnece which a branch could start with
|
96
|
+
{ ?x bnf:branch ?b.
|
97
|
+
?b bnf:sequence ?s.
|
98
|
+
} => {
|
99
|
+
?b bnf:branchTail ?s.
|
100
|
+
}.
|
101
|
+
|
102
|
+
{ ?b bnf:branchTail ?s.
|
103
|
+
?s rdf:first [ bnf:branch [ bnf:sequence () ]];
|
104
|
+
rdf:rest ?t
|
105
|
+
} => {
|
106
|
+
?b bnf:branchTail ?t.
|
107
|
+
}.
|
108
|
+
|
109
|
+
|
110
|
+
{ ?x bnf:branch ?b.
|
111
|
+
?b bnf:branchTail ?s.
|
112
|
+
?s rdf:first [bnf:canStartWith ?y].
|
113
|
+
} => {
|
114
|
+
?x bnf:canStartWith ?y.
|
115
|
+
?b bnf:condition ?y.
|
116
|
+
}.
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
{ ?x bnf:branch ?b;
|
121
|
+
bnf:canPrecede ?z.
|
122
|
+
?z log:rawType log:Literal.
|
123
|
+
?b bnf:sequence ().
|
124
|
+
} => { ?b bnf:condition ?z}.
|
125
|
+
|
126
|
+
{ ?x bnf:branch ?b;
|
127
|
+
bnf:canPrecede [bnf:canStartWith ?z].
|
128
|
+
?b bnf:sequence ().
|
129
|
+
} => { ?b bnf:condition ?z}.
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
#ends
|
Binary file
|
@@ -0,0 +1,261 @@
|
|
1
|
+
# Notation3 in Notation3
|
2
|
+
# Context Free Grammar without tokenization
|
3
|
+
#
|
4
|
+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
5
|
+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
|
6
|
+
@prefix cfg: <http://www.w3.org/2000/10/swap/grammar/bnf#>.
|
7
|
+
@prefix rul: <http://www.w3.org/2000/10/swap/grammar/bnf-rules#>.
|
8
|
+
@prefix : <http://www.w3.org/2000/10/swap/grammar/n3#>.
|
9
|
+
@prefix n3: <http://www.w3.org/2000/10/swap/grammar/n3#>.
|
10
|
+
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
|
11
|
+
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
|
12
|
+
@keywords a, is, of.
|
13
|
+
|
14
|
+
|
15
|
+
# Issues:
|
16
|
+
# - string token regexp not right FIXED
|
17
|
+
# - tokenizing rules in general: whitespace are not defined in n3.n3
|
18
|
+
# and it would be nice for the *entire* syntax description to be in RDF.
|
19
|
+
# - encoding really needs specifying
|
20
|
+
# - @keywords affects tokenizing
|
21
|
+
# - comments (tokenizer deals with)
|
22
|
+
# - We assume ASCII, in fact should use not notNameChars for i18n
|
23
|
+
|
24
|
+
# tokenizing:
|
25
|
+
# Absorb anything until end of regexp, then stil white space
|
26
|
+
# period followed IMMEDIATELY by an opener or name char is taken as "!".
|
27
|
+
# Except after a "." used instead of in those circumstances,
|
28
|
+
# ws may be inserted between tokens.
|
29
|
+
# WS MUST be inserted between tokens where ambiguity would arise.
|
30
|
+
# (possible ending characters of one and beginning characters overlap)
|
31
|
+
#
|
32
|
+
|
33
|
+
#<> cfg:syntaxFor [ cfg:internetMediaType
|
34
|
+
# <http://www.w3.org/2003/mediatypes/text/n3>].
|
35
|
+
|
36
|
+
|
37
|
+
# __________________________________________________________________
|
38
|
+
#
|
39
|
+
# The N3 Full Grammar
|
40
|
+
|
41
|
+
|
42
|
+
language a cfg:Language;
|
43
|
+
cfg:document document;
|
44
|
+
cfg:whiteSpace "@@@@@".
|
45
|
+
|
46
|
+
|
47
|
+
document a rul:Used;
|
48
|
+
cfg:mustBeOneSequence(
|
49
|
+
|
50
|
+
(
|
51
|
+
# [ cfg:zeroOrMore declaration ]
|
52
|
+
# [ cfg:zeroOrMore universal ]
|
53
|
+
# [ cfg:zeroOrMore existential ]
|
54
|
+
statements_optional
|
55
|
+
cfg:eof
|
56
|
+
)
|
57
|
+
).
|
58
|
+
|
59
|
+
statements_optional cfg:mustBeOneSequence (() ( statement "." statements_optional ) ).
|
60
|
+
|
61
|
+
# Formula does NOT need period on last statement
|
62
|
+
|
63
|
+
formulacontent cfg:mustBeOneSequence (
|
64
|
+
( statementlist )
|
65
|
+
).
|
66
|
+
|
67
|
+
|
68
|
+
statementlist cfg:mustBeOneSequence (
|
69
|
+
( )
|
70
|
+
( statement statementtail )
|
71
|
+
).
|
72
|
+
|
73
|
+
statementtail cfg:mustBeOneSequence (
|
74
|
+
( )
|
75
|
+
( "." statementlist )
|
76
|
+
).
|
77
|
+
|
78
|
+
|
79
|
+
statement cfg:mustBeOneSequence (
|
80
|
+
(declaration)
|
81
|
+
(universal)
|
82
|
+
(existential)
|
83
|
+
(simpleStatement)
|
84
|
+
).
|
85
|
+
|
86
|
+
universal cfg:mustBeOneSequence (
|
87
|
+
(
|
88
|
+
"@forAll"
|
89
|
+
[ cfg:commaSeparatedListOf symbol ]
|
90
|
+
)).
|
91
|
+
|
92
|
+
existential cfg:mustBeOneSequence(
|
93
|
+
( "@forSome"
|
94
|
+
[ cfg:commaSeparatedListOf symbol ]
|
95
|
+
)).
|
96
|
+
|
97
|
+
|
98
|
+
declaration cfg:mustBeOneSequence(
|
99
|
+
( "@base" explicituri )
|
100
|
+
( "@prefix" prefix explicituri )
|
101
|
+
( "@keywords" [ cfg:commaSeparatedListOf barename ] )
|
102
|
+
).
|
103
|
+
|
104
|
+
|
105
|
+
simpleStatement cfg:mustBeOneSequence(( subject propertylist )).
|
106
|
+
|
107
|
+
propertylist cfg:mustBeOneSequence (
|
108
|
+
( )
|
109
|
+
( predicate object objecttail propertylisttail )
|
110
|
+
).
|
111
|
+
|
112
|
+
propertylisttail cfg:mustBeOneSequence (
|
113
|
+
( )
|
114
|
+
( ";" propertylist )
|
115
|
+
).
|
116
|
+
|
117
|
+
|
118
|
+
objecttail cfg:mustBeOneSequence (
|
119
|
+
( )
|
120
|
+
( "," object objecttail )
|
121
|
+
).
|
122
|
+
|
123
|
+
|
124
|
+
predicate cfg:mustBeOneSequence (
|
125
|
+
( expression )
|
126
|
+
( "@has" expression )
|
127
|
+
( "@is" expression "@of" )
|
128
|
+
( "@a" )
|
129
|
+
( "=" )
|
130
|
+
( "=>" )
|
131
|
+
( "<=" )
|
132
|
+
).
|
133
|
+
|
134
|
+
subject cfg:mustBeOneSequence ((expression)).
|
135
|
+
|
136
|
+
object cfg:mustBeOneSequence ((expression)).
|
137
|
+
|
138
|
+
expression cfg:mustBeOneSequence(
|
139
|
+
( pathitem pathtail )
|
140
|
+
).
|
141
|
+
|
142
|
+
pathtail cfg:mustBeOneSequence(
|
143
|
+
( )
|
144
|
+
( "!" expression )
|
145
|
+
( "^" expression )
|
146
|
+
).
|
147
|
+
|
148
|
+
|
149
|
+
pathitem cfg:mustBeOneSequence (
|
150
|
+
( symbol )
|
151
|
+
( "{" formulacontent "}" )
|
152
|
+
( quickvariable )
|
153
|
+
( numericliteral )
|
154
|
+
( literal )
|
155
|
+
( "[" propertylist "]" )
|
156
|
+
( "(" pathlist ")" )
|
157
|
+
( boolean )
|
158
|
+
# ( "@this" ) # Deprocated. Was allowed for this log:forAll x
|
159
|
+
).
|
160
|
+
|
161
|
+
|
162
|
+
boolean cfg:mustBeOneSequence (
|
163
|
+
( "@true" )
|
164
|
+
( "@false" )
|
165
|
+
) .
|
166
|
+
|
167
|
+
pathlist cfg:mustBeOneSequence (() (expression pathlist)).
|
168
|
+
|
169
|
+
symbol cfg:mustBeOneSequence (
|
170
|
+
(explicituri)
|
171
|
+
(qname)
|
172
|
+
).
|
173
|
+
|
174
|
+
|
175
|
+
numericliteral cfg:mustBeOneSequence (
|
176
|
+
( integer )
|
177
|
+
( rational )
|
178
|
+
( double )
|
179
|
+
( decimal )
|
180
|
+
) .
|
181
|
+
|
182
|
+
rational cfg:mustBeOneSequence (( integer "/" unsignedint)).
|
183
|
+
|
184
|
+
|
185
|
+
literal cfg:mustBeOneSequence(( string dtlang)).
|
186
|
+
|
187
|
+
dtlang cfg:mustBeOneSequence( () ("@" langcode) ("^^" symbol)).
|
188
|
+
|
189
|
+
|
190
|
+
#______________________________________________________________________
|
191
|
+
#
|
192
|
+
# TERMINALS
|
193
|
+
#
|
194
|
+
# "canStartWith" actually gives "a" for the whole class of alpha characters
|
195
|
+
# and "0" for any of the digits 0-9. This is used to build the branching
|
196
|
+
# tables.
|
197
|
+
#
|
198
|
+
integer cfg:matches """[-+]?[0-9]+""";
|
199
|
+
cfg:canStartWith "0", "-", "+".
|
200
|
+
unsignedint cfg:matches """[0-9]+""";
|
201
|
+
cfg:canStartWith "0".
|
202
|
+
double cfg:matches """[-+]?[0-9]+(\\.[0-9]+)?([eE][-+]?[0-9]+)""";
|
203
|
+
cfg:canStartWith "0", "-", "+".
|
204
|
+
decimal cfg:matches """[-+]?[0-9]+\\.[0-9]*""";
|
205
|
+
cfg:canStartWith "0", "-", "+".
|
206
|
+
|
207
|
+
#numericliteral cfg:matches """[-+]?[0-9]+(\\.[0-9]+)?(e[-+]?[0-9]+)?""";
|
208
|
+
# cfg:canStartWith "0", "-", "+".
|
209
|
+
|
210
|
+
explicituri cfg:matches "<[^>]*>";
|
211
|
+
cfg:canStartWith "<".
|
212
|
+
|
213
|
+
prefix cfg:matches "([A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*)?:";
|
214
|
+
cfg:canStartWith "a", "_", ":". # @@ etc unicode
|
215
|
+
|
216
|
+
qname cfg:matches "(([A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*)?:)?[A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*";
|
217
|
+
cfg:canStartWith "a", "_", ":". # @@ etc unicode
|
218
|
+
|
219
|
+
# ASCII version:
|
220
|
+
#barename cfg:matches "[a-zA-Z_][a-zA-Z0-9_]*"; # subset of qname
|
221
|
+
# cfg:canStartWith "a", "_". # @@ etc
|
222
|
+
|
223
|
+
# This is the XML1.1
|
224
|
+
barename cfg:matches "[A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*";
|
225
|
+
cfg:canStartWith "a", "_". # @@ etc .
|
226
|
+
|
227
|
+
# as far as I can tell, the regexp should be
|
228
|
+
# barename cfg:matches "[A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*" .
|
229
|
+
#
|
230
|
+
|
231
|
+
quickvariable cfg:matches "\\?[A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff][\\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\U00010000-\U000effff]*"; # ? barename
|
232
|
+
cfg:canStartWith "?". #
|
233
|
+
|
234
|
+
# Maybe dtlang should just be part of string regexp?
|
235
|
+
# Whitespace is not allowed
|
236
|
+
|
237
|
+
# was: "[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)?";
|
238
|
+
langcode cfg:matches "[a-z]+(-[a-z0-9]+)*"; # http://www.w3.org/TR/rdf-testcases/#language
|
239
|
+
cfg:canStartWith "a".
|
240
|
+
|
241
|
+
|
242
|
+
# raw regexp single quoted would be "([^"]|(\\"))*"
|
243
|
+
# See:
|
244
|
+
# $ PYTHONPATH=$SWAP python
|
245
|
+
# >>> import tokenize
|
246
|
+
# >>> import notation3
|
247
|
+
# >>> print notation3.stringToN3(tokenize.Double3)
|
248
|
+
# "[^\"\\\\]*(?:(?:\\\\.|\"(?!\"\"))[^\"\\\\]*)*\"\"\""
|
249
|
+
# >>> print notation3.stringToN3(tokenize.Double)
|
250
|
+
# "[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\""
|
251
|
+
# After that we have to prefix with one or three opening \" which
|
252
|
+
# the python regexp doesn't have.
|
253
|
+
#
|
254
|
+
# string3 cfg:matches "\"\"\"[^\"\\\\]*(?:(?:\\\\.|\"(?!\"\"))[^\"\\\\]*)*\"\"\"".
|
255
|
+
# string1 cfg:matches "\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"".
|
256
|
+
|
257
|
+
string cfg:matches "(\"\"\"[^\"\\\\]*(?:(?:\\\\.|\"(?!\"\"))[^\"\\\\]*)*\"\"\")|(\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")";
|
258
|
+
cfg:canStartWith "\"".
|
259
|
+
|
260
|
+
|
261
|
+
#ends
|