Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

 

PARENT_KEY = "key_parent" 

PARAMS_KEY = "key_params" 

DATA_KEY = "key_data" 

 

class ChainContext(object): 

""" 

Context holding a dict to store data and information durring the computation of the likelihood 

""" 

 

def __init__(self, parent, params): 

""" 

Constructor of the context 

""" 

 

self._data = dict() 

self.add(PARENT_KEY, parent) 

self.add(PARAMS_KEY, params) 

self.add(DATA_KEY, dict()) 

 

def add(self, key, value): 

""" 

Adds the value to the context using the key 

 

:param key: string 

key to use 

:param value: object 

the value to store 

 

""" 

self._data[key] = value 

 

def remove(self, key): 

""" 

Removes the value from the context 

 

:param key: string 

key to remove from the context 

""" 

assert key != None 

del(self._data[key]) 

 

def contains(self, key): 

""" 

Checks if the key is in the context 

 

:param key: string 

key to check 

 

:return: True if the key is in the context 

""" 

return key in self._data 

 

def get(self, key, default=None): 

""" 

Returns the value stored in the context at the key or the default value in the  

context doesn't contain the key 

 

:param key: string 

key to use 

:param default: string 

the default value to use if the key is not available 

""" 

if(self.contains(key)): 

return self._data[key] 

 

return default 

 

def getParams(self): 

""" 

Returns the currently processed parameters 

 

:return: The param of this context 

""" 

return self.get(PARAMS_KEY) 

 

def getParent(self): 

""" 

Returns the parent 

 

:return: The parent chain of this context 

""" 

return self.get(PARENT_KEY) 

 

def getData(self): 

""" 

Returns the data 

 

:return: The data of this context 

""" 

return self.get(DATA_KEY)