Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Commit 9e987b9

Browse files
author
Tambup
committed
Full doc added
1 parent 86d83b9 commit 9e987b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1152
-103
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/.vscode/
22
/.mypy_cache/
3+
/doc/build/
4+
process-palette.json
35
*.pyc

FSM_algorithm/Closure.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@
55

66

77
class Closure(RegexOperation):
8+
"""
9+
This class represent a closure.
10+
11+
:param enter_state_index: The index, relative to state_space,
12+
of the enter state of the closure
13+
:type enter_state_index: int
14+
:param state_space: The list of space states
15+
:type state_space: list
16+
:param name: The symbolic name that the closure will assume
17+
:type name: str
18+
"""
819
final_state = DNSpaceState(SpaceState(states=['', ''], links=[]))
920

1021
def __init__(self, enter_state_index, state_space, name):
22+
"""
23+
Constructor method.
24+
"""
1125
super().__init__()
1226
self._name = name
1327
self._init_index = enter_state_index
@@ -20,19 +34,55 @@ def __init__(self, enter_state_index, state_space, name):
2034

2135
@property
2236
def name(self):
37+
"""
38+
Returns the symbolic name of the closure.
39+
40+
:return: The symbolyc name of the closure
41+
:rtype: str
42+
"""
2343
return self._name
2444

2545
@property
2646
def regex(self):
47+
"""
48+
Returns the decoration (that is a regex) of the closure.
49+
50+
:return: The decoration of the closure.
51+
:rtype: str
52+
"""
2753
return self._regex
2854

2955
def is_final(self):
56+
"""
57+
Check if the current closure is final or not.
58+
59+
:return: True if and only if the closure contains final states
60+
:rtype: bool
61+
"""
3062
return True if self._final_states else False
3163

3264
def in_space_state(self):
65+
"""
66+
Build the
67+
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
68+
relative to the initial state of the closure.
69+
70+
:return: The initial
71+
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
72+
:rtype:
73+
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
74+
"""
3375
return DNSpaceState(self._init_space[self._init_index])
3476

3577
def build(self):
78+
"""
79+
Build the closure.
80+
81+
Building means:
82+
83+
- Compute the decoration of all the final states;
84+
- Compute the decoration of all the exit states;
85+
"""
3686
init_st = DNSpaceState(space_state=SpaceState(states=[''], links=[]),
3787
is_closure_init=True)
3888
init_st.set_link(SpaceState.NULL_EVT, '!'+SpaceState.NULL_EVT)
@@ -146,6 +196,12 @@ def _new_generic_trans_given_relevance(self, relevance, nk=None):
146196
subscr=nk)
147197

148198
def build_next(self, closures):
199+
"""
200+
Build the list of adjacent closure, each one with its decoration.
201+
202+
:param closures: The list of closures of the network
203+
:type closures: list
204+
"""
149205
self._out = {}
150206
for state in self._exit_states.keys():
151207
for trns in state.external_nexts.keys():
@@ -166,9 +222,24 @@ def build_next(self, closures):
166222
break
167223

168224
def out_list(self, observation):
225+
"""
226+
Returns the list of adjacent closure, each one with its decoration,
227+
associated to an observation.
228+
229+
:param observation: The observation
230+
:type observation: str
231+
:return: A list of the adjacent closure with decoration
232+
:rtype: list
233+
"""
169234
return self._out.get(observation, [])
170235

171236
def dict_per_json(self):
237+
"""
238+
Returns the object's attributes in a form easy to transform in json.
239+
240+
:return: All the necessary information in a data structure
241+
:rtype: dict
242+
"""
172243
temp = {}
173244
temp['name'] = self._name
174245
temp['in_state_id'] = self.in_space_state().id

FSM_algorithm/ComportamentalFANSObservation.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,33 @@
44

55

66
class ComportamentalFANSObservation(ComportamentalFANSpace):
7+
"""
8+
The class rapresent a comportamental finite automa network space
9+
relative to an observation.
10+
11+
From now comportamental finite automa network space relative to an
12+
observation are identified as CFANSO or CFANSObservation.
13+
14+
:param compFAN: The comportamental FA network
15+
:type compFAN: :class:`~FSM_algorithm.core.ComportamentalFANetwork`
16+
"""
717
def __init__(self, compFAN):
18+
"""
19+
Constructor method.
20+
"""
821
super().__init__(compFAN)
922
self._observation = None
1023
self._id_count = None
1124

1225
def build(self, observation):
26+
"""
27+
Build a CFANS observation pruning states that cannot
28+
reach a final state.
29+
30+
:param observation: The list of observations on the
31+
:class:`~FSM_algorithm.core.ComportamentalFANetwork`
32+
:type observation: list
33+
"""
1334
self._observation = observation
1435
print('\nStart creation CFANS on observation ' +
1536
str(observation) + '\n')

FSM_algorithm/ComportamentalFANSpace.py

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,43 @@ class ComportamentalFANSpace(Task):
1010
1111
From now comportamental finite automa network space are identified
1212
as CFANS.
13-
"""
1413
14+
:param compFAN: The comportamental FA network
15+
:type compFAN: :class:`~FSM_algorithm.core.ComportamentalFANetwork`
16+
"""
1517
def __init__(self, compFAN):
18+
"""
19+
Constructor method.
20+
"""
1621
super().__init__(compFAN)
1722
self._space_states = []
1823

1924
@property
2025
def space_states(self):
26+
"""
27+
Returns all the :class:`~FSM_algorithm.SpaceState.SpaceState`
28+
of the current Comportamental FAN Space.
29+
30+
:return: The list of :class:`~FSM_algorithm.SpaceState.SpaceState`
31+
:rtype: list
32+
"""
2133
return self._space_states
2234

2335
def is_correct(self):
36+
"""
37+
Check if the Compotamental FAN Space is corret or not.
38+
39+
:return: True if is correct, else false
40+
:rtype: bool
41+
"""
2442
return True if self._space_states else False
2543

2644
def build(self, param=None):
27-
"""Build a CFANS pruning states that cannot reach a final state.
45+
"""
46+
Build a CFANS pruning states that cannot reach a final state.
2847
29-
Parameters
30-
----------
31-
param : list, optional
32-
In this class is useless. Don't use it. By default None
48+
:param param: In this class is useless. Don't use it, defaults to None
49+
:type param: list, optional
3350
"""
3451
print('Start creation CFANS\n')
3552
self._initialize()
@@ -46,12 +63,11 @@ def build(self, param=None):
4663
print('\nCFANS complete')
4764

4865
def build_no_prune(self, param=None):
49-
"""Build a CFANS without pruning.
66+
"""
67+
Build a CFANS without pruning.
5068
51-
Parameters
52-
----------
53-
param : list, optional
54-
In this class is useless. Don't use it. By default None
69+
:param param: In this class is useless. Don't use it, defaults to None
70+
:type param: list, optional
5571
"""
5672
self._initialize()
5773

@@ -151,12 +167,11 @@ def _prune_recursion(self, state, forbidden, mantain_list, remove_list):
151167
return True
152168

153169
def dict_per_json(self):
154-
"""Build a dict from the object.
170+
"""
171+
Returns the object's attributes in a form easy to transform in json.
155172
156-
Returns
157-
-------
158-
dict
159-
Return a dict that describe the CFANS.
173+
:return: All the necessary information in a data structure
174+
:rtype: dict
160175
"""
161176
num_trans = 0
162177
for space_state in self._space_states:

FSM_algorithm/DetachedNextsSpaceState.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22

33

44
class DetachedNextsSpaceState(SpaceState):
5+
"""
6+
This class represent a Space State of the state
7+
:class:`~FSM_algorithm.ComportamentalFANSpace.ComportamentalFANSpace`.
8+
9+
This can be seen as a vertex of a oriented graph, where the graph is
10+
represented by
11+
:class:`~FSM_algorithm.ComportamentalFANSpace.ComportamentalFANSpace`.
12+
13+
:param space_state: The Space State from from which is derived
14+
:type space_state: :class:`~FSM_algorithm.SpaceState.SpaceState`
15+
:param is_closure_init: If, inside a closure, this is the init state
16+
:type is_closure_init: bool, optional
17+
"""
518
def __init__(self, space_state, is_closure_init=False):
19+
"""
20+
Constructor method.
21+
"""
622
super().__init__(links=[], states=space_state.states)
723
self._links = space_state.links
824
self._id = space_state.id
@@ -12,6 +28,14 @@ def __init__(self, space_state, is_closure_init=False):
1228

1329
@property
1430
def external_nexts(self):
31+
"""
32+
Contains the list of all the pair transition-successor
33+
that exit the :class:`~FSM_algorithm.Closure` which the current
34+
DetachedNextsSpaceState belongs to.
35+
36+
:return: All the pair transition-successor exiting the current Closure
37+
:rtype: dict
38+
"""
1539
return self._external_nexts
1640

1741
@property
@@ -31,11 +55,27 @@ def is_closure_init(self):
3155
return self._is_closure_init
3256

3357
def to_decorate(self):
58+
"""
59+
Declare if the current DetachedNextsSpaceState must
60+
to be decorated or not.
61+
62+
:return: True if the current DetachedNextsSpaceState must
63+
be decorated, else False
64+
:rtype: bool
65+
"""
3466
if super().is_final():
3567
return True
3668
if self._external_nexts:
3769
return True
3870
return False
3971

4072
def exit_state(self):
73+
"""
74+
Declare if the current DetachedNextsSpaceState has transitions
75+
exiting the current :class:`~FSM_algorithm.Closure`.
76+
77+
:return: True if the current DetachedNextsSpaceState has transitions
78+
exiting the current :class:`~FSM_algorithm.Closure`, else False
79+
:rtype: bool
80+
"""
4181
return True if self._external_nexts else False

FSM_algorithm/Diagnosis.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66

77
class Diagnosis(RegexOperation):
8+
"""
9+
This class, using :py:meth:`diagnosis()` compute the regex from a
10+
list of :class:`~FSM_algorithm.LOSpaceState` computed with
11+
:class:`~FSM_algorithm.ComportamentalFANSObservation`.
12+
13+
:param space_states: The list of :class:`~FSM_algorithm.LOSpaceState`
14+
:type space_states: list
15+
:param observation: The list of observations on the
16+
:class:`~FSM_algorithm.core.ComportamentalFANetwork`
17+
:type observation: list
18+
"""
819
final_trans = OutTransition(name='',
920
destination='FINAL',
1021
links=[],
@@ -14,16 +25,30 @@ class Diagnosis(RegexOperation):
1425
final_state = LOSpaceState(states=[], links=[])
1526

1627
def __init__(self, space_states, observation):
28+
"""
29+
Constructor method.
30+
"""
1731
super().__init__()
1832
self._space_states = space_states
1933
self._regex = ''
2034
self._observation = observation
2135

2236
@property
2337
def regex(self):
38+
"""
39+
Describe the regex computed with :py:meth:`diagnosis()`.
40+
41+
:return: The computed regex
42+
:rtype: str
43+
"""
2444
return self._regex
2545

2646
def diagnosis(self):
47+
"""
48+
Compute the regex relative to an observation on a
49+
list of :class:`~FSM_algorithm.LOSpaceState` computed with
50+
:class:`~FSM_algorithm.ComportamentalFANSObservation`.
51+
"""
2752
print('Start computing diagnosis')
2853
self._unify_exit()
2954
while len([tr for space in self._work_space.keys()
@@ -64,6 +89,12 @@ def _new_generic_trans_given_relevance(self, relevance, nk=None):
6489
relevant=relevance)
6590

6691
def dict_per_json(self):
92+
"""
93+
Returns the object's attributes in a form easy to transform in json.
94+
95+
:return: All the necessary information in a data structure
96+
:rtype: dict
97+
"""
6798
return {
6899
'observation': self._observation,
69100
'number space states': len(self._space_states),

0 commit comments

Comments
 (0)