def _save_settings_values(self): """ Persists the settings values of the app to the settings module so it can be accesible from another part of the software. """ for key in dir(self._settings_module): if key.upper() == key: value = getattr(self._settings_module, key) if isinstance(value, str): value = encoding_flexible_conversion(value) setattr(settings, key, value)
def get_queries(self, question): """ Given `question` in natural language, it returns :type self: object three things: - the target of the query in string format - the query - metadata given by the regex programmer (defaults to None) The queries returned corresponds to the regexes that match in weight order. """ """ parse the question so that we split it if it hase "or" or "and" in it *( maybe on "," also at a later date) """ question = encoding_flexible_conversion(question) questions = question.split(" and ", (-1)) expr = Expression() first_time = True index = 0 #print questions toBeReturned = ReturnModel(None, None) for question in questions: for expression, userdata in self._iter_compiled_forms(question): if first_time: #print expression.rule_used toBeReturned.rule_used = expression.rule_used #print userdata """ -- it wont work for all the question or it will but we need more parrsing -- base on the type of the expression.rule_used we can take actions to connect the next expressions to the curent one if they are more """ if len(questions) > (index + 1): if expression.rule_used == "WhoAreChildrensOfQuestion": print "**************=Next query=**************************" temp_data = question.split(" ", (-1)) print temp_data questions[index + 1] = _new_query_string( temp_data, questions[index + 1], userdata.i, userdata.j) print(questions[index + 1]) message = u"Interpretation {1}: {0}" print(message.format(str(expression), expression.rule_used)) first_time = False expr = expression expr.rule_used = expression else: """ will have to see if there is more to parse form question if there are mor conditions in order to make the next question base on the first query ! """ expr += expression index += 1 target, query = generation.get_code(expr, self.language) toBeReturned.query = query yield toBeReturned print(u"Query generated: {0}".format(query))
def get_queries(self, question): """ Given `question` in natural language, it returns :type self: object three things: - the target of the query in string format - the query - metadata given by the regex programmer (defaults to None) The queries returned corresponds to the regexes that match in weight order. """ """ parse the question so that we split it if it hase "or" or "and" in it *( maybe on "," also at a later date) """ question = encoding_flexible_conversion(question) questions = question.split(" and ", (-1)) expr = Expression() first_time = True index = 0 #print questions toBeReturned = ReturnModel(None, None) for question in questions: for expression, userdata in self._iter_compiled_forms(question): if first_time: #print expression.rule_used toBeReturned.rule_used = expression.rule_used #print userdata """ -- it wont work for all the question or it will but we need more parrsing -- base on the type of the expression.rule_used we can take actions to connect the next expressions to the curent one if they are more """ if len(questions) > (index + 1): if expression.rule_used == "WhoAreChildrensOfQuestion": print "**************=Next query=**************************" temp_data = question.split(" ", (-1)) print temp_data questions[index+1] = _new_query_string(temp_data, questions[index+1], userdata.i, userdata.j) print(questions[index+1]) message = u"Interpretation {1}: {0}" print(message.format(str(expression), expression.rule_used)) first_time = False expr = expression expr.rule_used = expression else: """ will have to see if there is more to parse form question if there are mor conditions in order to make the next question base on the first query ! """ expr += expression index += 1 target, query = generation.get_code(expr, self.language) toBeReturned.query = query yield toBeReturned print(u"Query generated: {0}".format(query))