-
Notifications
You must be signed in to change notification settings - Fork 0
/
narcBuilder.py
139 lines (124 loc) · 6.27 KB
/
narcBuilder.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
Neural Cognitive Architecture Builder
Builder service to build the Neural Coginitive Architecture.
"""
from generators.sequentialRuleGenerator import SequentialRuleGenerator
from repositories.activationsRepository import ActivationsRepository
from repositories.assertionRepository import AssertionRepository
from repositories.connectionsRepository import ConnectionsRepository
from repositories.factGroupRepository import FactGroupRepository
from repositories.factRepository import FactRepository
from repositories.internRepository import InternRepository
from repositories.linkRepository import LinkRepository
from repositories.neuronRepository import NeuronRepository
from repositories.primeRepository import PrimeRepository
from repositories.rulesRepository import RulesRepository
from services.associationService import AssociationService
from services.baseService import BaseService
from services.connectionsService import ConnectionsService
from services.internService import InternService
from services.loggerService import LoggerService
from services.propertyService import PropertyService
from services.relationshipService import RelationshipService
from services.rulesService import RulesService
from lib.make3Assoc import NeuralThreeAssocClass
from executorBuilder import ExecutorBuilder
from narc import NeuralCognitiveArchitecture
class NeuralCognitiveArchitectureBuilder:
def __init__(self, simulator, sim, fsa, neal, spinnakerVersion = -1, debug = False):
if(simulator not in ["nest", "spinnaker"]):
raise Exception("simulator type: '{}' is invalid. Use one of the following: nest, spinnaker.".format(simulator))
self.__sim = sim
self.__fsa = fsa
self.__neal = neal
self.__simulator = simulator
self.__debug = debug
self.__spinnakerVersion = spinnakerVersion
self.__basesFile = None
self.__propertiesFile = None
self.__relationshipsFile = None
self.__associationsFile = None
self.__topology = None
self.__baseService = None
self.__propertyService = None
self.__relationshipService = None
self.__generatorType = None
self.__generator = None
def useBasesFile(self, basesFile):
self.__basesFile = basesFile
return self
def useRelationshipsFiles(self, propertiesFile, relationshipsFile, associationsFile):
self.__propertiesFile = propertiesFile
self.__relationshipsFile = relationshipsFile
self.__associationsFile = associationsFile
return self
def build(self):
self.__initDependencies()
generator = self.__getGenerator()
exe = self.__buildExe()
return NeuralCognitiveArchitecture(exe,
self.__rulesService,
self.__rulesRepository,
self.__neuronRepository,
self.__internRepository,
self.__factGroupRepository,
self.__factRepository,
self.__assertionRepository,
self.__primeRepository,
self.__linkRepository,
generator,
self.__topology,
self.__baseService,
self.__propertyService,
self.__relationshipService,
self.__connectionsService)
def __initDependencies(self):
if(self.__basesFile):
self.__topology = NeuralThreeAssocClass(self.__simulator, self.__sim, self.__neal, self.__spinnakerVersion, self.__fsa)
self.__baseService = BaseService(self.__fsa, self.__basesFile)
self.__topology.createBaseNet(self.__baseService.getInheritance())
if(self.__propertiesFile and self.__relationshipsFile and self.__associationsFile):
self.__propertyService = PropertyService(self.__fsa, self.__propertiesFile)
self.__relationshipService = RelationshipService(self.__fsa, self.__relationshipsFile)
self.__associationService = AssociationService(self.__associationsFile)
self.__topology.createAssociationTopology(self.__propertyService.getStructure(), self.__relationshipService.getStructure())
self.__topology.addAssociations(self.__associationService.getAssociations())
self.__logger = LoggerService(self.__debug)
self.__connectionsRepository = ConnectionsRepository()
self.__neuronRepository = NeuronRepository()
self.__internRepository = InternRepository()
self.__internService = InternService(self.__neuronRepository, self.__internRepository)
self.__connectionsService = ConnectionsService(self.__connectionsRepository, self.__internService)
self.__linkRepository = LinkRepository(self.__neuronRepository, self.__connectionsService, self.__baseService, self.__propertyService, self.__relationshipService)
self.__factGroupRepository = FactGroupRepository()
self.__activationsRepository = ActivationsRepository()
self.__factRepository = FactRepository(self.__factGroupRepository, self.__neuronRepository, self.__activationsRepository)
self.__primeRepository = PrimeRepository(self.__neuronRepository, self.__connectionsService, self.__baseService, self.__propertyService, self.__relationshipService)
self.__assertionRepository = AssertionRepository(self.__neuronRepository)
self.__rulesRepository = RulesRepository()
self.__rulesService = RulesService(self.__rulesRepository,
self.__primeRepository,
self.__linkRepository,
self.__factGroupRepository,
self.__factRepository,
self.__assertionRepository,
self.__connectionsService,
self.__baseService,
self.__propertyService,
self.__relationshipService,
self.__logger)
def __buildExe(self):
exeBuilder = ExecutorBuilder(self.__sim,
self.__simulator,
self.__spinnakerVersion,
self.__fsa,
self.__neal,
self.__neuronRepository,
self.__connectionsRepository,
self.__activationsRepository,
self.__logger)
if(self.__topology):
exeBuilder.useAssociationTopology(self.__topology)
return exeBuilder.build()
def __getGenerator(self):
return SequentialRuleGenerator(self.__connectionsService, self.__internService)