Skip to content

Commit c4744a7

Browse files
committed
Changed 'options' to 'oneOf' to implement proposal json-schema-org/json-schema-spec#57
1 parent 063f7d9 commit c4744a7

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/controller/controller.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def on_door_opened(self, is_opened):
3939
if secs <= self.auth_ttl_secs: # Permission case
4040
welcome_action = self.alarm_source.get_action_by_types(['http://www.matthias-fisch.de/ontologies/wot#PlaybackAction'])
4141
if welcome_action:
42-
pb = TDInputBuilder()
43-
pb.add_option_rule('http://www.matthias-fisch.de/ontologies/wot#SoundFile', 'http://www.matthias-fisch.de/ontologies/wot#WelcomeSound')
42+
ib = TDInputBuilder()
43+
ib.add_oneof_rule('http://www.matthias-fisch.de/ontologies/wot#SoundFile', 'http://www.matthias-fisch.de/ontologies/wot#WelcomeSound')
4444

4545
try:
46-
params = pb.build(welcome_action)
46+
params = ib.build(welcome_action)
4747
except UnknownSemanticsException:
4848
print("Wanted to say 'Welcome', but semantics of playback action could not be determined :(")
4949
return
@@ -55,15 +55,15 @@ def on_door_opened(self, is_opened):
5555
alarm_action = self.alarm_source.get_action_by_types(
5656
['http://www.matthias-fisch.de/ontologies/wot#AlarmAction'])
5757

58-
pb = TDInputBuilder()
59-
pb.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
58+
ib = TDInputBuilder()
59+
ib.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
6060
'http://dbpedia.org/resource/Second', self.alarm_duration_secs)
61-
pb.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
61+
ib.add_value_rule('http://www.matthias-fisch.de/ontologies/wot#Duration',
6262
'http://dbpedia.org/resource/Millisecond', self.alarm_duration_secs * 1000)
63-
pb.add_option_rule('http://dbpedia.org/ontology/Colour', 'http://dbpedia.org/resource/Red')
63+
ib.add_oneof_rule('http://dbpedia.org/ontology/Colour', 'http://dbpedia.org/resource/Red')
6464

6565
try:
66-
params = pb.build(alarm_action)
66+
params = ib.build(alarm_action)
6767
except UnknownSemanticsException as e:
6868
print("Cannot determine semantics of alarm actions input type.")
6969
return

src/semantics/__init__.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class TDInputBuilder(object):
1414
# Rules for 'free-text' fields
1515
__value_rules = []
1616

17-
# Rules for fields with 'option' constraints
18-
__option_rules = []
17+
# Rules for fields with 'oneof' constraints
18+
__oneof_rules = []
1919

2020
def add_value_rule(self, domain, type, value):
2121
"""
@@ -48,19 +48,19 @@ def add_value_rule(self, domain, type, value):
4848
"""
4949
self.__value_rules.append((domain, type, value))
5050

51-
def add_option_rule(self, domain, type):
51+
def add_oneof_rule(self, domain, type):
5252
"""
53-
Adds an rule how to process fields with 'options' constraints.
53+
Adds an rule how to process fields with 'oneOf' constraints.
5454
5555
Example:
5656
ib = TDInputBuilder()
57-
ib.add_option_rule('http://someont.de/#Color', 'http://someont.de/#Red')
57+
ib.add_oneof_rule('http://someont.de/#Color', 'http://someont.de/#Red')
5858
input_params = ib.build(some_action)
5959
6060
This sets the value of the field with the following type description to "#ff0000"
6161
{
6262
"type": "string",
63-
"options": [
63+
"oneOf": [
6464
{
6565
"value": "#0000ff",
6666
"dbo:Colour": "dbr:Blue"
@@ -78,7 +78,7 @@ def add_option_rule(self, domain, type):
7878
@type type str
7979
@param type Full IRI of the fields value type.
8080
"""
81-
self.__option_rules.append((domain, type))
81+
self.__oneof_rules.append((domain, type))
8282

8383
def __dispatch_value_field(self, ns_repo, key, value, datatype):
8484
"""
@@ -97,19 +97,19 @@ def __dispatch_value_field(self, ns_repo, key, value, datatype):
9797
return rule_value
9898
return None
9999

100-
def __dispatch_options_field(self, ns_repo, options):
100+
def __dispatch_oneof_field(self, ns_repo, options):
101101
"""
102-
Determines the value of a 'options' constrained field using the rules given.
102+
Determines the value of a 'oneOf' constrained field using the rules given.
103103
@return Returns the value imposed by an applicable rule or None if no rule was applicable.
104104
"""
105105
for option in options:
106106
for key, value in option.items():
107-
if key != 'value':
108-
for rule_domain, rule_type in self.__option_rules:
107+
if key != 'constant':
108+
for rule_domain, rule_type in self.__oneof_rules:
109109
domain = ns_repo.resolve(key)
110110
type = ns_repo.resolve(value)
111111
if sparql.classes_equivalent(domain, rule_domain) and sparql.classes_equivalent(type, rule_type):
112-
return option['value']
112+
return option['constant']
113113
return None
114114

115115
def __dispatch_type_description(self, ns_repo, it):
@@ -121,12 +121,12 @@ def __dispatch_type_description(self, ns_repo, it):
121121
"""
122122
if it['type'] != 'object':
123123
for key, value in it.items():
124-
if key == 'options':
125-
v = self.__dispatch_options_field(ns_repo, it['options'])
124+
if key == 'oneOf':
125+
v = self.__dispatch_oneof_field(ns_repo, it['oneOf'])
126126
if v:
127127
return v
128128
else:
129-
raise UnknownSemanticsException('The semantics of none of the options could be determined.')
129+
raise UnknownSemanticsException('The semantics of none of the oneOf options could be determined.')
130130

131131
elif isinstance(key, str) and isinstance(value, str):
132132
v = self.__dispatch_value_field(ns_repo, key, value, it['type'])

0 commit comments

Comments
 (0)