Esempio n. 1
0
	def translateAction(self, ruleConsequent, getDict = False):
		checkData(locals())

		actions = Actions()
		action, originalTemplate, parameterValues = self.getActionAndTemplateAndParameterValues(ruleConsequent)
		translationTemplate = actions.translateTemplate('Z3', originalTemplate)

		translatedParams = {}

		for key,value in parameterValues.iteritems():
			translatedParams[key] = self.__translateParameters(action.category, value)


		translation = translationTemplate

		for i in range(0,len(parameterValues.keys())):

			value = translatedParams[str(i)]
			translation = translation.replace("@val", value, 1)

		if not getDict:
			return translation, action, translatedParams
		else:
			result = {}
			result["translation"] = translation
			result["action"] = action.getDict()
			result["translatedParams"] = translatedParams
			return result
Esempio n. 2
0
	def getActionAndTemplateAndParameterValues(self, ruleConsequent):
		checkData(locals())

		actions = Actions()
		actionList = actions.getAllActions()

		for action in actionList:
			
			# A action.ruleConsequent is represented as set of templates models:
			# Example "template1 | template2 | template2"

			models = action.ruleConsequent.split('|')

			for model in models:
				parameterNumber = model.count("@val")
				originalModel = model.strip()
				model = model.replace("@val","(.+)").strip()

				matchObj = re.match( model, ruleConsequent, re.M|re.I)

				if matchObj:
					parameterValues = {}

					for i in range(0,parameterNumber):
						parameterValues[str(i)] = matchObj.group(i + 1)

					return (action, originalModel, parameterValues)

		raise NotWellFormedRuleError("Impossible to find any action corresponding to the following rule consequent > " + ruleConsequent)
Esempio n. 3
0
	def getActions(self, buildingName = None, groupId = None):
		checkData(locals())

		from app.backend.model.actions import Actions
		actions = Actions()

		actionList = []
		for action in actions.getAllActions():
			actionList.append(action.getDict())

		return {"actions" : actionList}
Esempio n. 4
0
	def getActionCategories(self):
		checkData(locals())

		
		actions = Actions()
		actionList = actions.getAllActions()

		categories = []
		for action in actionList:
			if action.category not in categories:
				categories.append(action.category)

		return categories