Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from answers import HighestWeightedScoreSelection, MultipleAnswerSelection
- import logging, sys
- import configParser, subprocess
- from DecisionMaker import DecisionMaker
- from AgentManager import AgentManager
- def dialogue():
- # Check config.xml to verify workmode
- defaultAgentsMode = configParser.getDefaultAgentsMode()
- # Lucene initialization
- list_args = ["java", "LuceneWrapper", "0", configParser.getCorpusPath(), "", configParser.getLanguage(), configParser.getIndexPath(), configParser.getHitsPerQuery(), configParser.getDbPath()]
- sp1 = subprocess.Popen(list_args,shell=False)
- exitCode = sp1.wait()
- # If "multi", call the multiagent SSS framework; else, call the "classic" version of SSS
- if(defaultAgentsMode == 'multi'):
- multiAgentAnswerMode()
- else:
- classicDialogueMode()
- def classicDialogueMode():
- """
- Classic mode for SSS: only calls the Evaluators inside SSS's source, doesn't take external agents into account
- """
- #Initialize AnswerSelection object
- highestWeightedScoreSelection = HighestWeightedScoreSelection()
- #SSS classic workloop: receive user query, determine answer through the AnswerSelection object, print the answer for the user
- while True:
- query = ""
- while (query == ""):
- query = input("Say something:\n")
- if query == "exit":
- break;
- logging.basicConfig(filename='log.txt', filemode='w', format='%(message)s', level=logging.INFO)
- logging.info("Query: " + query)
- answer = highestWeightedScoreSelection.provideAnswer(query)
- print("Question:", query)
- print("Answer:", answer)
- def multiAgentAnswerMode():
- """
- Initialize main modules:
- MultipleAnswerSelection will give us the answers from the classic SSS's agents
- AgentManager will generate our external agents and retrieve their answers
- DecisionMaker will receive both the answers from MultipleAnswerSelection and AgentManager, and will decide the best answer to give to the user
- """
- multipleAnswerSelection = MultipleAnswerSelection()
- agentManager = AgentManager()
- decisionMaker = DecisionMaker(configParser.getDecisionMethod())
- # SSS workloop
- while True:
- query = ""
- while (query == ""):
- query = input("Say something:\n")
- if query == "exit":
- break;
- logging.basicConfig(filename='log.txt', filemode='w', format='%(message)s', level=logging.INFO)
- logging.info("Query: " + query)
- defaultAgentsAnswers = multipleAnswerSelection.provideAnswer(query)
- externalAgentsAnswers = agentManager.generateAgentsAnswers(query)
- # Both defaultAgentsAnswers and externalAgentsAnswers are dictionaries in the format {'agent1': 'answer1', 'agent2': 'answer2'}
- # Calling the DecisionMaker after having all of the answers stored in the above dictionaries
- answer = decisionMaker.decideBestAnswer(defaultAgentsAnswers,externalAgentsAnswers)
- print("Question:", query)
- print("Final Answer:", answer)
- if __name__ == "__main__":
- dialogue()
- #TODO mode evaluation
- #TODO mode learning
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement