yaparc 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +36 -36
- data/lib/yaparc.rb +121 -199
- data/tests/test_abc.rb +40 -41
- data/tests/test_calc.rb +24 -29
- data/tests/test_owl.rb +986 -15
- data/tests/test_parser.rb +94 -45
- data/tests/test_sql.rb +98 -106
- data/tests/test_uri.rb +100 -100
- metadata +2 -2
data/tests/test_abc.rb
CHANGED
@@ -14,13 +14,13 @@ module ABC
|
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
@parser = lambda do
|
17
|
-
Yaparc::
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
Yaparc::Many.new(
|
18
|
+
Yaparc::Alt.new(AbcTune.new,
|
19
|
+
Comment.new,
|
20
|
+
Xcommand.new,
|
21
|
+
FileField.new,
|
22
|
+
TextLine.new,
|
23
|
+
Tex.new))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -31,28 +31,28 @@ module ABC
|
|
31
31
|
|
32
32
|
def initialize
|
33
33
|
@parser = lambda do
|
34
|
-
Yaparc::
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
34
|
+
Yaparc::Alt.new(
|
35
|
+
FieldArea.new,
|
36
|
+
FieldBook.new,
|
37
|
+
FieldComposer.new,
|
38
|
+
FieldDiscography.new,
|
39
|
+
FieldFile.new,
|
40
|
+
FieldGroup.new,
|
41
|
+
FieldHistory.new,
|
42
|
+
FieldLength.new,
|
43
|
+
FieldMeter.new,
|
44
|
+
FieldNotes.new,
|
45
|
+
FieldOrigin.new,
|
46
|
+
FieldParts.new,
|
47
|
+
FieldTempo.new,
|
48
|
+
FieldRhythm.new,
|
49
|
+
FieldSource.new,
|
50
|
+
FieldUserdefPrint.new,
|
51
|
+
FieldUserdefPlay.new,
|
52
|
+
FieldWords.new,
|
53
|
+
FieldTranscription.new,
|
54
|
+
FieldKey.new,
|
55
|
+
UnusedField.new)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -63,9 +63,9 @@ module ABC
|
|
63
63
|
|
64
64
|
def initialize
|
65
65
|
@parser = lambda do
|
66
|
-
Yaparc::
|
67
|
-
|
68
|
-
|
66
|
+
Yaparc::Seq.new(AbcHeader.new,
|
67
|
+
AbcMusic.new,
|
68
|
+
Eol.new)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -76,11 +76,11 @@ module ABC
|
|
76
76
|
|
77
77
|
def initialize
|
78
78
|
@parser = lambda do
|
79
|
-
Yaparc::
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
Yaparc::Seq.new(
|
80
|
+
ZeroOne.new(FieldNumber.new)
|
81
|
+
TitleFields.new,
|
82
|
+
Many.new(OtherField.new),
|
83
|
+
FieldKey.new)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -91,9 +91,8 @@ module ABC
|
|
91
91
|
|
92
92
|
def initialize
|
93
93
|
@parser = lambda do
|
94
|
-
Yaparc::
|
95
|
-
|
96
|
-
|
94
|
+
Yaparc::Seq.new(
|
95
|
+
|
97
96
|
%x58.3A *WSP 1*DIGIT header-eol ; X:
|
98
97
|
end
|
99
98
|
end
|
@@ -105,7 +104,7 @@ module ABC
|
|
105
104
|
|
106
105
|
def initialize
|
107
106
|
@parser = lambda do
|
108
|
-
Yaparc::
|
107
|
+
Yaparc::Alt.new(Regex.new(/\n/))
|
109
108
|
end
|
110
109
|
end
|
111
110
|
end
|
data/tests/test_calc.rb
CHANGED
@@ -3,20 +3,19 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
module Calc
|
5
5
|
|
6
|
-
# class Expr < Yaparc::AbstractParser
|
7
6
|
class Expr
|
8
7
|
include Yaparc::Parsable
|
9
8
|
|
10
9
|
def initialize
|
11
10
|
@parser = lambda do
|
12
|
-
Yaparc::
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
Yaparc::Alt.new(
|
12
|
+
Yaparc::Seq.new(Term.new,
|
13
|
+
Yaparc::Symbol.new('+'),
|
14
|
+
Expr.new) do |term, _, expr|
|
15
|
+
['+', term,expr]
|
16
|
+
end,
|
17
|
+
Term.new
|
18
|
+
)
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
@@ -45,40 +44,36 @@ module Calc
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
# class Term < Yaparc::AbstractParser
|
49
47
|
class Term
|
50
48
|
include Yaparc::Parsable
|
51
49
|
|
52
50
|
def initialize
|
53
51
|
@parser = lambda do
|
54
|
-
Yaparc::
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
)
|
52
|
+
Yaparc::Alt.new(
|
53
|
+
Yaparc::Seq.new(Factor.new,
|
54
|
+
Yaparc::Symbol.new('*'),
|
55
|
+
Term.new) do |factor, _, term|
|
56
|
+
['*', factor,term]
|
57
|
+
end,
|
58
|
+
Factor.new)
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
65
62
|
|
66
|
-
# class Factor < Yaparc::AbstractParser
|
67
63
|
class Factor
|
68
64
|
include Yaparc::Parsable
|
69
65
|
|
70
66
|
def initialize
|
71
67
|
@parser = lambda do
|
72
|
-
Yaparc::
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
)
|
68
|
+
Yaparc::Alt.new(
|
69
|
+
Yaparc::Seq.new(
|
70
|
+
Yaparc::Symbol.new('('),
|
71
|
+
Expr.new,
|
72
|
+
Yaparc::Symbol.new(')')
|
73
|
+
) do |_,expr, _|
|
74
|
+
expr
|
75
|
+
end,
|
76
|
+
Yaparc::Natural.new)
|
82
77
|
end
|
83
78
|
end
|
84
79
|
end
|
data/tests/test_owl.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
=begin
|
1
2
|
ontology ::= 'Ontology(' [ ontologyID ] { directive } ')'
|
2
3
|
directive ::= 'Annotation(' ontologyPropertyID ontologyID ')'
|
3
4
|
| 'Annotation(' annotationPropertyID URIreference ')'
|
@@ -13,17 +14,8 @@ datavaluedPropertyID ::= URIreference
|
|
13
14
|
individualvaluedPropertyID ::= URIreference
|
14
15
|
annotationPropertyID ::= URIreference
|
15
16
|
ontologyPropertyID ::= URIreference
|
16
|
-
annotation ::= 'annotation(' annotationPropertyID URIreference ')'
|
17
|
-
| 'annotation(' annotationPropertyID dataLiteral ')'
|
18
|
-
| 'annotation(' annotationPropertyID individual ')'
|
19
17
|
|
20
18
|
fact ::= individual
|
21
|
-
individual ::= 'Individual(' [ individualID ] { annotation } { 'type(' type ')' } { value } ')'
|
22
|
-
value ::= 'value(' individualvaluedPropertyID individualID ')'
|
23
|
-
| 'value(' individualvaluedPropertyID individual ')'
|
24
|
-
| 'value(' datavaluedPropertyID dataLiteral ')'
|
25
|
-
type ::= description
|
26
|
-
|
27
19
|
axiom ::= 'Class(' classID ['Deprecated'] modality { annotation } { description } ')'
|
28
20
|
| 'EnumeratedClass(' classID ['Deprecated'] { annotation } { individualID } ')'
|
29
21
|
| 'DisjointClasses(' description description { description } ')'
|
@@ -39,7 +31,17 @@ axiom ::= 'Class(' classID ['Deprecated'] modality { annotation } { description
|
|
39
31
|
| 'EquivalentProperties(' individualvaluedPropertyID individualvaluedPropertyID { individualvaluedPropertyID } ')'
|
40
32
|
| 'SubPropertyOf(' individualvaluedPropertyID individualvaluedPropertyID ')'
|
41
33
|
|
42
|
-
|
34
|
+
individual ::= 'Individual(' [ individualID ] { annotation } { 'type(' type ')' } { value } ')'
|
35
|
+
value ::= 'value(' individualvaluedPropertyID individualID ')'
|
36
|
+
| 'value(' individualvaluedPropertyID individual ')'
|
37
|
+
| 'value(' datavaluedPropertyID dataLiteral ')'
|
38
|
+
annotation ::= 'annotation(' annotationPropertyID URIreference ')'
|
39
|
+
| 'annotation(' annotationPropertyID dataLiteral ')'
|
40
|
+
| 'annotation(' annotationPropertyID individual ')'
|
41
|
+
|
42
|
+
type ::= description
|
43
|
+
|
44
|
+
|
43
45
|
|
44
46
|
description ::= classID
|
45
47
|
| restriction
|
@@ -51,18 +53,987 @@ description ::= classID
|
|
51
53
|
restriction ::= 'restriction(' datavaluedPropertyID dataRestrictionComponent { dataRestrictionComponent } ')'
|
52
54
|
| 'restriction(' individualvaluedPropertyID individualRestrictionComponent { individualRestrictionComponent } ')'
|
53
55
|
|
56
|
+
individualRestrictionComponent ::= 'allValuesFrom(' description ')'
|
57
|
+
| 'someValuesFrom(' description ')'
|
58
|
+
| 'value(' individualID ')'
|
59
|
+
| cardinality
|
60
|
+
modality ::= 'complete' | 'partial'
|
61
|
+
|
54
62
|
dataRestrictionComponent ::= 'allValuesFrom(' dataRange ')'
|
55
63
|
| 'someValuesFrom(' dataRange ')'
|
56
64
|
| 'value(' dataLiteral ')'
|
57
65
|
| cardinality
|
58
66
|
|
59
|
-
individualRestrictionComponent ::= 'allValuesFrom(' description ')'
|
60
|
-
| 'someValuesFrom(' description ')'
|
61
|
-
| 'value(' individualID ')'
|
62
|
-
| cardinality
|
63
67
|
cardinality ::= 'minCardinality(' non-negative-integer ')'
|
64
68
|
| 'maxCardinality(' non-negative-integer ')'
|
65
69
|
| 'cardinality(' non-negative-integer ')'
|
66
|
-
dataRange ::= datatypeID
|
70
|
+
dataRange ::= datatypeID
|
71
|
+
| 'rdfs:Literal'
|
67
72
|
| 'oneOf(' { dataLiteral } ')'
|
68
73
|
|
74
|
+
|
75
|
+
# http://www.w3.org/TR/rdf-concepts/#dfn-plain-literal
|
76
|
+
dataLiteral ::= typedLiteral | plainLiteral
|
77
|
+
typedLiteral ::= lexicalForm^^URIreference
|
78
|
+
plainLiteral ::= lexicalForm | lexicalForm@languageTag
|
79
|
+
lexicalForm ::= /"[^"]*"/ # as in RDF, a unicode string in normal form C
|
80
|
+
languageTag ::= /[a-z-]+/ # as in RDF, an XML language tag
|
81
|
+
=end
|
82
|
+
|
83
|
+
module OWLParser
|
84
|
+
KEYWORDS = %w{Ontology( Class( EnumeratedClass( DisjointClasses( EquivalentClasses( SubClassOf( Datatype( DatatypeProperty( ObjectProperty( AnnotationProperty( OntologyProperty( EquivalentProperties( SubPropertyOf( EquivalentProperties( type( Annotation( Individual( value( unionOf( intersectionOf( complementOf( oneOf( restriction( allValuesFrom( someValuesFrom( (minCardinality( maxCardinality( cardinality( rdfs:Literal}
|
85
|
+
|
86
|
+
# ontology ::= 'Ontology(' [ ontologyID ] { directive } ')'
|
87
|
+
class Ontology
|
88
|
+
include Yaparc::Parsable
|
89
|
+
def initialize
|
90
|
+
@parser = lambda do |input|
|
91
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Ontology('),
|
92
|
+
Yaparc::ZeroOne.new(OntologyID.new,{}),
|
93
|
+
Yaparc::Many.new(Directive.new,{}),
|
94
|
+
Yaparc::Literal.new(')')) do |_,ontologyID, directive,_|
|
95
|
+
{:ontologyID => ontologyID, :directive => directive}
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# directive ::= 'Annotation(' ontologyPropertyID ontologyID ')'
|
102
|
+
# | 'Annotation(' annotationPropertyID URIreference ')'
|
103
|
+
# | 'Annotation(' annotationPropertyID dataLiteral ')'
|
104
|
+
# | 'Annotation(' annotationPropertyID individual ')'
|
105
|
+
# | axiom
|
106
|
+
# | fact
|
107
|
+
class Directive
|
108
|
+
include Yaparc::Parsable
|
109
|
+
def initialize
|
110
|
+
@parser = lambda do |input|
|
111
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('Annotation('),
|
112
|
+
OntologyPropertyID.new,
|
113
|
+
OntologyID.new,
|
114
|
+
Yaparc::Literal.new(')')) do |_,ontology_property_id,ontology_id,_|
|
115
|
+
{:ontology_property_id => ontology_property_id, :ontology_id => ontology_id }
|
116
|
+
end,
|
117
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Annotation('),
|
118
|
+
AnnotationPropertyID.new,
|
119
|
+
Yaparc::Alt.new(URIReference.new,
|
120
|
+
DataLiteral.new,
|
121
|
+
Individual.new),
|
122
|
+
Yaparc::Literal.new(')')),
|
123
|
+
Axiom.new,
|
124
|
+
Fact.new)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# axiom ::= 'Class(' classID ['Deprecated'] modality { annotation } { description } ')'
|
130
|
+
# | 'EnumeratedClass(' classID ['Deprecated'] { annotation } { individualID } ')'
|
131
|
+
# | 'DisjointClasses(' description description { description } ')'
|
132
|
+
# | 'EquivalentClasses(' description { description } ')'
|
133
|
+
# | 'SubClassOf(' description description ')'
|
134
|
+
# | 'Datatype(' datatypeID ['Deprecated'] { annotation } )'
|
135
|
+
# | 'DatatypeProperty(' datavaluedPropertyID ['Deprecated'] { annotation } { 'super(' datavaluedPropertyID ')'} ['Functional'] { 'domain(' description ')' } { 'range(' dataRange ')' } ')'
|
136
|
+
# | 'ObjectProperty(' individualvaluedPropertyID ['Deprecated'] { annotation } { 'super(' individualvaluedPropertyID ')' } [ 'inverseOf(' individualvaluedPropertyID ')' ] [ 'Symmetric' ] [ 'Functional' | 'InverseFunctional' | 'Functional' 'InverseFunctional' | 'Transitive' ] { 'domain(' description ')' } { 'range(' description ')' } ')'
|
137
|
+
# | 'AnnotationProperty(' annotationPropertyID { annotation } ')'
|
138
|
+
# | 'OntologyProperty(' ontologyPropertyID { annotation } ')'
|
139
|
+
# | 'EquivalentProperties(' datavaluedPropertyID datavaluedPropertyID { datavaluedPropertyID } ')'
|
140
|
+
# | 'SubPropertyOf(' datavaluedPropertyID datavaluedPropertyID ')'
|
141
|
+
# | 'EquivalentProperties(' individualvaluedPropertyID individualvaluedPropertyID { individualvaluedPropertyID } ')'
|
142
|
+
# | 'SubPropertyOf(' individualvaluedPropertyID individualvaluedPropertyID ')'
|
143
|
+
|
144
|
+
class Axiom
|
145
|
+
include Yaparc::Parsable
|
146
|
+
def initialize
|
147
|
+
@parser = lambda do |input|
|
148
|
+
Yaparc::Alt.new(#'Class(' classID ['Deprecated'] modality { annotation } { description } ')'
|
149
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Class('),
|
150
|
+
ClassID.new,
|
151
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Deprecated'),{}),
|
152
|
+
Modality.new,
|
153
|
+
Yaparc::Many.new(Annotation.new,{}),
|
154
|
+
Yaparc::Many.new(Description.new,{}),
|
155
|
+
Yaparc::Literal.new(')')) do |_,class_id, deprecated, modality, annotations, descriptions,_|
|
156
|
+
{:class => {:class_id => class_id, :deprecated => deprecated, :modality => modality, :annotations => annotations, :descriptions => descriptions }}
|
157
|
+
end,
|
158
|
+
#'EnumeratedClass(' classID ['Deprecated'] { annotation } { individualID } ')'
|
159
|
+
Yaparc::Seq.new(Yaparc::Literal.new('EnumeratedClass('),
|
160
|
+
ClassID.new,
|
161
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Deprecated'),{}),
|
162
|
+
Yaparc::Many.new(Annotation.new,{}),
|
163
|
+
Yaparc::Many.new(IndividualID.new,{}),
|
164
|
+
Yaparc::Literal.new(')')) do |_,class_id, deprecated, annotations, individual_ids,_|
|
165
|
+
{:enumerated_class => {:class_id => class_id, :deprecated => deprecated, :annotations => annotations, :individual_ids => individual_ids }}
|
166
|
+
end,
|
167
|
+
#'DisjointClasses(' description description { description } ')'
|
168
|
+
Yaparc::Seq.new(Yaparc::Literal.new('DisjointClasses('),
|
169
|
+
Description.new,
|
170
|
+
Yaparc::ManyOne.new(Description.new,{}),
|
171
|
+
Yaparc::Literal.new(')')) do |_,description,descriptions,_|
|
172
|
+
{:disjoint_classes => description.merge(descriptions)}
|
173
|
+
end,
|
174
|
+
#'EquivalentClasses(' description { description } ')'
|
175
|
+
Yaparc::Seq.new(Yaparc::Literal.new('EquivalentClasses('),
|
176
|
+
Yaparc::ManyOne.new(Description.new,{ }),
|
177
|
+
Yaparc::Literal.new(')')) do |_,descriptions,_|
|
178
|
+
{:equivalent_classes => descriptions}
|
179
|
+
end,
|
180
|
+
#'SubClassOf(' description description ')'
|
181
|
+
Yaparc::Seq.new(Yaparc::Literal.new('SubClassOf('),
|
182
|
+
Description.new,
|
183
|
+
Description.new,
|
184
|
+
Yaparc::Literal.new(')')) do |_,description1,description2,_|
|
185
|
+
{:sub_class_of => description1.merge(description2)}
|
186
|
+
end,
|
187
|
+
#'Datatype(' datatypeID ['Deprecated'] { annotation } )'
|
188
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Datatype('),
|
189
|
+
DatatypeID.new,
|
190
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Deprecated'),{}),
|
191
|
+
Yaparc::Many.new(Annotation.new,{ }),
|
192
|
+
Yaparc::Literal.new(')')) do |_,datatype_id,_,annotations,_|
|
193
|
+
{:datatype => {:datatype_id => datatype_id,:annotations=> annotations }}
|
194
|
+
end,
|
195
|
+
#'DatatypeProperty(' datavaluedPropertyID ['Deprecated'] { annotation } { 'super(' datavaluedPropertyID ')'} ['Functional'] { 'domain(' description ')' } { 'range(' dataRange ')' } ')'
|
196
|
+
Yaparc::Seq.new(Yaparc::Literal.new('DatatypeProperty('),
|
197
|
+
DatavaluedPropertyID.new,
|
198
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Deprecated'),{}),
|
199
|
+
Yaparc::Many.new(Annotation.new,{ }),
|
200
|
+
Yaparc::Many.new(
|
201
|
+
Yaparc::Seq.new(Yaparc::Literal.new('super('),
|
202
|
+
DatavaluedPropertyID.new,
|
203
|
+
Yaparc::Literal.new(')')),{}),
|
204
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Functional'),{}),
|
205
|
+
Yaparc::Many.new(
|
206
|
+
Yaparc::Seq.new(Yaparc::Literal.new('domain('),
|
207
|
+
Description.new,
|
208
|
+
Yaparc::Literal.new(')')),{}),
|
209
|
+
Yaparc::Many.new(
|
210
|
+
Yaparc::Seq.new(Yaparc::Literal.new('range('),
|
211
|
+
DataRange.new,
|
212
|
+
Yaparc::Literal.new(')')),{}),
|
213
|
+
Yaparc::Literal.new(')')) do |_, datavalued_property_id, _, annotation, super_tag, functional, domain, range,_|
|
214
|
+
{:datatype_property_id => {:annotation => annotation, :super_tag => super_tag, :functional => functional, :domain => domain, :range => range}}
|
215
|
+
end,
|
216
|
+
#'ObjectProperty(' individualvaluedPropertyID ['Deprecated'] { annotation } { 'super(' individualvaluedPropertyID ')' } [ 'inverseOf(' individualvaluedPropertyID ')' ] [ 'Symmetric' ] [ 'Functional' | 'InverseFunctional' | 'Functional' 'InverseFunctional' | 'Transitive' ] { 'domain(' description ')' } { 'range(' description ')' } ')'
|
217
|
+
Yaparc::Seq.new(Yaparc::Literal.new('ObjectProperty('),
|
218
|
+
IndividualvaluedPropertyID.new,
|
219
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Deprecated'),{}),
|
220
|
+
Yaparc::Many.new(Annotation.new,{}),
|
221
|
+
Yaparc::Many.new(
|
222
|
+
Yaparc::Seq.new(Yaparc::Literal.new('super('),
|
223
|
+
IndividualvaluedPropertyID.new,
|
224
|
+
Yaparc::Literal.new(')')),{}),
|
225
|
+
Yaparc::Many.new(
|
226
|
+
Yaparc::Seq.new(Yaparc::Literal.new('inverseOf('),
|
227
|
+
IndividualvaluedPropertyID.new,
|
228
|
+
Yaparc::Literal.new(')')),{}),
|
229
|
+
Yaparc::ZeroOne.new(Yaparc::Literal.new('Symmetric'),{}),
|
230
|
+
Yaparc::Alt.new(
|
231
|
+
Yaparc::Literal.new('Functional'),
|
232
|
+
Yaparc::Literal.new('InverseFunctional'),
|
233
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Functional'), Yaparc::Literal.new('InverseFunctional')),
|
234
|
+
Yaparc::Literal.new('Transitive')),
|
235
|
+
Yaparc::Many.new(
|
236
|
+
Yaparc::Seq.new(Yaparc::Literal.new('domain('),
|
237
|
+
Description.new,
|
238
|
+
Yaparc::Literal.new(')')),{}),
|
239
|
+
Yaparc::Many.new(
|
240
|
+
Yaparc::Seq.new(Yaparc::Literal.new('range('),
|
241
|
+
Description.new,
|
242
|
+
Yaparc::Literal.new(')')),{}),
|
243
|
+
|
244
|
+
Yaparc::Literal.new(')')) do |_,individualvaluedPropertyID1, deprecated, annotation, super_tag,inverseOf,symmetric, functional, domain, range, _|
|
245
|
+
{:object_property => {}}
|
246
|
+
end,
|
247
|
+
#'AnnotationProperty(' annotationPropertyID { annotation } ')'
|
248
|
+
Yaparc::Seq.new(Yaparc::Literal.new('AnnotationPropertyID('),
|
249
|
+
AnnotationPropertyID.new,
|
250
|
+
Yaparc::ManyOne.new(Annotation.new,{}),
|
251
|
+
Yaparc::Literal.new(')')) do |_, annotationPropertyID, annotation,_|
|
252
|
+
{:annotationProperty => {:annotationPropertyID => annotationPropertyID, :annotation => annotation }}
|
253
|
+
end,
|
254
|
+
#'OntologyProperty(' ontologyPropertyID { annotation } ')'
|
255
|
+
Yaparc::Seq.new(Yaparc::Literal.new('OntologyProperty('),
|
256
|
+
OntologyPropertyID.new,
|
257
|
+
Yaparc::ManyOne.new(Annotation.new,{}),
|
258
|
+
Yaparc::Literal.new(')')) do |_, ontologyPropertyID, annotation,_|
|
259
|
+
{:OntologyProperty => {:ontologyPropertyID => ontologyPropertyID, :annotation => annotation }}
|
260
|
+
end,
|
261
|
+
#'EquivalentProperties(' datavaluedPropertyID datavaluedPropertyID { datavaluedPropertyID } ')'
|
262
|
+
Yaparc::Seq.new(Yaparc::Literal.new('EquivalentProperties('),
|
263
|
+
DatavaluedPropertyID.new,
|
264
|
+
Yaparc::ManyOne.new(DatavaluedPropertyID.new,{}),
|
265
|
+
Yaparc::Literal.new(')')) do |_,datavaluedPropertyID, datavaluedPropertyIDs,_|
|
266
|
+
{:equivalentProperties => {}}
|
267
|
+
end,
|
268
|
+
#'SubPropertyOf(' datavaluedPropertyID datavaluedPropertyID ')'
|
269
|
+
Yaparc::Seq.new(Yaparc::Literal.new('SubPropertyOf('),
|
270
|
+
DatavaluedPropertyID.new,
|
271
|
+
DatavaluedPropertyID.new,
|
272
|
+
Yaparc::Literal.new(')')) do |_,datavaluedPropertyID1, datavaluedPropertyID2,_|
|
273
|
+
{:subPropertyOf => {}}
|
274
|
+
end,
|
275
|
+
#'EquivalentProperties(' individualvaluedPropertyID individualvaluedPropertyID { individualvaluedPropertyID } ')'
|
276
|
+
Yaparc::Seq.new(Yaparc::Literal.new('EquivalentProperties('),
|
277
|
+
IndividualvaluedPropertyID.new,
|
278
|
+
Yaparc::ManyOne.new(IndividualvaluedPropertyID.new,{}),
|
279
|
+
Yaparc::Literal.new(')')) do |_,individualvaluedPropertyID,individualvaluedPropertyIDs,_|
|
280
|
+
{:equivalentProperties => {}}
|
281
|
+
end,
|
282
|
+
#'SubPropertyOf(' individualvaluedPropertyID individualvaluedPropertyID ')'
|
283
|
+
Yaparc::Seq.new(Yaparc::Literal.new('SubPropertyOf('),
|
284
|
+
IndividualvaluedPropertyID.new,
|
285
|
+
IndividualvaluedPropertyID.new,
|
286
|
+
Yaparc::Literal.new(')')) do |_,individualvaluedPropertyID1, individualvaluedPropertyID2,_|
|
287
|
+
{:subPropertyOf => { }}
|
288
|
+
end)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# fact ::= individual
|
294
|
+
class Fact
|
295
|
+
include Yaparc::Parsable
|
296
|
+
def initialize
|
297
|
+
@parser = lambda do |input|
|
298
|
+
Individual.new
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# individual ::= 'Individual(' [ individualID ] { annotation } { 'type(' type ')' } { value } ')'
|
304
|
+
class Individual
|
305
|
+
include Yaparc::Parsable
|
306
|
+
def initialize
|
307
|
+
@parser = lambda do |input|
|
308
|
+
Yaparc::Seq.new(Yaparc::Literal.new('Individual('),
|
309
|
+
Yaparc::ZeroOne.new(IndividualID.new,{}),
|
310
|
+
Yaparc::Many.new(Annotation.new,{ }),
|
311
|
+
Yaparc::Many.new(
|
312
|
+
Yaparc::Seq.new(Yaparc::Literal.new('type('),
|
313
|
+
Type.new,
|
314
|
+
Yaparc::Literal.new(')')) do |_, type, _|
|
315
|
+
{:type => type}
|
316
|
+
end,{}),
|
317
|
+
# Yaparc::Apply.new(Yaparc::Many.new(Value.new,{ })) do |value|
|
318
|
+
# {:value => value}
|
319
|
+
# end,
|
320
|
+
Yaparc::Many.new(Value.new,{ }),
|
321
|
+
Yaparc::Literal.new(')')) do |_,individual_id, annotations, types, values,_|
|
322
|
+
individual_id.merge(annotations).merge(types).merge(values)
|
323
|
+
# {:individual_id => individual_id, :annotations => annotations, :types => types, :values => values}
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
# annotation ::= 'annotation(' annotationPropertyID URIreference ')'
|
330
|
+
# | 'annotation(' annotationPropertyID dataLiteral ')'
|
331
|
+
# | 'annotation(' annotationPropertyID individual ')'
|
332
|
+
class Annotation
|
333
|
+
include Yaparc::Parsable
|
334
|
+
def initialize
|
335
|
+
@parser = lambda do |input|
|
336
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('annotation('),
|
337
|
+
AnnotationPropertyID.new,
|
338
|
+
URIReference.new,
|
339
|
+
Yaparc::Literal.new(')')) do |_,annotation_property_id, uri_reference, _|
|
340
|
+
{:annotation_property_id => annotation_property_id, :uri_reference => uri_reference }
|
341
|
+
end,
|
342
|
+
Yaparc::Seq.new(Yaparc::Literal.new('annotation('),
|
343
|
+
AnnotationPropertyID.new,
|
344
|
+
DataLiteral.new,
|
345
|
+
Yaparc::Literal.new(')')) do |_,annotation_property_id, data_literal, _|
|
346
|
+
{:annotation_property_id => annotation_property_id, :data_literal => data_literal}
|
347
|
+
end,
|
348
|
+
Yaparc::Seq.new(Yaparc::Literal.new('annotation('),
|
349
|
+
AnnotationPropertyID.new,
|
350
|
+
Individual.new,
|
351
|
+
Yaparc::Literal.new(')')) do |_,annotation_property_id, individual, _|
|
352
|
+
{:annotation_property_id => annotation_property_id, :individual => individual }
|
353
|
+
end)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
# value ::= 'value(' individualvaluedPropertyID individualID ')'
|
360
|
+
# | 'value(' individualvaluedPropertyID individual ')'
|
361
|
+
# | 'value(' datavaluedPropertyID dataLiteral ')'
|
362
|
+
class Value
|
363
|
+
include Yaparc::Parsable
|
364
|
+
def initialize
|
365
|
+
@parser = lambda do |input|
|
366
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('value('),
|
367
|
+
IndividualvaluedPropertyID.new,
|
368
|
+
IndividualID.new,
|
369
|
+
Yaparc::Literal.new(')')) do |_,individualvalued_property_id, individual_id,_|
|
370
|
+
{:individualvalued_property_id => individualvalued_property_id, :individual_id => individual_id }
|
371
|
+
end,
|
372
|
+
Yaparc::Seq.new(Yaparc::Literal.new('value('),
|
373
|
+
IndividualvaluedPropertyID.new,
|
374
|
+
Individual.new,
|
375
|
+
Yaparc::Literal.new(')')) do |_,individualvalued_property_id, individual,_|
|
376
|
+
{:individualvalued_property_id => individualvalued_property_id, :individual => individual}
|
377
|
+
end,
|
378
|
+
Yaparc::Seq.new(Yaparc::Literal.new('value('),
|
379
|
+
IndividualvaluedPropertyID.new,
|
380
|
+
DataLiteral.new,
|
381
|
+
Yaparc::Literal.new(')')) do |_,individualvalued_property_id, data_literal,_|
|
382
|
+
{:individualvalued_property_id => individualvalued_property_id, :data_literal => data_literal}
|
383
|
+
|
384
|
+
end)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
# type ::= description
|
390
|
+
class Type
|
391
|
+
include Yaparc::Parsable
|
392
|
+
def initialize
|
393
|
+
@parser = lambda do |input|
|
394
|
+
Description.new
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
# description ::= classID
|
400
|
+
# | restriction
|
401
|
+
# | 'unionOf(' { description } ')'
|
402
|
+
# | 'intersectionOf(' { description } ')'
|
403
|
+
# | 'complementOf(' description ')'
|
404
|
+
# | 'oneOf(' { individualID } ')'
|
405
|
+
class Description
|
406
|
+
include Yaparc::Parsable
|
407
|
+
def initialize
|
408
|
+
@parser = lambda do |input|
|
409
|
+
Yaparc::Alt.new(Restriction.new,
|
410
|
+
Yaparc::Seq.new(Yaparc::Literal.new('unionOf('),
|
411
|
+
Yaparc::Many.new(Description.new,{ }),
|
412
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
413
|
+
{:unionOf => description}
|
414
|
+
end,
|
415
|
+
Yaparc::Seq.new(Yaparc::Literal.new('intersectionOf('),
|
416
|
+
Yaparc::Many.new(Description.new,{ }),
|
417
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
418
|
+
{:intersectionOf => description}
|
419
|
+
end,
|
420
|
+
Yaparc::Seq.new(Yaparc::Literal.new('complementOf('),
|
421
|
+
Description.new,
|
422
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
423
|
+
{:complementOf => description}
|
424
|
+
end,
|
425
|
+
Yaparc::Seq.new(Yaparc::Literal.new('oneOf('),
|
426
|
+
Yaparc::Many.new(IndividualID.new,{}),
|
427
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
428
|
+
{:oneOf => {:individual_id => description}}
|
429
|
+
end,
|
430
|
+
ClassID.new)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
# restriction ::= 'restriction(' datavaluedPropertyID dataRestrictionComponent { dataRestrictionComponent } ')'
|
436
|
+
# | 'restriction(' individualvaluedPropertyID individualRestrictionComponent { individualRestrictionComponent } ')'
|
437
|
+
class Restriction
|
438
|
+
include Yaparc::Parsable
|
439
|
+
def initialize
|
440
|
+
@parser = lambda do |input|
|
441
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('restriction('),
|
442
|
+
DatavaluedPropertyID.new,
|
443
|
+
Yaparc::ManyOne.new(DataRestrictionComponent.new,{ }),
|
444
|
+
Yaparc::Literal.new(')')) do |_,datavalued_property_id, data_restriction_components,_|
|
445
|
+
{:datavalued_property_id => datavalued_property_id, :data_restriction_components => data_restriction_components}
|
446
|
+
end,
|
447
|
+
Yaparc::Seq.new(Yaparc::Literal.new('restriction('),
|
448
|
+
IndividualvaluedPropertyID.new,
|
449
|
+
Yaparc::ManyOne.new(IndividualRestrictionComponent.new,{ }),
|
450
|
+
Yaparc::Literal.new(')')) do |_,individualvalued_property_id, individual_restriction_components,_|
|
451
|
+
{:individualvalued_property_id => individualvalued_property_id, :individual_restriction_components => individual_restriction_components}
|
452
|
+
end)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
# individualRestrictionComponent ::= 'allValuesFrom(' description ')'
|
458
|
+
# | 'someValuesFrom(' description ')'
|
459
|
+
# | 'value(' individualID ')'
|
460
|
+
# | cardinality
|
461
|
+
class IndividualRestrictionComponent
|
462
|
+
include Yaparc::Parsable
|
463
|
+
def initialize
|
464
|
+
@parser = lambda do |input|
|
465
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('allValuesFrom('),
|
466
|
+
Description.new,
|
467
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
468
|
+
{:allValuesFrom => description}
|
469
|
+
end,
|
470
|
+
Yaparc::Seq.new(Yaparc::Literal.new('someValuesFrom('),
|
471
|
+
Description.new,
|
472
|
+
Yaparc::Literal.new(')')) do |_,description,_|
|
473
|
+
{:someValuesFrom => description}
|
474
|
+
end,
|
475
|
+
Yaparc::Seq.new(Yaparc::Literal.new('value('),
|
476
|
+
IndividualID.new,
|
477
|
+
Yaparc::Literal.new(')')) do |_,individual_id,_|
|
478
|
+
{:value => individual_id}
|
479
|
+
end,
|
480
|
+
Cardinality.new)
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
# modality ::= 'complete' | 'partial'
|
486
|
+
class Modality
|
487
|
+
include Yaparc::Parsable
|
488
|
+
def initialize
|
489
|
+
@parser = lambda do |input|
|
490
|
+
Yaparc::Alt.new(Yaparc::Literal.new('complete'),Yaparc::Literal.new('partial'))
|
491
|
+
end
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
# dataRestrictionComponent ::= 'allValuesFrom(' dataRange ')'
|
496
|
+
# | 'someValuesFrom(' dataRange ')'
|
497
|
+
# | 'value(' dataLiteral ')'
|
498
|
+
# | cardinality
|
499
|
+
class DataRestrictionComponent
|
500
|
+
include Yaparc::Parsable
|
501
|
+
def initialize
|
502
|
+
@parser = lambda do |input|
|
503
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('allValuesFrom('),
|
504
|
+
DataRange.new,
|
505
|
+
Yaparc::Literal.new(')')) do |_,data_range,_|
|
506
|
+
{:allValuesFrom => data_range }
|
507
|
+
end,
|
508
|
+
Yaparc::Seq.new(Yaparc::Literal.new('someValuesFrom('),
|
509
|
+
DataRange.new,
|
510
|
+
Yaparc::Literal.new(')')) do |_,data_range,_|
|
511
|
+
{:someValuesFrom => data_range }
|
512
|
+
end,
|
513
|
+
Yaparc::Seq.new(Yaparc::Literal.new('value('),
|
514
|
+
DataLiteral.new,
|
515
|
+
Yaparc::Literal.new(')')) do |_,data_literal,_|
|
516
|
+
{:value => data_literal }
|
517
|
+
end,
|
518
|
+
Cardinality.new)
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
# cardinality ::= 'minCardinality(' non-negative-integer ')'
|
524
|
+
# | 'maxCardinality(' non-negative-integer ')'
|
525
|
+
# | 'cardinality(' non-negative-integer ')'
|
526
|
+
|
527
|
+
class Cardinality
|
528
|
+
include Yaparc::Parsable
|
529
|
+
def initialize
|
530
|
+
@parser = lambda do |input|
|
531
|
+
Yaparc::Alt.new(Yaparc::Seq.new(Yaparc::Literal.new('minCardinality('),
|
532
|
+
Yaparc::Many.new(NonNegativeInteger.new,0),
|
533
|
+
Yaparc::Literal.new(')')) do |_,integer,_|
|
534
|
+
{:minCardinality => integer}
|
535
|
+
end,
|
536
|
+
Yaparc::Seq.new(Yaparc::Literal.new('maxCardinality('),
|
537
|
+
Yaparc::Many.new(NonNegativeInteger.new,0),
|
538
|
+
Yaparc::Literal.new(')')) do |_,integer,_|
|
539
|
+
{:maxCardinality => integer}
|
540
|
+
end,
|
541
|
+
Yaparc::Seq.new(Yaparc::Literal.new('cardinality('),
|
542
|
+
Yaparc::Many.new(NonNegativeInteger.new,0),
|
543
|
+
Yaparc::Literal.new(')')) do |_,integer,_|
|
544
|
+
{:cardinality => integer}
|
545
|
+
end)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
class NonNegativeInteger
|
551
|
+
include Yaparc::Parsable
|
552
|
+
def initialize
|
553
|
+
@parser = lambda do |input|
|
554
|
+
Yaparc::Apply.new(Yaparc::Regex.new(/\A[0-9]+/)) do |number|
|
555
|
+
Integer(number)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
|
562
|
+
# dataRange ::= datatypeID
|
563
|
+
# | 'rdfs:Literal'
|
564
|
+
# | 'oneOf(' { dataLiteral } ')'
|
565
|
+
class DataRange
|
566
|
+
include Yaparc::Parsable
|
567
|
+
def initialize
|
568
|
+
@parser = lambda do |input|
|
569
|
+
Yaparc::Alt.new(Yaparc::Literal.new('rdfs:Literal'),
|
570
|
+
Yaparc::Seq.new(Yaparc::Literal.new('oneOf('),
|
571
|
+
Yaparc::Many.new(DataLiteral.new,[]),
|
572
|
+
Yaparc::Literal.new(')')) do |_,data_literals,_|
|
573
|
+
{:oneOf => data_literals}
|
574
|
+
end,
|
575
|
+
DatatypeID.new)
|
576
|
+
end
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
# ontologyID ::= URIreference
|
581
|
+
class OntologyID
|
582
|
+
include Yaparc::Parsable
|
583
|
+
def initialize
|
584
|
+
@parser = lambda do |input|
|
585
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
586
|
+
{:ontology_id => uri}
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
# datavaluedPropertyID ::= URIreference
|
593
|
+
class DatavaluedPropertyID
|
594
|
+
include Yaparc::Parsable
|
595
|
+
def initialize
|
596
|
+
@parser = lambda do |input|
|
597
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
598
|
+
{:datavalued_property_id => {:uri_reference => uri}}
|
599
|
+
end
|
600
|
+
#URIReference.new
|
601
|
+
#URIParser::URIReference.new
|
602
|
+
end
|
603
|
+
end
|
604
|
+
end
|
605
|
+
|
606
|
+
|
607
|
+
# individualvaluedPropertyID ::= URIreference
|
608
|
+
class IndividualvaluedPropertyID
|
609
|
+
include Yaparc::Parsable
|
610
|
+
def initialize
|
611
|
+
@parser = lambda do |input|
|
612
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
613
|
+
{:individualvalued_property_id => {:uri_reference => uri}}
|
614
|
+
end
|
615
|
+
end
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
# annotationPropertyID ::= URIreference
|
620
|
+
class AnnotationPropertyID
|
621
|
+
include Yaparc::Parsable
|
622
|
+
def initialize
|
623
|
+
@parser = lambda do |input|
|
624
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
625
|
+
{:annotation_property_id => uri}
|
626
|
+
end
|
627
|
+
end
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
# ontologyPropertyID ::= URIreference
|
632
|
+
class OntologyPropertyID
|
633
|
+
include Yaparc::Parsable
|
634
|
+
def initialize
|
635
|
+
@parser = lambda do |input|
|
636
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
637
|
+
{:ontology_property_id => {:uri_reference => uri}}
|
638
|
+
end
|
639
|
+
end
|
640
|
+
end
|
641
|
+
end
|
642
|
+
|
643
|
+
# classID ::= URIreference
|
644
|
+
class ClassID
|
645
|
+
include Yaparc::Parsable
|
646
|
+
|
647
|
+
def initialize
|
648
|
+
@parser = lambda do |input|
|
649
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
650
|
+
{:class_id => uri}
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
# individualID ::= URIreference
|
657
|
+
class IndividualID
|
658
|
+
include Yaparc::Parsable
|
659
|
+
def initialize
|
660
|
+
@parser = lambda do |input|
|
661
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
662
|
+
{:individual_id => uri}
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
# datatypeID ::= URIreference
|
669
|
+
class DatatypeID
|
670
|
+
include Yaparc::Parsable
|
671
|
+
def initialize
|
672
|
+
@parser = lambda do |input|
|
673
|
+
Yaparc::Apply.new(URIReference.new) do |uri|
|
674
|
+
{:datatype_id => {:uri_reference => uri}}
|
675
|
+
end
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
# dataLiteral ::= typedLiteral | plainLiteral
|
681
|
+
class DataLiteral
|
682
|
+
include Yaparc::Parsable
|
683
|
+
def initialize
|
684
|
+
@parser = lambda do |input|
|
685
|
+
Yaparc::Alt.new(TypedLiteral.new,
|
686
|
+
PlainLiteral.new)
|
687
|
+
end
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
# typedLiteral ::= lexicalForm^^URIreference
|
692
|
+
class TypedLiteral
|
693
|
+
include Yaparc::Parsable
|
694
|
+
def initialize
|
695
|
+
@parser = lambda do |input|
|
696
|
+
Yaparc::Seq.new(LexicalForm.new,
|
697
|
+
Yaparc::Literal.new('^^'),
|
698
|
+
URIReference.new) do |lexical_form, _, uri|
|
699
|
+
["#{lexical_form}^^#{uri}"]
|
700
|
+
end
|
701
|
+
end
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
# plainLiteral ::= lexicalForm | lexicalForm@languageTag
|
706
|
+
class PlainLiteral
|
707
|
+
include Yaparc::Parsable
|
708
|
+
def initialize
|
709
|
+
@parser = lambda do |input|
|
710
|
+
Yaparc::Alt.new(Yaparc::Seq.new(LexicalForm.new,
|
711
|
+
Yaparc::Literal.new('@'),
|
712
|
+
LanguageTag.new) do |lexical_form,_,language_tag|
|
713
|
+
[lexical_form + '@' + language_tag]
|
714
|
+
end,
|
715
|
+
LexicalForm.new)
|
716
|
+
end
|
717
|
+
end
|
718
|
+
end
|
719
|
+
|
720
|
+
#lexicalForm ::= as in RDF, a unicode string in normal form C
|
721
|
+
class LexicalForm
|
722
|
+
include Yaparc::Parsable
|
723
|
+
def initialize
|
724
|
+
@parser = lambda do |input|
|
725
|
+
Yaparc::Apply.new(Yaparc::Regex.new(/"[^"]*"/)) do |lexical_form|
|
726
|
+
lexical_form
|
727
|
+
end
|
728
|
+
end
|
729
|
+
end
|
730
|
+
end
|
731
|
+
|
732
|
+
#languageTag ::= as in RDF, an XML language tag
|
733
|
+
class LanguageTag
|
734
|
+
include Yaparc::Parsable
|
735
|
+
def initialize
|
736
|
+
@parser = lambda do |input|
|
737
|
+
Yaparc::Regex.new(/[a-zA-Z-]+/)
|
738
|
+
end
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
742
|
+
# ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
|
743
|
+
class URIReference
|
744
|
+
include Yaparc::Parsable
|
745
|
+
def initialize
|
746
|
+
@parser = lambda do |input|
|
747
|
+
|
748
|
+
keyword_parsers = OWLParser::KEYWORDS.map {|keyword| Yaparc::Literal.new(keyword)}
|
749
|
+
case result = Yaparc::Alt.new(*keyword_parsers).parse(input)
|
750
|
+
when Yaparc::Result::OK
|
751
|
+
return Yaparc::Fail.new
|
752
|
+
end
|
753
|
+
|
754
|
+
parser = Yaparc::Tokenize.new(Yaparc::Regex.new(/\A(([^:\/?# ]+):)?(\/\/([^\/?#() ]*))?([^?#() ]*)(\?([^# ]*))?(#(.*))?/), :prefix => Yaparc::Space.new, :postfix => Yaparc::Space.new)
|
755
|
+
case result = parser.parse(input)
|
756
|
+
when Yaparc::Result::OK
|
757
|
+
unless result.value.empty?
|
758
|
+
Yaparc::Result::OK.new(:value => {:uri_reference => result.value}, :input => result.input)
|
759
|
+
else
|
760
|
+
Yaparc::Fail.new
|
761
|
+
end
|
762
|
+
else
|
763
|
+
result
|
764
|
+
end
|
765
|
+
end
|
766
|
+
end
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
770
|
+
|
771
|
+
class OwlTest < Test::Unit::TestCase
|
772
|
+
include ::Yaparc
|
773
|
+
|
774
|
+
def test_ontology
|
775
|
+
ontology = OWLParser::Ontology.new
|
776
|
+
result = ontology.parse("Ontology()")
|
777
|
+
assert_instance_of Result::OK, result
|
778
|
+
result = ontology.parse("Ontology(ex:ontology_id)")
|
779
|
+
assert_instance_of Result::OK, result
|
780
|
+
result = ontology.parse("Ontology(Class(ex:class complete annotation(ex:annotation http://localhost.localdomain )))")
|
781
|
+
assert_instance_of Result::OK, result
|
782
|
+
result = ontology.parse("Ontology(Class(ex:class Deprecated partial annotation(ex:annotation http://localhost.localdomain )))")
|
783
|
+
assert_instance_of Result::OK, result
|
784
|
+
|
785
|
+
ontology1 = <<-EOS
|
786
|
+
Ontology(ontology1
|
787
|
+
Class(Pc complete unionOf(Desktop Laptop))
|
788
|
+
Individual(ibmR40 type(Laptop))
|
789
|
+
Individual(compaqPresario200 type(Desktop))
|
790
|
+
Class(PcOffice complete intersectionOf(Pc complementOf(Desktop))))
|
791
|
+
EOS
|
792
|
+
result = ontology.parse(ontology1)
|
793
|
+
assert_instance_of Result::OK, result
|
794
|
+
end
|
795
|
+
|
796
|
+
def test_directive
|
797
|
+
directive = OWLParser::Directive.new
|
798
|
+
result = directive.parse("Class(ex:class complete )")
|
799
|
+
assert_instance_of Result::OK, result
|
800
|
+
result = directive.parse("Class(ex:class complete annotation(ex:annotation http://localhost.localdomain ))")
|
801
|
+
assert_instance_of Result::OK, result
|
802
|
+
result = directive.parse("Class(ex:class Deprecated partial annotation(ex:annotation http://localhost.localdomain ))")
|
803
|
+
assert_instance_of Result::OK, result
|
804
|
+
end
|
805
|
+
|
806
|
+
def test_axiom
|
807
|
+
axiom = OWLParser::Axiom.new
|
808
|
+
result = axiom.parse("Class(Pc complete unionOf(Desktop Laptop))")
|
809
|
+
assert_instance_of Result::OK, result
|
810
|
+
result = axiom.parse("Class(ex:class_id complete )")
|
811
|
+
assert_instance_of Result::OK, result
|
812
|
+
result = axiom.parse("EnumeratedClass(ex:class_id Deprecated )")
|
813
|
+
assert_instance_of Result::OK, result
|
814
|
+
result = axiom.parse("Class(ex:class complete annotation(ex:annotation http://localhost.localdomain ))")
|
815
|
+
assert_instance_of Result::OK, result
|
816
|
+
result = axiom.parse("Class(ex:class Deprecated partial annotation(ex:annotation http://localhost.localdomain ))")
|
817
|
+
result = axiom.parse("SubClassOf(ex:subclass ex:superclass)")
|
818
|
+
assert_instance_of Result::OK, result
|
819
|
+
end
|
820
|
+
|
821
|
+
def test_annotation
|
822
|
+
annotation = OWLParser::Annotation.new
|
823
|
+
result = annotation.parse("annotation(ex:annotation http://localhost.localdomain)")
|
824
|
+
assert_instance_of Result::OK, result
|
825
|
+
result = annotation.parse("annotation(ex:annotation type(ex:human))")
|
826
|
+
assert_instance_of Result::Fail, result
|
827
|
+
result = annotation.parse('annotation(ex:annotation "akimichi"^^http://www.w3.org/2001/XMLSchema@integer)')
|
828
|
+
assert_instance_of Result::OK, result
|
829
|
+
assert_instance_of Result::Fail, annotation.parse("annotation(ex:annotation value(ex:human))")
|
830
|
+
assert_instance_of Result::Fail, annotation.parse("annotation(ex:annotation type(ex:human) value(ex:human))")
|
831
|
+
end
|
832
|
+
|
833
|
+
def test_value
|
834
|
+
value = OWLParser::Value.new
|
835
|
+
result = value.parse("value(ex:value http://localhost.localdomain)")
|
836
|
+
assert_instance_of Result::OK, result
|
837
|
+
end
|
838
|
+
|
839
|
+
def test_individual
|
840
|
+
individual = OWLParser::Individual.new
|
841
|
+
result = individual.parse("Individual(ex:individual)")
|
842
|
+
assert_instance_of Result::OK, result
|
843
|
+
assert_equal Hash[:individual_id=>{:uri_reference=>"ex:individual"}], result.value
|
844
|
+
result = individual.parse("Individual(ex:individual type(ex:human))")
|
845
|
+
assert_instance_of Result::OK, result
|
846
|
+
assert_instance_of Result::OK, individual.parse("Individual(ex:individual type(ex:human))")
|
847
|
+
assert_instance_of Result::OK, individual.parse("Individual(ex:individual value(ex:human http://localhost.localdomain))")
|
848
|
+
assert_instance_of Result::OK, individual.parse("Individual(ex:individual type(ex:human) value(ex:human http://localhost.localdomain))")
|
849
|
+
end
|
850
|
+
|
851
|
+
def test_type
|
852
|
+
type = OWLParser::Type.new
|
853
|
+
assert_instance_of Result::OK, type.parse("http://localhost.localdomain")
|
854
|
+
assert_instance_of Result::OK, type.parse("unionOf( )")
|
855
|
+
assert_instance_of Result::OK, type.parse("unionOf(Desktop Laptop)")
|
856
|
+
assert_instance_of Result::OK, type.parse("unionOf(http://localhost.localdomain)")
|
857
|
+
assert_instance_of Result::OK, type.parse("ex:hasMember")
|
858
|
+
assert_instance_of Result::OK, type.parse("unionOf(ex:hasMember)")
|
859
|
+
assert_instance_of Result::OK, type.parse("intersectionOf(ex:hasMember)")
|
860
|
+
assert_instance_of Result::OK, type.parse("complementOf(intersectionOf(ex:hasMember))")
|
861
|
+
assert_instance_of Result::OK, type.parse("oneOf(ex:hasMember)")
|
862
|
+
end
|
863
|
+
|
864
|
+
def test_description
|
865
|
+
description = OWLParser::Description.new
|
866
|
+
assert_instance_of Result::OK, description.parse("http://localhost.localdomain")
|
867
|
+
assert_instance_of Result::OK, description.parse("unionOf( )")
|
868
|
+
assert_instance_of Result::OK, description.parse("unionOf(http://localhost.localdomain)")
|
869
|
+
assert_instance_of Result::OK, description.parse("unionOf(Desktop Laptop)")
|
870
|
+
assert_instance_of Result::OK, description.parse("ex:hasMember")
|
871
|
+
assert_instance_of Result::OK, description.parse("unionOf(ex:hasMember)")
|
872
|
+
assert_instance_of Result::OK, description.parse("intersectionOf(ex:hasMember)")
|
873
|
+
assert_instance_of Result::OK, description.parse("complementOf(intersectionOf(ex:hasMember))")
|
874
|
+
assert_instance_of Result::OK, description.parse("oneOf(ex:hasMember)")
|
875
|
+
assert_instance_of Result::OK, description.parse("restriction(ex:hasMember allValuesFrom(ex:StringPlayer))")
|
876
|
+
end
|
877
|
+
|
878
|
+
def test_individual_restriction_component
|
879
|
+
individual_restriction_component = OWLParser::IndividualRestrictionComponent.new
|
880
|
+
result = individual_restriction_component.parse("allValuesFrom(ex:StringPlayer)")
|
881
|
+
assert_instance_of Result::OK, result
|
882
|
+
assert_equal "", result.input
|
883
|
+
result = individual_restriction_component.parse("someValuesFrom(ex:StringPlayer)")
|
884
|
+
assert_instance_of Result::OK, result
|
885
|
+
assert_equal "", result.input
|
886
|
+
result = individual_restriction_component.parse("value(ex:StringPlayer)")
|
887
|
+
assert_instance_of Result::OK, result
|
888
|
+
assert_equal "", result.input
|
889
|
+
result = individual_restriction_component.parse("minCardinality(1)")
|
890
|
+
assert_instance_of Result::OK, result
|
891
|
+
assert_equal "", result.input
|
892
|
+
end
|
893
|
+
|
894
|
+
def test_restriction
|
895
|
+
restriction = OWLParser::Restriction.new
|
896
|
+
assert_instance_of Result::OK, restriction.parse("restriction(ex:hasMember value(datatype))")
|
897
|
+
assert_instance_of Result::OK, restriction.parse("restriction(ex:hasMember allValuesFrom(ex:StringPlayer))")
|
898
|
+
end
|
899
|
+
|
900
|
+
|
901
|
+
def test_data_restriction_component
|
902
|
+
data_restriction_component = OWLParser::DataRestrictionComponent.new
|
903
|
+
assert_instance_of Result::OK, data_restriction_component.parse('value("akimichi"@ja)')
|
904
|
+
assert_instance_of Result::OK, data_restriction_component.parse("allValuesFrom( rdfs:Literal )")
|
905
|
+
assert_instance_of Result::OK, data_restriction_component.parse("allValuesFrom(ex:StringPlayer)")
|
906
|
+
assert_instance_of Result::OK, data_restriction_component.parse("allValuesFrom(http://localhost.localdomain)")
|
907
|
+
assert_instance_of Result::OK, data_restriction_component.parse("allValuesFrom(oneOf())")
|
908
|
+
assert_instance_of Result::OK, data_restriction_component.parse('allValuesFrom(oneOf("akimichi"@ja))')
|
909
|
+
assert_instance_of Result::OK, data_restriction_component.parse("maxCardinality(10)")
|
910
|
+
assert_instance_of Result::OK, data_restriction_component.parse("cardinality(398)")
|
911
|
+
assert_instance_of Result::OK, data_restriction_component.parse("minCardinality(1)")
|
912
|
+
assert_instance_of Result::OK, data_restriction_component.parse("maxCardinality(10)")
|
913
|
+
assert_instance_of Result::OK, data_restriction_component.parse("cardinality(398)")
|
914
|
+
|
915
|
+
end
|
916
|
+
|
917
|
+
def test_cardinality
|
918
|
+
cardinality = OWLParser::Cardinality.new
|
919
|
+
assert_instance_of Result::OK, cardinality.parse("minCardinality(1)")
|
920
|
+
assert_instance_of Result::OK, cardinality.parse("maxCardinality(10)")
|
921
|
+
assert_instance_of Result::OK, cardinality.parse("cardinality(398)")
|
922
|
+
|
923
|
+
end
|
924
|
+
|
925
|
+
def test_data_range
|
926
|
+
data_range = OWLParser::DataRange.new
|
927
|
+
assert_instance_of Result::OK, data_range.parse("datatype@localhost.localdomain")
|
928
|
+
assert_instance_of Result::OK, data_range.parse("http://datatype@localhost.localdomain")
|
929
|
+
assert_instance_of Result::OK, data_range.parse("http://localhost.localdomain")
|
930
|
+
assert_instance_of Result::OK, data_range.parse("datatype@localhost.localdomain)")
|
931
|
+
assert_instance_of Result::OK, data_range.parse("rdfs:Literal")
|
932
|
+
assert_instance_of Result::OK, data_range.parse("oneOf()")
|
933
|
+
assert_instance_of Result::OK, data_range.parse('oneOf("akimichi"@ja)')
|
934
|
+
# assert_instance_of Result::OK, data_range.parse("oneOf( emile@datarange.localdomain )")
|
935
|
+
end
|
936
|
+
|
937
|
+
def test_data_literal
|
938
|
+
data_literal = OWLParser::DataLiteral.new
|
939
|
+
assert_instance_of Result::OK, data_literal.parse('"akimichi"@ja')
|
940
|
+
assert_instance_of Result::OK, data_literal.parse('"akimichi"^^http://www.w3.org/2001/XMLSchema@integer')
|
941
|
+
assert_instance_of Result::Fail, data_literal.parse("ex:hasMember")
|
942
|
+
assert_instance_of Result::Fail, data_literal.parse("datatype")
|
943
|
+
assert_instance_of Result::Fail, data_literal.parse("emile@localhost.localdomain")
|
944
|
+
end
|
945
|
+
|
946
|
+
def test_plain_literal
|
947
|
+
plain_literal = OWLParser::PlainLiteral.new
|
948
|
+
assert_instance_of Result::OK, plain_literal.parse('"akimichi"@ja')
|
949
|
+
result = plain_literal.parse('"nick"@en-US')
|
950
|
+
assert_instance_of Result::OK, result
|
951
|
+
assert_equal ["\"nick\"@en-US"], result.value
|
952
|
+
assert_instance_of Result::OK, plain_literal.parse('"akimichi"')
|
953
|
+
end
|
954
|
+
|
955
|
+
def test_typed_literal
|
956
|
+
typed_literal = OWLParser::TypedLiteral.new
|
957
|
+
assert_instance_of Result::OK, typed_literal.parse('"akimichi"^^http://www.w3.org/2001/XMLSchema@integer')
|
958
|
+
end
|
959
|
+
|
960
|
+
def test_lexical_form
|
961
|
+
lexical_form = OWLParser::LexicalForm.new
|
962
|
+
assert_instance_of Result::OK, lexical_form.parse('"ex:hasMember"')
|
963
|
+
assert_instance_of Result::OK, lexical_form.parse('"datatype"')
|
964
|
+
assert_instance_of Result::OK, lexical_form.parse('"emile@localhost.localdomain"')
|
965
|
+
end
|
966
|
+
|
967
|
+
def test_language_tag
|
968
|
+
language_tag = OWLParser::LanguageTag.new
|
969
|
+
assert_instance_of Result::OK, language_tag.parse("ja")
|
970
|
+
result = language_tag.parse("en-US")
|
971
|
+
assert_instance_of Result::OK, result
|
972
|
+
assert_equal "en-US", result.value
|
973
|
+
end
|
974
|
+
|
975
|
+
def test_annotation_property_id
|
976
|
+
annotation_property_id = OWLParser::AnnotationPropertyID.new
|
977
|
+
result = annotation_property_id.parse("ex:annotation")
|
978
|
+
assert_instance_of Result::OK, result
|
979
|
+
assert_equal Hash[:annotation_property_id => {:uri_reference=>"ex:annotation"}], result.value
|
980
|
+
end
|
981
|
+
|
982
|
+
def test_individual_id
|
983
|
+
individual_id = OWLParser::IndividualID.new
|
984
|
+
assert_instance_of Result::Fail, individual_id.parse("type(")
|
985
|
+
result = individual_id.parse("ex:individual")
|
986
|
+
assert_instance_of Result::OK, result
|
987
|
+
assert_equal "", result.input
|
988
|
+
result = individual_id.parse("ex:individual type")
|
989
|
+
assert_instance_of Result::OK, result
|
990
|
+
assert_equal Hash[:individual_id => {:uri_reference=>"ex:individual"}], result.value
|
991
|
+
assert_equal "type", result.input
|
992
|
+
assert_instance_of Result::OK, individual_id.parse("http://localhost.localdomain:3000/pchar;param?query")
|
993
|
+
assert_instance_of Result::OK, individual_id.parse("http://localhost.localdomain")
|
994
|
+
end
|
995
|
+
|
996
|
+
def test_ontology_id
|
997
|
+
ontology_id = OWLParser::OntologyID.new
|
998
|
+
assert_instance_of Result::OK, ontology_id.parse("http://localhost.localdomain:3000")
|
999
|
+
result = ontology_id.parse("ex:individual type")
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
def test_class_id
|
1003
|
+
class_id = OWLParser::ClassID.new
|
1004
|
+
result = class_id.parse("ex:class_id")
|
1005
|
+
assert_instance_of Result::OK, result
|
1006
|
+
assert_equal Hash[:class_id=>{:uri_reference=>"ex:class_id"}], result.value
|
1007
|
+
result = class_id.parse("ex:individual")
|
1008
|
+
assert_instance_of Result::OK, class_id.parse("http://localhost.localdomain:3000")
|
1009
|
+
result = class_id.parse("ex:individual type")
|
1010
|
+
assert_instance_of Result::OK, result
|
1011
|
+
assert_equal Hash[:class_id=> {:uri_reference=>"ex:individual"}], result.value
|
1012
|
+
assert_equal "type", result.input
|
1013
|
+
assert_instance_of Result::OK, class_id.parse("http://localhost.localdomain:3000/pchar;param?query")
|
1014
|
+
assert_instance_of Result::OK, class_id.parse("http://localhost.localdomain")
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
def test_uri_reference
|
1018
|
+
uri_reference = OWLParser::URIReference.new
|
1019
|
+
assert_instance_of Result::OK, uri_reference.parse("http://localhost.localdomain:3000/pchar;param?query")
|
1020
|
+
assert_instance_of Result::OK, uri_reference.parse("http://localhost.localdomain")
|
1021
|
+
result = uri_reference.parse("http://localhost.localdomain")
|
1022
|
+
assert_instance_of Result::OK, result
|
1023
|
+
assert_equal Hash[:uri_reference=>"http://localhost.localdomain"], result.value
|
1024
|
+
assert_equal "", result.input
|
1025
|
+
result = uri_reference.parse("http://localhost.localdomain)")
|
1026
|
+
assert_instance_of Result::OK, result
|
1027
|
+
assert_equal Hash[:uri_reference=>"http://localhost.localdomain"], result.value
|
1028
|
+
assert_equal ")", result.input
|
1029
|
+
result = uri_reference.parse("ex:hasMember")
|
1030
|
+
assert_instance_of Result::OK, result
|
1031
|
+
assert_equal Hash[:uri_reference => "ex:hasMember"], result.value
|
1032
|
+
assert_equal "", result.input
|
1033
|
+
result = uri_reference.parse("")
|
1034
|
+
assert_instance_of Result::Fail, result
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
|
1038
|
+
|
1039
|
+
end
|