1
1
"""
2
2
Defines all the types in the QuaRel domain.
3
3
"""
4
- from typing import Dict
5
- from allennlp .semparse .type_declarations .type_declaration import ComplexType , NamedBasicType , Type
4
+ from allennlp .semparse .type_declarations .type_declaration import ComplexType , NamedBasicType , NameMapper
6
5
7
6
class QuarelTypeDeclaration :
8
7
def __init__ (self , syntax : str ) -> None :
9
8
10
- self .common_name_mapping : Dict [str , str ] = {}
11
-
12
- self .common_type_signature : Dict [str , Type ] = {}
9
+ self .name_mapper = NameMapper ()
13
10
14
11
num_type = NamedBasicType ("NUM" )
15
12
attr_type = NamedBasicType ("ATTR" )
@@ -30,18 +27,18 @@ def __init__(self, syntax: str) -> None:
30
27
infer_function_type = ComplexType (attr_type ,
31
28
ComplexType (attr_type ,
32
29
ComplexType (attr_type , num_type )))
33
- self .add_common_name_with_type ("infer" , "I10 " , infer_function_type )
30
+ self .name_mapper . map_name_with_signature ("infer" , infer_function_type )
34
31
# Attributes
35
- self .add_common_name_with_type ("friction" , "A10 " , attr_function_type )
36
- self .add_common_name_with_type ("smoothness" , "A11 " , attr_function_type )
37
- self .add_common_name_with_type ("speed" , "A12 " , attr_function_type )
38
- self .add_common_name_with_type ("heat" , "A13 " , attr_function_type )
39
- self .add_common_name_with_type ("distance" , "A14 " , attr_function_type )
32
+ self .name_mapper . map_name_with_signature ("friction" , attr_function_type )
33
+ self .name_mapper . map_name_with_signature ("smoothness" , attr_function_type )
34
+ self .name_mapper . map_name_with_signature ("speed" , attr_function_type )
35
+ self .name_mapper . map_name_with_signature ("heat" , attr_function_type )
36
+ self .name_mapper . map_name_with_signature ("distance" , attr_function_type )
40
37
41
38
# For simplicity we treat "high" and "low" as directions as well
42
- self .add_common_name_with_type ("high" , "R12 " , rdir_type )
43
- self .add_common_name_with_type ("low" , "R13 " , rdir_type )
44
- self .add_common_name_with_type ("and" , "C10 " , and_function_type )
39
+ self .name_mapper . map_name_with_signature ("high" , rdir_type )
40
+ self .name_mapper . map_name_with_signature ("low" , rdir_type )
41
+ self .name_mapper . map_name_with_signature ("and" , and_function_type )
45
42
46
43
self .curried_functions = {
47
44
attr_function_type : 2 ,
@@ -59,14 +56,14 @@ def __init__(self, syntax: str) -> None:
59
56
infer_function_type = ComplexType (attr_type ,
60
57
ComplexType (attr_type ,
61
58
ComplexType (attr_type , num_type )))
62
- self .add_common_name_with_type ("infer" , "I10 " , infer_function_type )
59
+ self .name_mapper . map_name_with_signature ("infer" , infer_function_type )
63
60
# TODO: Remove this?
64
- self .add_common_name_with_type ("placeholder" , "A99 " , attr_function_type )
61
+ self .name_mapper . map_name_with_signature ("placeholder" , attr_function_type )
65
62
66
63
# For simplicity we treat "high" and "low" as directions as well
67
- self .add_common_name_with_type ("high" , "R12 " , rdir_type )
68
- self .add_common_name_with_type ("low" , "R13 " , rdir_type )
69
- self .add_common_name_with_type ("and" , "C10 " , and_function_type )
64
+ self .name_mapper . map_name_with_signature ("high" , rdir_type )
65
+ self .name_mapper . map_name_with_signature ("low" , rdir_type )
66
+ self .name_mapper . map_name_with_signature ("and" , and_function_type )
70
67
71
68
self .curried_functions = {
72
69
attr_function_type : 2 ,
@@ -85,32 +82,32 @@ def __init__(self, syntax: str) -> None:
85
82
infer_function_type = ComplexType (attr_type ,
86
83
ComplexType (attr_type ,
87
84
ComplexType (attr_type , num_type )))
88
- self .add_common_name_with_type ("infer" , "I10 " , infer_function_type )
85
+ self .name_mapper . map_name_with_signature ("infer" , infer_function_type )
89
86
# Attributes
90
- self .add_common_name_with_type ("friction" , "A10 " , attr_function_type )
91
- self .add_common_name_with_type ("smoothness" , "A11 " , attr_function_type )
92
- self .add_common_name_with_type ("speed" , "A12 " , attr_function_type )
93
- self .add_common_name_with_type ("heat" , "A13 " , attr_function_type )
94
- self .add_common_name_with_type ("distance" , "A14 " , attr_function_type )
95
- self .add_common_name_with_type ("acceleration" , "A15 " , attr_function_type )
96
- self .add_common_name_with_type ("amountSweat" , "A16 " , attr_function_type )
97
- self .add_common_name_with_type ("apparentSize" , "A17 " , attr_function_type )
98
- self .add_common_name_with_type ("breakability" , "A18 " , attr_function_type )
99
- self .add_common_name_with_type ("brightness" , "A19 " , attr_function_type )
100
- self .add_common_name_with_type ("exerciseIntensity" , "A20 " , attr_function_type )
101
- self .add_common_name_with_type ("flexibility" , "A21 " , attr_function_type )
102
- self .add_common_name_with_type ("gravity" , "A22 " , attr_function_type )
103
- self .add_common_name_with_type ("loudness" , "A23 " , attr_function_type )
104
- self .add_common_name_with_type ("mass" , "A24 " , attr_function_type )
105
- self .add_common_name_with_type ("strength" , "A25 " , attr_function_type )
106
- self .add_common_name_with_type ("thickness" , "A26 " , attr_function_type )
107
- self .add_common_name_with_type ("time" , "A27 " , attr_function_type )
108
- self .add_common_name_with_type ("weight" , "A28 " , attr_function_type )
87
+ self .name_mapper . map_name_with_signature ("friction" , attr_function_type )
88
+ self .name_mapper . map_name_with_signature ("smoothness" , attr_function_type )
89
+ self .name_mapper . map_name_with_signature ("speed" , attr_function_type )
90
+ self .name_mapper . map_name_with_signature ("heat" , attr_function_type )
91
+ self .name_mapper . map_name_with_signature ("distance" , attr_function_type )
92
+ self .name_mapper . map_name_with_signature ("acceleration" , attr_function_type )
93
+ self .name_mapper . map_name_with_signature ("amountSweat" , attr_function_type )
94
+ self .name_mapper . map_name_with_signature ("apparentSize" , attr_function_type )
95
+ self .name_mapper . map_name_with_signature ("breakability" , attr_function_type )
96
+ self .name_mapper . map_name_with_signature ("brightness" , attr_function_type )
97
+ self .name_mapper . map_name_with_signature ("exerciseIntensity" , attr_function_type )
98
+ self .name_mapper . map_name_with_signature ("flexibility" , attr_function_type )
99
+ self .name_mapper . map_name_with_signature ("gravity" , attr_function_type )
100
+ self .name_mapper . map_name_with_signature ("loudness" , attr_function_type )
101
+ self .name_mapper . map_name_with_signature ("mass" , attr_function_type )
102
+ self .name_mapper . map_name_with_signature ("strength" , attr_function_type )
103
+ self .name_mapper . map_name_with_signature ("thickness" , attr_function_type )
104
+ self .name_mapper . map_name_with_signature ("time" , attr_function_type )
105
+ self .name_mapper . map_name_with_signature ("weight" , attr_function_type )
109
106
110
107
# For simplicity we treat "high" and "low" as directions as well
111
- self .add_common_name_with_type ("high" , "R12 " , rdir_type )
112
- self .add_common_name_with_type ("low" , "R13 " , rdir_type )
113
- self .add_common_name_with_type ("and" , "C10 " , and_function_type )
108
+ self .name_mapper . map_name_with_signature ("high" , rdir_type )
109
+ self .name_mapper . map_name_with_signature ("low" , rdir_type )
110
+ self .name_mapper . map_name_with_signature ("and" , and_function_type )
114
111
115
112
self .curried_functions = {
116
113
attr_function_type : 2 ,
@@ -121,19 +118,15 @@ def __init__(self, syntax: str) -> None:
121
118
else :
122
119
raise Exception (f"Unknown LF syntax specification: { syntax } " )
123
120
124
- self .add_common_name_with_type ("higher" , "R10 " , rdir_type )
125
- self .add_common_name_with_type ("lower" , "R11 " , rdir_type )
121
+ self .name_mapper . map_name_with_signature ("higher" , rdir_type )
122
+ self .name_mapper . map_name_with_signature ("lower" , rdir_type )
126
123
127
- self .add_common_name_with_type ("world1" , "W11 " , world_type )
128
- self .add_common_name_with_type ("world2" , "W12 " , world_type )
124
+ self .name_mapper . map_name_with_signature ("world1" , world_type )
125
+ self .name_mapper . map_name_with_signature ("world2" , world_type )
129
126
130
127
# Hack to expose types
131
128
self .world_type = world_type
132
129
self .attr_function_type = attr_function_type
133
130
self .var_type = var_type
134
131
135
132
self .starting_types = {num_type }
136
-
137
- def add_common_name_with_type (self , name : str , mapping : str , type_signature : Type ) -> None :
138
- self .common_name_mapping [name ] = mapping
139
- self .common_type_signature [mapping ] = type_signature
0 commit comments