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

Commit

Permalink
Full doc added
Browse files Browse the repository at this point in the history
  • Loading branch information
Tambup committed Jan 12, 2021
1 parent 86d83b9 commit 9e987b9
Show file tree
Hide file tree
Showing 41 changed files with 1,152 additions and 103 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.vscode/
/.mypy_cache/
/doc/build/
process-palette.json
*.pyc
71 changes: 71 additions & 0 deletions FSM_algorithm/Closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@


class Closure(RegexOperation):
"""
This class represent a closure.
:param enter_state_index: The index, relative to state_space,
of the enter state of the closure
:type enter_state_index: int
:param state_space: The list of space states
:type state_space: list
:param name: The symbolic name that the closure will assume
:type name: str
"""
final_state = DNSpaceState(SpaceState(states=['', ''], links=[]))

def __init__(self, enter_state_index, state_space, name):
"""
Constructor method.
"""
super().__init__()
self._name = name
self._init_index = enter_state_index
Expand All @@ -20,19 +34,55 @@ def __init__(self, enter_state_index, state_space, name):

@property
def name(self):
"""
Returns the symbolic name of the closure.
:return: The symbolyc name of the closure
:rtype: str
"""
return self._name

@property
def regex(self):
"""
Returns the decoration (that is a regex) of the closure.
:return: The decoration of the closure.
:rtype: str
"""
return self._regex

def is_final(self):
"""
Check if the current closure is final or not.
:return: True if and only if the closure contains final states
:rtype: bool
"""
return True if self._final_states else False

def in_space_state(self):
"""
Build the
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
relative to the initial state of the closure.
:return: The initial
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
:rtype:
:class:`~FSM_algorithm.DetachedNextsSpaceState.DetachedNextsSpaceState`
"""
return DNSpaceState(self._init_space[self._init_index])

def build(self):
"""
Build the closure.
Building means:
- Compute the decoration of all the final states;
- Compute the decoration of all the exit states;
"""
init_st = DNSpaceState(space_state=SpaceState(states=[''], links=[]),
is_closure_init=True)
init_st.set_link(SpaceState.NULL_EVT, '!'+SpaceState.NULL_EVT)
Expand Down Expand Up @@ -146,6 +196,12 @@ def _new_generic_trans_given_relevance(self, relevance, nk=None):
subscr=nk)

def build_next(self, closures):
"""
Build the list of adjacent closure, each one with its decoration.
:param closures: The list of closures of the network
:type closures: list
"""
self._out = {}
for state in self._exit_states.keys():
for trns in state.external_nexts.keys():
Expand All @@ -166,9 +222,24 @@ def build_next(self, closures):
break

def out_list(self, observation):
"""
Returns the list of adjacent closure, each one with its decoration,
associated to an observation.
:param observation: The observation
:type observation: str
:return: A list of the adjacent closure with decoration
:rtype: list
"""
return self._out.get(observation, [])

def dict_per_json(self):
"""
Returns the object's attributes in a form easy to transform in json.
:return: All the necessary information in a data structure
:rtype: dict
"""
temp = {}
temp['name'] = self._name
temp['in_state_id'] = self.in_space_state().id
Expand Down
21 changes: 21 additions & 0 deletions FSM_algorithm/ComportamentalFANSObservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@


class ComportamentalFANSObservation(ComportamentalFANSpace):
"""
The class rapresent a comportamental finite automa network space
relative to an observation.
From now comportamental finite automa network space relative to an
observation are identified as CFANSO or CFANSObservation.
:param compFAN: The comportamental FA network
:type compFAN: :class:`~FSM_algorithm.core.ComportamentalFANetwork`
"""
def __init__(self, compFAN):
"""
Constructor method.
"""
super().__init__(compFAN)
self._observation = None
self._id_count = None

def build(self, observation):
"""
Build a CFANS observation pruning states that cannot
reach a final state.
:param observation: The list of observations on the
:class:`~FSM_algorithm.core.ComportamentalFANetwork`
:type observation: list
"""
self._observation = observation
print('\nStart creation CFANS on observation ' +
str(observation) + '\n')
Expand Down
47 changes: 31 additions & 16 deletions FSM_algorithm/ComportamentalFANSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,43 @@ class ComportamentalFANSpace(Task):
From now comportamental finite automa network space are identified
as CFANS.
"""
:param compFAN: The comportamental FA network
:type compFAN: :class:`~FSM_algorithm.core.ComportamentalFANetwork`
"""
def __init__(self, compFAN):
"""
Constructor method.
"""
super().__init__(compFAN)
self._space_states = []

@property
def space_states(self):
"""
Returns all the :class:`~FSM_algorithm.SpaceState.SpaceState`
of the current Comportamental FAN Space.
:return: The list of :class:`~FSM_algorithm.SpaceState.SpaceState`
:rtype: list
"""
return self._space_states

def is_correct(self):
"""
Check if the Compotamental FAN Space is corret or not.
:return: True if is correct, else false
:rtype: bool
"""
return True if self._space_states else False

def build(self, param=None):
"""Build a CFANS pruning states that cannot reach a final state.
"""
Build a CFANS pruning states that cannot reach a final state.
Parameters
----------
param : list, optional
In this class is useless. Don't use it. By default None
:param param: In this class is useless. Don't use it, defaults to None
:type param: list, optional
"""
print('Start creation CFANS\n')
self._initialize()
Expand All @@ -46,12 +63,11 @@ def build(self, param=None):
print('\nCFANS complete')

def build_no_prune(self, param=None):
"""Build a CFANS without pruning.
"""
Build a CFANS without pruning.
Parameters
----------
param : list, optional
In this class is useless. Don't use it. By default None
:param param: In this class is useless. Don't use it, defaults to None
:type param: list, optional
"""
self._initialize()

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

def dict_per_json(self):
"""Build a dict from the object.
"""
Returns the object's attributes in a form easy to transform in json.
Returns
-------
dict
Return a dict that describe the CFANS.
:return: All the necessary information in a data structure
:rtype: dict
"""
num_trans = 0
for space_state in self._space_states:
Expand Down
40 changes: 40 additions & 0 deletions FSM_algorithm/DetachedNextsSpaceState.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@


class DetachedNextsSpaceState(SpaceState):
"""
This class represent a Space State of the state
:class:`~FSM_algorithm.ComportamentalFANSpace.ComportamentalFANSpace`.
This can be seen as a vertex of a oriented graph, where the graph is
represented by
:class:`~FSM_algorithm.ComportamentalFANSpace.ComportamentalFANSpace`.
:param space_state: The Space State from from which is derived
:type space_state: :class:`~FSM_algorithm.SpaceState.SpaceState`
:param is_closure_init: If, inside a closure, this is the init state
:type is_closure_init: bool, optional
"""
def __init__(self, space_state, is_closure_init=False):
"""
Constructor method.
"""
super().__init__(links=[], states=space_state.states)
self._links = space_state.links
self._id = space_state.id
Expand All @@ -12,6 +28,14 @@ def __init__(self, space_state, is_closure_init=False):

@property
def external_nexts(self):
"""
Contains the list of all the pair transition-successor
that exit the :class:`~FSM_algorithm.Closure` which the current
DetachedNextsSpaceState belongs to.
:return: All the pair transition-successor exiting the current Closure
:rtype: dict
"""
return self._external_nexts

@property
Expand All @@ -31,11 +55,27 @@ def is_closure_init(self):
return self._is_closure_init

def to_decorate(self):
"""
Declare if the current DetachedNextsSpaceState must
to be decorated or not.
:return: True if the current DetachedNextsSpaceState must
be decorated, else False
:rtype: bool
"""
if super().is_final():
return True
if self._external_nexts:
return True
return False

def exit_state(self):
"""
Declare if the current DetachedNextsSpaceState has transitions
exiting the current :class:`~FSM_algorithm.Closure`.
:return: True if the current DetachedNextsSpaceState has transitions
exiting the current :class:`~FSM_algorithm.Closure`, else False
:rtype: bool
"""
return True if self._external_nexts else False
31 changes: 31 additions & 0 deletions FSM_algorithm/Diagnosis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@


class Diagnosis(RegexOperation):
"""
This class, using :py:meth:`diagnosis()` compute the regex from a
list of :class:`~FSM_algorithm.LOSpaceState` computed with
:class:`~FSM_algorithm.ComportamentalFANSObservation`.
:param space_states: The list of :class:`~FSM_algorithm.LOSpaceState`
:type space_states: list
:param observation: The list of observations on the
:class:`~FSM_algorithm.core.ComportamentalFANetwork`
:type observation: list
"""
final_trans = OutTransition(name='',
destination='FINAL',
links=[],
Expand All @@ -14,16 +25,30 @@ class Diagnosis(RegexOperation):
final_state = LOSpaceState(states=[], links=[])

def __init__(self, space_states, observation):
"""
Constructor method.
"""
super().__init__()
self._space_states = space_states
self._regex = ''
self._observation = observation

@property
def regex(self):
"""
Describe the regex computed with :py:meth:`diagnosis()`.
:return: The computed regex
:rtype: str
"""
return self._regex

def diagnosis(self):
"""
Compute the regex relative to an observation on a
list of :class:`~FSM_algorithm.LOSpaceState` computed with
:class:`~FSM_algorithm.ComportamentalFANSObservation`.
"""
print('Start computing diagnosis')
self._unify_exit()
while len([tr for space in self._work_space.keys()
Expand Down Expand Up @@ -64,6 +89,12 @@ def _new_generic_trans_given_relevance(self, relevance, nk=None):
relevant=relevance)

def dict_per_json(self):
"""
Returns the object's attributes in a form easy to transform in json.
:return: All the necessary information in a data structure
:rtype: dict
"""
return {
'observation': self._observation,
'number space states': len(self._space_states),
Expand Down
Loading

0 comments on commit 9e987b9

Please sign in to comment.