Skip to content

Commit 6c7a9da

Browse files
committed
Improved Engine usage docs.
1 parent 47f15b8 commit 6c7a9da

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

lib/iris/fileformats/_nc_load_rules/engine.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,47 @@
1717
API of a Pyke.knowlege_base, so that we can list its case-specific facts, as
1818
used in :meth:`iris.fileformats.netcdf._actions_activation_stats`.
1919
20+
TODO: get rid of redundact fact-database identifier arguments.
21+
2022
"""
2123
from .actions import run_actions
2224

2325

24-
class FactList:
25-
def __init__(self):
26-
self.case_specific_facts = []
27-
28-
2926
class FactEntity:
30-
# To support:
3127
"""
32-
kb_facts = engine.get_kb(_PYKE_FACT_BASE)
28+
An object with property 'entity_lists', which is a dictionary of 'FactList's.
3329
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))
3739
3840
"""
3941

4042
def __init__(self):
4143
self.entity_lists = {}
4244

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+
4350
def add_fact(self, fact_name, args):
51+
# Add a fact "fact_name(*args)".
4452
if fact_name not in self.entity_lists:
45-
self.entity_lists[fact_name] = FactList()
53+
self.entity_lists[fact_name] = self._FactList()
4654
fact_list = self.entity_lists[fact_name]
4755
fact_list.case_specific_facts.append(tuple(args))
4856

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
5261
else:
5362
facts = []
5463
return facts
@@ -61,6 +70,11 @@ class Engine:
6170
Provides just enough API so that the existing code in
6271
:mod:`iris.fileformats.netcdf` can interface with our new rules functions.
6372
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+
6478
"""
6579

6680
def __init__(self):
@@ -79,7 +93,7 @@ def activate(self):
7993
set by engine.cf_var (the variable name).
8094
8195
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`.
8397
8498
"""
8599
run_actions(self)
@@ -98,6 +112,8 @@ def add_case_specific_fact(self, fact_name, fact_arglist):
98112
99113
Roughly, self.facts.entity_lists[fact_name].append(fact_arglist).
100114
115+
NOTE: 'kb_name' is no longer used.
116+
101117
"""
102118
self.facts.add_fact(fact_name, fact_arglist)
103119

0 commit comments

Comments
 (0)