17
17
API of a Pyke.knowlege_base, so that we can list its case-specific facts, as
18
18
used in :meth:`iris.fileformats.netcdf._actions_activation_stats`.
19
19
20
+ TODO: get rid of redundact fact-database identifier arguments.
21
+
20
22
"""
21
23
from .actions import run_actions
22
24
23
25
24
- class FactList :
25
- def __init__ (self ):
26
- self .case_specific_facts = []
27
-
28
-
29
26
class FactEntity :
30
- # To support:
31
27
"""
32
- kb_facts = engine.get_kb(_PYKE_FACT_BASE)
28
+ An object with property 'entity_lists', which is a dictionary of 'FactList's.
33
29
34
- for key in kb_facts.entity_lists.keys():
35
- for arg in kb_facts.entity_lists[key].case_specific_facts:
36
- print("\t %s%s" % (key, arg))
30
+ A Factlist, in turn, is an object with property 'case_specific_facts',
31
+ which is a list of tuples of strings
32
+ (each of which is a 'fact' of the named class).
33
+
34
+ To support the debug code :
35
+ kb_facts = engine.get_kb(_PYKE_FACT_BASE)
36
+ for key in kb_facts.entity_lists.keys():
37
+ for arg in kb_facts.entity_lists[key].case_specific_facts:
38
+ print("\t %s%s" % (key, arg))
37
39
38
40
"""
39
41
40
42
def __init__ (self ):
41
43
self .entity_lists = {}
42
44
45
+ class _FactList :
46
+ # Just "an object with a 'case_specific_facts' property" (which is a list).
47
+ def __init__ (self ):
48
+ self .case_specific_facts = []
49
+
43
50
def add_fact (self , fact_name , args ):
51
+ # Add a fact "fact_name(*args)".
44
52
if fact_name not in self .entity_lists :
45
- self .entity_lists [fact_name ] = FactList ()
53
+ self .entity_lists [fact_name ] = self . _FactList ()
46
54
fact_list = self .entity_lists [fact_name ]
47
55
fact_list .case_specific_facts .append (tuple (args ))
48
56
49
- def sect_facts (self , entity_name ):
50
- if entity_name in self .entity_lists :
51
- facts = self .entity_lists .get (entity_name ).case_specific_facts
57
+ def sect_facts (self , fact_name ):
58
+ # Lookup all facts "fact_name(*args)" for a given fact_name.
59
+ if fact_name in self .entity_lists :
60
+ facts = self .entity_lists .get (fact_name ).case_specific_facts
52
61
else :
53
62
facts = []
54
63
return facts
@@ -61,6 +70,11 @@ class Engine:
61
70
Provides just enough API so that the existing code in
62
71
:mod:`iris.fileformats.netcdf` can interface with our new rules functions.
63
72
73
+ A list of possible fact-arglists is store, for each of a set of fact-names
74
+ (which are strings).
75
+ Each fact-argslist is represented by a tuple of values
76
+ -- at present, in practice, those are all strings too.
77
+
64
78
"""
65
79
66
80
def __init__ (self ):
@@ -79,7 +93,7 @@ def activate(self):
79
93
set by engine.cf_var (the variable name).
80
94
81
95
The rules operation itself is coded elsewhere,
82
- in :mod:`iris.fileformats.netcdf._nc_load_rules.rules `.
96
+ in :mod:`iris.fileformats.netcdf._nc_load_rules.actions `.
83
97
84
98
"""
85
99
run_actions (self )
@@ -98,6 +112,8 @@ def add_case_specific_fact(self, fact_name, fact_arglist):
98
112
99
113
Roughly, self.facts.entity_lists[fact_name].append(fact_arglist).
100
114
115
+ NOTE: 'kb_name' is no longer used.
116
+
101
117
"""
102
118
self .facts .add_fact (fact_name , fact_arglist )
103
119
0 commit comments