# Path: ltlbroom/specgeneration.py
# def chunks_from_gentree(gen_tree):
#     """Return all the SpecChunk contained in a generation tree."""
#     return [spec_lines for command_spec_lines in gen_tree.values()
#             for spec_lines_list in command_spec_lines.values()
#             for spec_lines in spec_lines_list]
# 
# def goal_to_chunk(goal_idx, spec_chunks):
#     """Return the unique SpecChunk that contain a goal index."""
#     chunks = [spec_chunk for spec_chunk in spec_chunks if spec_chunk.contains_goal(goal_idx)]
#     if len(chunks) == 1:
#         return chunks[0]
#     elif len(chunks) > 1:
#         print >> sys.stderr, "Error: Found multiple chunks for goal {}.".format(goal_idx)
#     # Zero length case returns None without printing an error
#     return None


from ltlbroom.specgeneration import chunks_from_gentree, goal_to_chunk
    """Supports stateful dialog with the NL system."""

    def __init__(self, generation_tree=None):
        # Store the logic generation tree if it is provided.
        self._gen_tree = None
        self._spec_lists = None
        self.set_gen_tree(generation_tree)
        self._user_history = []
        self._system_history = []

    def set_gen_tree(self, gen_tree):
        """Set the generation tree."""
        self._gen_tree = gen_tree
        self._spec_lists = chunks_from_gentree(self._gen_tree) if self._gen_tree else None

    def tell(self, text, current_goal=None):
        """Tell the system something and return its response."""
        self._user_history.append(text)
        # Return the English of the current goal
        if self._gen_tree and current_goal:
            response = self.explain_goal(current_goal)
        else:
            response = "I'm not sure what to say, but thank you for sharing."

        self._system_history.append(response)
        return response

    def explain_goal(self, goal_idx):
        """Explain what a goal number means."""
        if self._spec_lists:

# Path: ltlbroom/specgeneration.py
# def chunks_from_gentree(gen_tree):
#     """Return all the SpecChunk contained in a generation tree."""
#     return [spec_lines for command_spec_lines in gen_tree.values()
#             for spec_lines_list in command_spec_lines.values()
#             for spec_lines in spec_lines_list]
# 
# def goal_to_chunk(goal_idx, spec_chunks):
#     """Return the unique SpecChunk that contain a goal index."""
#     chunks = [spec_chunk for spec_chunk in spec_chunks if spec_chunk.contains_goal(goal_idx)]
#     if len(chunks) == 1:
#         return chunks[0]
#     elif len(chunks) > 1:
#         print >> sys.stderr, "Error: Found multiple chunks for goal {}.".format(goal_idx)
#     # Zero length case returns None without printing an error
#     return None


# Path: ltlbroom/dialog.py
from ltlbroom.specgeneration import chunks_from_gentree, goal_to_chunk

    """Supports stateful dialog with the NL system."""

    def __init__(self, generation_tree=None):
        # Store the logic generation tree if it is provided.
        self._gen_tree = None
        self._spec_lists = None
        self.set_gen_tree(generation_tree)
        self._user_history = []
        self._system_history = []

    def set_gen_tree(self, gen_tree):
        """Set the generation tree."""
        self._gen_tree = gen_tree
        self._spec_lists = chunks_from_gentree(self._gen_tree) if self._gen_tree else None

    def tell(self, text, current_goal=None):
        """Tell the system something and return its response."""
        self._user_history.append(text)
        # Return the English of the current goal
        if self._gen_tree and current_goal:
            response = self.explain_goal(current_goal)
        else:
            response = "I'm not sure what to say, but thank you for sharing."

        self._system_history.append(response)
        return response

    def explain_goal(self, goal_idx):
        """Explain what a goal number means."""
        if self._spec_lists:

            goal_spec_chunk = goal_to_chunk(goal_idx, self._spec_lists)