Coverage for src/SymbSyntDec/ground.py: 60%

1

2 from functools import singledispatch

3

4 from pylogics_modalities.syntax.base import (

5 And as PLTLAnd,

6 Or as PLTLOr,

7 Formula,

8 Not as PLTLNot,

9 _UnaryOp

10)

11 from pylogics_modalities.syntax.pltl import (

12 Atomic as PLTLAtomic,

13 Before,

14 WeakBefore,

15 PropositionalFalse,

16 PropositionalTrue

17)

18

19

20 State_var = {}

21

22

23 def ground(formula: object, state_var: dict) -> Formula:

24 global State_var

25 State_var = state_var

26 return ground_operands(formula)

27

28

29 def ground_operands_unaryop(formula: _UnaryOp):

30 return ground_operands(formula.argument)

31

32

33@ singledispatch

34 def ground_operands(formula: object) -> Formula:

35 raise NotImplementedError(

36 f"Ground not implemented for object of type {type(formula)}"

37 )

38

39

40@ground_operands.register

41 def ground_operands_prop_true(formula: PropositionalTrue) -> Formula:

42 return formula

43

44

45@ground_operands.register

46 def ground_operands_prop_false(formula: PropositionalFalse) -> Formula:

47 return formula

48

49

50@ground_operands.register

51 def ground_operands_atomic(formula: PLTLAtomic) -> Formula:

52 return formula

53

54

55@ground_operands.register

56 def ground_operands_and(formula: PLTLAnd) -> Formula:

57 sub = [ground_operands(f) for f in formula.operands]

58 return PLTLAnd(*sub)

59

60

61@ground_operands.register

62 def ground_operands_or(formula: PLTLOr) -> Formula:

63 sub = [ground_operands(f) for f in formula.operands]

64 return PLTLOr(*sub)

65

66

67@ground_operands.register

68 def ground_operands_not(formula: PLTLNot) -> Formula:

69 return PLTLNot(ground_operands_unaryop(formula))

70

71

72@ground_operands.register

73 def ground_operands_yesterday(formula: Before) -> Formula:

74 var = PLTLAtomic(State_var.get(formula))

75 return var

76

77

78@ground_operands.register

79 def ground_operands_weak_yesterday(formula: WeakBefore) -> Formula:

80 var = PLTLAtomic(State_var.get(formula))

81 return var