-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkrss_parser.mly
160 lines (130 loc) · 4.93 KB
/
krss_parser.mly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
%{
(***********************************************************)
(* Copyright (C) 2009 *)
(* Yevgeny Kazakov <yevgeny.kazakov@comlab.ox.ac.uk> *)
(* University of Oxford *)
(* *)
(* Copyright (C) 2010 - 2014 *)
(* Michel Ludwig (michel.ludwig@gmail.com) *)
(* University of Liverpool *)
(* *)
(* This program is free software; you can redistribute *)
(* it and/or modify it under the terms of the GNU *)
(* General Public License as published by the Free *)
(* Software Foundation; either version 3 of the License, *)
(* or (at your option) any later version. *)
(* *)
(* This program is distributed in the hope that it will *)
(* be useful, but WITHOUT ANY WARRANTY; without even *)
(* the implied warranty of MERCHANTABILITY or FITNESS *)
(* FOR A PARTICULAR PURPOSE. See the GNU General Public *)
(* License for more details. *)
(* *)
(* You should have received a copy of the GNU General *)
(* Public License along with this program; if not, see *)
(* <http://www.gnu.org/licenses/>. *)
(***********************************************************)
open Types
open Utilities
(* abbreviations for commonly used modules *)
(*let parse_error s = *)
(* Printf.fprintf stderr "%s" s;*)
(* raise Parsing.Parse_error *)
(*;; *)
let checkIfConceptNameHashOccurredLeftAlready leftHandSideSet conceptName =
if StringSet.mem !leftHandSideSet conceptName then
failwith("Concept name " ^ conceptName ^ " already occurred on the left-hand side of a concept axiom!")
else
leftHandSideSet := StringSet.add !leftHandSideSet conceptName
let leftHandSideSet = ref (StringSet.empty)
%}
/* parentheses */
%token LeftParen RightParen
/* axioms keywords */
%token Implies Equivalent EquivalentRole ImpliesRole Inverse Functional
%token Transitive Composition Domain Range
/* properties */
%token DomainProperty RangeProperty RightIdentityProperty ParentsProperty ParentProperty
/* constructors */
%token And Or Some All Not Inv Top Bottom
/* identifiers */
%token <string> Identifier
/* comments */
%token <string> Comment
/* eof */
%token EOF
%start ontology
%type <Types.axiom list> ontology
%%
ontology : init axioms EOF
{ $2 }
init :
{ leftHandSideSet := StringSet.empty; }
axioms : /* empty */ { [] }
| axioms axiom { List.rev_append $2 $1 }
axiom :
concept_axiom { [$1] }
| role_axiom { [$1] }
| ignored_role_axiom { [] }
| domain_axiom { [$1] }
| range_axiom { [$1] }
| domain_range_axiom { $1 }
concept_axiom :
LeftParen Implies concept_name RightParen
{ checkIfConceptNameHashOccurredLeftAlready leftHandSideSet $3;
ConceptInclusion(Name $3, Name $3)
}
| LeftParen Implies concept_name concept RightParen
{ checkIfConceptNameHashOccurredLeftAlready leftHandSideSet $3;
ConceptInclusion(Name $3, $4) }
| LeftParen Equivalent concept_name concept RightParen
{ checkIfConceptNameHashOccurredLeftAlready leftHandSideSet $3;
ConceptEquality(Name $3, $4) }
concept_name:
Identifier
{ $1 }
concept :
Identifier
{ Name $1 }
| LeftParen And and_concepts RightParen
{ And($3) }
| LeftParen Some role Top RightParen
{ Exists($3, Top) }
| LeftParen Some role concept RightParen
{ Exists($3, $4) }
and_concepts :
concept concept
{ [$1; $2] }
| and_concepts concept
{ $2::$1 }
role :
Identifier
{ $1 }
role_axiom :
LeftParen ImpliesRole role RightParen
{ RoleInclusion($3, $3) }
| LeftParen ImpliesRole role role RightParen
{ RoleInclusion($3, $4) }
| LeftParen ImpliesRole role ParentProperty role RightParen
{ RoleInclusion($3, $5) }
| LeftParen ImpliesRole role ParentsProperty LeftParen role RightParen RightParen
{ RoleInclusion($3, $6) }
ignored_role_axiom :
| LeftParen ImpliesRole role RightIdentityProperty role RightParen
{ print_endline("Right-identity axiom (" ^ $3 ^ ", " ^ $3 ^ ") ignored."); }
domain_axiom :
LeftParen Domain role concept RightParen
{ ConceptInclusion(Domain($3), $4) }
| LeftParen ImpliesRole role DomainProperty concept RightParen
{ ConceptInclusion(Domain($3), $5) }
range_axiom :
LeftParen Range role concept RightParen
{ ConceptInclusion(Range($3), $4) }
| LeftParen ImpliesRole role RangeProperty concept RightParen
{ ConceptInclusion(Range($3), $5) }
domain_range_axiom :
LeftParen ImpliesRole role DomainProperty concept RangeProperty concept RightParen
{ [ConceptInclusion(Domain($3), $5);
ConceptInclusion(Range($3), $7)] }
%%
(* kate: replace-tabs on; indent-width 2; *)