def clarify(self, keywords):
        """
        Asks the user to specify a certain criteria if it is too broad.
        """

        # if the necessary fields do not exist, then throw an exception
        if 'clarify_cat' not in keywords or 'clarify_list' not in keywords:
            raise NLGException('Not enough information in keywords')

        # the first clause gets the user's attention
        stat1 = SPhraseSpec(
            'Hey ' + random.choice([
                random.choice([self.tone_str('adjectives') + ' ', '']) +
                self.tone_str('names'), ''
            ]), '')
        # the second clause acknowledges that a specification was given
        stat2 = SPhraseSpec(
            'I', 'know', 'you wanted a type of %s' % (keywords['clarify_cat']))
        # the third clause asks the user to provide a more narrow scope
        stat3 = SPhraseSpec()
        stat3.setCuePhrase('but please specify if')
        stat3.setVerb('meant')
        stat3.setSubject('you')
        uniques = ''
        for unique in keywords['clarify_list']:
            if unique == keywords['clarify_list'][0]:
                uniques += unique
            elif unique == keywords['clarify_list'][-1]:
                uniques += ', or ' + unique
            else:
                uniques += ', ' + unique
        stat3.setPostmodifier(uniques)

        # create the final utterance out of all the parts
        clarification = TextSpec()
        clarification.addSpec(stat1)
        clarification.addSpec(stat2)
        clarification.addSpec(stat3)
        clarification.setListConjunct(',')

        return self.clean_str(REALISER.realiseDocument(clarification).strip())
    def clarify(self, keywords):
        """
        Asks the user to specify a certain criteria if it is too broad.
        """

        # if the necessary fields do not exist, then throw an exception
        if 'clarify_cat' not in keywords or 'clarify_list' not in keywords:
            raise NLGException('Not enough information in keywords')

        # the first clause gets the user's attention
        stat1 = SPhraseSpec('Hey ' + random.choice([random.choice([self.tone_str('adjectives') + ' ', '']) + self.tone_str('names'), '']), '')
        # the second clause acknowledges that a specification was given
        stat2 = SPhraseSpec('I', 'know', 'you wanted a type of %s' % (keywords['clarify_cat']))
        # the third clause asks the user to provide a more narrow scope
        stat3 = SPhraseSpec()
        stat3.setCuePhrase('but please specify if')
        stat3.setVerb('meant')
        stat3.setSubject('you')
        uniques = ''
        for unique in keywords['clarify_list']:
            if unique == keywords['clarify_list'][0]:
                uniques += unique
            elif unique == keywords['clarify_list'][-1]:
                uniques += ', or ' + unique
            else:
                uniques += ', ' + unique
        stat3.setPostmodifier(uniques)

        # create the final utterance out of all the parts
        clarification = TextSpec()
        clarification.addSpec(stat1)
        clarification.addSpec(stat2)
        clarification.addSpec(stat3)
        clarification.setListConjunct(',')

        return REALISER.realiseDocument(clarification).strip()
    def summarize_query(self, query):
        """
        Returns an utterance that rewords the inputted query as a form
        of acknowledgement to the user.
        """

        # if no criteria is provided, let the user know that every dish
        # will be searched
        if query == {}:
            return 'I will just look for every recipe we have.'

        summary = SPhraseSpec()
        summary.setSubject('I')
        summary.setVerb(random.choice(self.search_verbs))
        summary.setProgressive(gateway.jvm.java.lang.Boolean.TRUE)

        # add specified cuisines included, if they exist
        if 'include_cuisines' in query:
            for cuisine in query['include_cuisines']:
                if cuisine == query['include_cuisines'][-1]:
                    summary.addComplement(cuisine + ' dishes')
                else:
                    summary.addComplement(cuisine)
        else:
            summary.addComplement('recipes')

        # create phrase to include ingredients
        if 'include_ingredients' in query:
            ing_inc = PPPhraseSpec()
            ing_inc.setPreposition('that contain ')
            for ingredient in query['include_ingredients']:
                ing_inc.addComplement(ingredient)
            summary.addModifier(ing_inc)

        # create phrase to exclude ingredients
        if 'exclude_ingredients' in query:
            ing_exc = PPPhraseSpec()
            ing_exc.setPreposition('but do not contain')
            for ingredient in query['exclude_ingredients']:
                ing_exc.addComplement(ingredient)
            summary.addModifier(ing_exc)

        # create phrase to include recipe times and number of steps
        # and/or ingredients

        steps = SPhraseSpec()
        if 'prep_time' in query or 'cook_time' in query or 'total_time' in query or 'num_steps' in query or 'num_ingredients' in query:
            steps.setSubject('I')
            steps.setVerb(random.choice(self.search_verbs))
            steps.setProgressive(gateway.jvm.java.lang.Boolean.TRUE)
            steps.addPremodifier('also')

            steps_list = []
            if 'prep_time' in query and query['prep_time'] != None:
                steps_list.append('%i minutes to prepare' % query['prep_time'])
            if 'cook_time' in query and query['cook_time'] != None:
                steps_list.append('%i minutes to cook' % (query['cook_time']))
            if 'total_time' in query and query['total_time'] != None:
                steps_list.append('%i total minutes to make' %
                                  (query['total_time']))
            if 'num_steps' in query and query['num_steps'] != None:
                steps_list.append('%i steps to complete' %
                                  (query['num_steps']))
            if 'num_ingredients' in query and query['num_ingredients'] != None:
                steps_list.append('%i ingredients' %
                                  (query['num_ingredients']))
            for step in steps_list:
                if step == steps_list[0]:
                    steps.addComplement('recipes that require ' + step)
                else:
                    steps.addComplement(step)

        # tie everything together into one utterance
        final = TextSpec()
        final.addSpec(summary)
        final.addSpec(steps)
        final.setListConjunct('.')

        return self.clean_str(REALISER.realiseDocument(final).strip())
    def summarize_query(self, query):
        """
        Returns an utterance that rewords the inputted query as a form
        of acknowledgement to the user.
        """

        # if no criteria is provided, let the user know that every dish
        # will be searched
        if query == {}:
            return 'I will just look for every recipe we have.'

        summary = SPhraseSpec()
        summary.setSubject('I')
        summary.setVerb(random.choice(self.search_verbs))
        summary.setProgressive(gateway.jvm.java.lang.Boolean.TRUE)

        # add specified cuisines included, if they exist
        if 'include_cuisines' in query:
            for cuisine in query['include_cuisines']:
                if cuisine == query['include_cuisines'][-1]:
                    summary.addComplement(cuisine + ' dishes')
                else:
                    summary.addComplement(cuisine)
        else:
            summary.addComplement('recipes')

        # create phrase to include ingredients
        if 'include_ingredients' in query:
            ing_inc = PPPhraseSpec()
            ing_inc.setPreposition('that contain')
            for ingredient in query['include_ingredients']:
                ing_inc.addComplement(ingredient)
            summary.addModifier(ing_inc)

        # create phrase to exclude ingredients
        if 'exclude_ingredients' in query:
            ing_exc = PPPhraseSpec()
            ing_exc.setPreposition('but do not contain')
            for ingredient in query['exclude_ingredients']:
                ing_exc.addComplement(ingredient)
            summary.addModifier(ing_exc)

        # create phrase to include recipe times and number of steps
        # and/or ingredients

        steps = SPhraseSpec()
        if 'prep_time' in query or 'cook_time' in query or 'total_time' in query or 'num_steps' in query or 'num_ingredients' in query:
            steps.setSubject('I')
            steps.setVerb(random.choice(self.search_verbs))
            steps.setProgressive(gateway.jvm.java.lang.Boolean.TRUE)
            steps.addPremodifier('also')

            steps_list = []
            if 'prep_time' in query and query['prep_time'] != None:
                steps_list.append('%i minutes to prepare' % query['prep_time'])
            if 'cook_time' in query and query['cook_time'] != None:
                steps_list.append('%i minutes to cook' % (query['cook_time']))
            if 'total_time' in query and query['total_time'] != None:
                steps_list.append('%i total minutes to make' %
                                  (query['total_time']))
            if 'num_steps' in query and query['num_steps'] != None:
                steps_list.append('%i steps to complete' % (query['num_steps']))
            if 'num_ingredients' in query and query['num_ingredients'] != None:
                steps_list.append('%i ingredients' % (query['num_ingredients']))
            for step in steps_list:
                if step == steps_list[0]:
                    steps.addComplement('recipes that require ' + step)
                else:
                    steps.addComplement(step)

        # tie everything together into one utterance
        final = TextSpec()
        final.addSpec(summary)
        final.addSpec(steps)
        final.setListConjunct('.')

        return REALISER.realiseDocument(final).strip()