Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. from answers import HighestWeightedScoreSelection, MultipleAnswerSelection
  2. import logging, sys
  3. import configParser, subprocess
  4. from DecisionMaker import DecisionMaker
  5. from AgentManager import AgentManager
  6.  
  7. def dialogue():
  8.  
  9.     # Check config.xml to verify workmode
  10.     defaultAgentsMode = configParser.getDefaultAgentsMode()
  11.  
  12.  
  13.     # Lucene initialization
  14.     list_args = ["java", "LuceneWrapper", "0", configParser.getCorpusPath(), "", configParser.getLanguage(), configParser.getIndexPath(), configParser.getHitsPerQuery(), configParser.getDbPath()]
  15.     sp1 = subprocess.Popen(list_args,shell=False)
  16.  
  17.     exitCode = sp1.wait()
  18.  
  19.  
  20.     # If "multi", call the multiagent SSS framework; else, call the "classic" version of SSS
  21.     if(defaultAgentsMode == 'multi'):
  22.         multiAgentAnswerMode()
  23.     else:
  24.         classicDialogueMode()
  25.        
  26.  
  27.  
  28. def classicDialogueMode():
  29.  
  30.     """
  31.    Classic mode for SSS: only calls the Evaluators inside SSS's source, doesn't take external agents into account
  32.    """
  33.  
  34.  
  35.     #Initialize AnswerSelection object
  36.     highestWeightedScoreSelection = HighestWeightedScoreSelection()
  37.  
  38.  
  39.     #SSS classic workloop: receive user query, determine answer through the AnswerSelection object, print the answer for the user
  40.     while True:
  41.         query = ""
  42.  
  43.         while (query == ""):
  44.             query = input("Say something:\n")
  45.  
  46.         if query == "exit":
  47.             break;
  48.  
  49.         logging.basicConfig(filename='log.txt', filemode='w', format='%(message)s', level=logging.INFO)
  50.         logging.info("Query: " + query)
  51.  
  52.  
  53.         answer = highestWeightedScoreSelection.provideAnswer(query)
  54.  
  55.  
  56.         print("Question:", query)
  57.         print("Answer:", answer)
  58.  
  59.  
  60.  
  61.  
  62. def multiAgentAnswerMode():
  63.  
  64.     """
  65.    Initialize main modules:
  66.    MultipleAnswerSelection will give us the answers from the classic SSS's agents
  67.    AgentManager will generate our external agents and retrieve their answers
  68.    DecisionMaker will receive both the answers from MultipleAnswerSelection and AgentManager, and will decide the best answer to give to the user
  69.    """
  70.  
  71.     multipleAnswerSelection = MultipleAnswerSelection()
  72.     agentManager = AgentManager()
  73.     decisionMaker = DecisionMaker(configParser.getDecisionMethod())
  74.  
  75.  
  76.     # SSS workloop
  77.     while True:
  78.         query = ""
  79.  
  80.         while (query == ""):
  81.             query = input("Say something:\n")
  82.  
  83.         if query == "exit":
  84.             break;
  85.  
  86.         logging.basicConfig(filename='log.txt', filemode='w', format='%(message)s', level=logging.INFO)
  87.         logging.info("Query: " + query)
  88.  
  89.  
  90.         defaultAgentsAnswers = multipleAnswerSelection.provideAnswer(query)
  91.         externalAgentsAnswers = agentManager.generateAgentsAnswers(query)
  92.         # Both defaultAgentsAnswers and externalAgentsAnswers are dictionaries in the format {'agent1': 'answer1', 'agent2': 'answer2'}
  93.        
  94.  
  95.         # Calling the DecisionMaker after having all of the answers stored in the above dictionaries
  96.         answer = decisionMaker.decideBestAnswer(defaultAgentsAnswers,externalAgentsAnswers)
  97.  
  98.  
  99.         print("Question:", query)
  100.         print("Final Answer:", answer)
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. if __name__ == "__main__":
  109.     dialogue()
  110.  
  111.  
  112. #TODO mode evaluation
  113. #TODO mode learning
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement