-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
111 lines (88 loc) · 3.75 KB
/
test.py
File metadata and controls
111 lines (88 loc) · 3.75 KB
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
import os
import unittest
from packaging import version
import itertools
from os.path import join as pjoin
from pathlib import Path
import pyirk as p
from ipydex import IPS, activate_ips_on_exception # noqa
if os.environ.get("IPYDEX_AIOE") == "true":
activate_ips_on_exception()
if not os.environ.get("PYIRK_DISABLE_CONSISTENCY_CHECKING", "").lower() == "true":
p.cc.enable_consistency_checking()
PACKAGE_ROOT_PATH = Path(__file__).parent.absolute().as_posix()
ag = p.irkloader.load_mod_from_path(pjoin(PACKAGE_ROOT_PATH, "agents1.py"), prefix="ag")
ma = p.irkloader.load_mod_from_path(pjoin(PACKAGE_ROOT_PATH, "math1.py"), prefix="ma", reuse_loaded=True)
ct = p.irkloader.load_mod_from_path(pjoin(PACKAGE_ROOT_PATH, "control_theory1.py"), prefix="ct", reuse_loaded=True)
ds = p.core.ds
theorems = [i for i in ds.items.values() if p.is_instance(i, p.I14["mathematical proposition"])]
systems = [i for i in ds.items.values() if p.is_instance(i, ct.I7641["general system model"])]
def cond_func(sys, rep, th):
# Note: most sys items here will be the systems created in the scope of a theorem. matching those doesnt make sense.
# they have to be filtered out first
# sys is from a setting scope:
if sys.get_relations("R20"):
if sys.get_relations("R20", return_obj=True)[0].R64 == "SETTING":
return False
scopes = th.get_inv_relations("R21",return_subj=True)
set, pre, ass = None, None, None
for scope in scopes:
match scope.R64:
case "SETTING":
set = scope
case "PREMISE":
pre = scope
case "ASSERTION":
ass = scope
if set is None:
return False
setting_items = set.get_inv_relations("R20", return_subj=True)
systh = [i for i in setting_items if isinstance(i, p.Item) and p.is_instance(i, ct.I7641["general system model"])]
if len(systh) != 1:
return False
systh = systh[0]
repth = [i for i in setting_items if isinstance(i, p.Item) and p.is_instance(i, ct.I2928["general model representation"])]
if len(repth) != 1:
return False
repth = repth[0]
cond = True
# for each statement regarding sys in theorem
for statement in sum(systh.get_relations().values(), []):
# take only the property relations for now
if "property" in statement.relation.R1:
rel_uri = statement.relation.uri
obj = statement.object
# make sure the systems has the same or more restrictive property as sys in th
# if relation does not exist -> False
cond = cond and (len(sys.get_relations(rel_uri)) > 0)
for stm in sys.get_relations(rel_uri):
if not p.is_subproperty(stm.object, obj):
cond = False
# same for rep
for statement in sum(repth.get_relations().values(), []):
if "property" in statement.relation.R1:
rel_uri = statement.relation.uri
obj = statement.object
cond = cond and (len(rep.get_relations(rel_uri)) > 0)
for stm in rep.get_relations(rel_uri):
if not p.is_subproperty(stm.object, obj):
cond = cond and False
return cond
res_list = []
for th, sys in itertools.product(theorems, systems):
rep = sys.get_relations("irk:/ocse/0.2/control_theory#R2928", return_obj=True)
if len(rep) == 1:
if cond_func(sys, rep[0], th):
res_list.append((sys, th))
elif len(rep) == 0:
continue
else:
raise IndexError
res = p.RuleResult()
for s, t in res_list:
# res.new_statements.append(t.set_relation(p.R80["applies to"], s))
# t.set_relation(p.R80["applies to"], s)
print(t, "applies to", s)
# for stm in res.new_statements:
# print(stm)
# IPS()