def getInformExactEntity(acceptanceList, numAccepted, domainString): '''**Method for global inform action:** creates inform act with none or an entity :param acceptanceList: of slots with value:prob mass pairs :type acceptanceList: dict :param numAccepted: number of *accepted slots* (>80 prob mass) :type numAccepted: int :param domainString: domain tag :type domainString: str :returns: getInformNoneVenue() or getInformAcceptedSlotsAboutEntity() as appropriate ''' acceptedValues = {} for i, slot in enumerate(acceptanceList): if i >= numAccepted: break #(topvalue, topbelief) = acceptanceList[slot] (topvalue, _) = acceptanceList[slot] if topvalue != 'dontcare': acceptedValues[slot] = topvalue result = Ontology.global_ontology.entity_by_features(domainString, acceptedValues) if len(result) == 0: return SummaryUtils.getInformNoneVenue(acceptedValues) else: ent = result[0] return getInformAcceptedSlotsAboutEntity(acceptanceList, ent, numAccepted)
def _getInformAlternativeEntities(acceptanceList, acceptanceList80, prohibitedList, domainString): ''' Returns the dialogue act representing either 1) there is not matching venue: inform(name=none, slot=value, ...) 2) it offers a venue which is not on the prohibited list 3) if all matching venues are on the prohibited list then it says there is no venue except x,y,z,... with such features: inform(name=none, name!=x, name!=y, name!=z, ..., slot=value, ...) ''' acceptedValues = {} numFeats = len(acceptanceList80) for slot in acceptanceList80: (topvalue, topbelief) = acceptanceList80[slot] if topvalue != 'dontcare': acceptedValues[slot] = topvalue if len(acceptedValues) == 0: logger.warning("User didn't specify any constraints or all are dontcare") #return 'null()' result = Ontology.global_ontology.entity_by_features(domainString, acceptedValues) if len(result) == 0: return SummaryUtils.getInformNoneVenue(acceptedValues) else: for ent in result: name = ent['name'] if name not in prohibitedList: return getInformAcceptedSlotsAboutEntity(acceptanceList80, ent, numFeats) return SummaryUtils.getInformNoMoreVenues(acceptanceList, result) return 'null()'
def getInformRequestedSlots(requested_slots, name, domainString): ''' Informs about the requested slots from the last informed venue of form the venue informed by name :param requested_slots: list of requested slots :param name: name of the last informed venue :param domainString: string representing the domain :return: string representing the inform dialogue act ''' result = Ontology.global_ontology.entity_by_features( domainString, {'name': name}) if len(result) > 0: ent = result[0] return _getInformRequestedSlotsForEntity(requested_slots, ent, domainString) else: if not name: # Return a random venue result = [] while len(result) == 0: rand_name = Ontology.global_ontology.getRandomValueForSlot( domainString, 'name', nodontcare=True) result = Ontology.global_ontology.entity_by_features( domainString, {'name': rand_name}) ent = result[0] return _getInformRequestedSlotsForEntity(requested_slots, ent, domainString) else: logger.warning('Couldn\'t find the provided name: ' + name) return SummaryUtils.getInformNoneVenue({'name': name})