<reponame>roholazandie/ParlAI
from parlai.agents.programr.parser.exceptions import ParserException
from parlai.agents.programr.parser.template.nodes.base import TemplateNode
from parlai.agents.programr.utils.logging.ylogger import YLogger


class TemplateSrNode(TemplateNode):

    def __init__(self):
        TemplateNode.__init__(self)

    def resolve_to_string(self, brain):
        sentence = brain.dialog.get_conversation().current_question().current_sentence()
        star = sentence.matched_context.star(1)
        if star is not None:
            resolved = ""#client_context.bot.ask_question(brain, star, srai=True)
        else:
            YLogger.error(brain, "Sr node has no stars available")
            resolved = ""
        YLogger.debug(brain, "[%s] resolved to [%s]", self.to_string(), resolved)
        return resolved

    def resolve(self, brain):
        try:
            return self.resolve_to_string(brain)
        except Exception as excep:
            YLogger.exception(brain, "Failed to resolve", excep)
            return ""

    def to_string(self):
        return "SR"

    def to_xml(self, client_context):
        xml = "<sr />"
        return xml

    #######################################################################################################
    # <sr/> |

    def parse_expression(self, graph, expression):
        self._parse_node(graph, expression)
        if self.children:
            raise ParserException("<sr> node should not contain child text, use <sr /> or <sr></sr> only")

from parlai.agents.programr.parser.exceptions import ParserException
from parlai.agents.programr.parser.template.nodes.base import TemplateNode
from parlai.agents.programr.utils.logging.ylogger import YLogger


class TemplateSrNode(TemplateNode):

    def __init__(self):
        TemplateNode.__init__(self)

    def resolve_to_string(self, brain):
        sentence = brain.dialog.get_conversation().current_question().current_sentence()
        star = sentence.matched_context.star(1)
        if star is not None:
            resolved = ""#client_context.bot.ask_question(brain, star, srai=True)
        else:
            YLogger.error(brain, "Sr node has no stars available")
            resolved = ""
        YLogger.debug(brain, "[%s] resolved to [%s]", self.to_string(), resolved)
        return resolved

    def resolve(self, brain):
        try:
            return self.resolve_to_string(brain)
        except Exception as excep:
            YLogger.exception(brain, "Failed to resolve", excep)
            return ""

    def to_string(self):
        return "SR"

    def to_xml(self, client_context):
        xml = "<sr />"
        return xml

    #######################################################################################################
    # <sr/> |

    def parse_expression(self, graph, expression):
        self._parse_node(graph, expression)
        if self.children:
            raise ParserException("<sr> node should not contain child text, use <sr /> or <sr></sr> only")
####################################################################################################### # <sr/> |