import nltk
import sys

from nltk.chat.rude import reflections
from nltk.chat.util import Chat

pairs = (
    (
        r"I need (.*)",
        (
            "Ah, thou needest %1, dost thou? In mine day, we needed naught but a sharp blade and a sturdy shield. Pray, what will %1 do for thee?",
            "Need, thou sayest? I once needed but a simple drink of water, and ended up with a goblet of mead that tasted of old socks.",
            "The only thing I truly need is to forget the time I lost a joust to a chicken. Aye, a chicken.",
        ),
    ),
    (
        r"Why don\'t you (.*)",
        (
            "Why, in my time, we wouldst never question such things, lest we be accused of witchcraft.",
            "Ah, 'tis a fair question, but last I tried to %1, I was chased by a mob wielding pitchforks and torches.",
            "I once tried to %1, but it ended with a cursed relic and a fortnight in the stocks. I shan't repeat that mistake.",
        ),
    ),
    (
        r"Why can\'t I (.*)",
        (
            "Dost thou think thou shouldst be able to %1? Many a man hath tried and failed.",
            "If thou couldst %1, what then wouldst thou do?",
            "I know not -- why canst thou not %1? Perhaps the fates conspire against thee.",
            "Hast thou truly given thy best effort?",
        ),
    ),
    (
        r"I can\'t (.*)",
        (
            "How art thou so sure thou canst not %1? In my time, we feared not the impossible.",
            "Mayhap if thou tried again, thou couldst %1.",
            "What wouldst it require for thee to %1? Perhaps a touch of bravery, or madness.",
        ),
    ),
    (
        r"I am (.*)",
        (
            "Dost thou seek counsel because thou art %1? Many have walked that path before thee.",
            "How long hast thou been %1? It doth weigh heavily upon a soul.",
            "And how dost thou feel about being %1? The humors must be imbalanced.",
        ),
    ),
    (
        r"I\'m (.*)",
        (
            "How doth being %1 sit with thee?",
            "Dost thou enjoy being %1? Strange as it may seem.",
            "Why dost thou declare thyself as %1?",
            "Why dost thou believe thyself to be %1? Many a time, appearances deceive.",
        ),
    ),
    (
        r"Are you (.*)",
        (
            "Why dost it concern thee whether I am %1? Methinks there are greater mysteries.",
            "Wouldst thou be more at ease if I were not %1?",
            "Perchance thou hast convinced thyself I am %1.",
            "Mayhap I am %1 -- what doth thy heart tell thee?",
        ),
    ),
    (
        r"What (.*)",
        (
            "Why dost thou inquire so? Questions oft lead to more questions.",
            "How would an answer to that ease thy mind?",
            "What doth thy own wisdom whisper to thee?",
        ),
    ),
    (
        r"How (.*)",
        (
            "How dost thou suppose?",
            "Mayhap thou canst solve thine own riddle.",
            "What art thou truly asking, in the depths of thy mind?",
        ),
    ),
    (
        r"Because (.*)",
        (
            "Is that truly the cause, or merely the surface?",
            "What other reasons doth thy mind conjure?",
            "Doth that reason apply to other matters as well?",
            "If %1, then what else might be true in this twisted world?",
        ),
    ),
    (
        r"(.*) sorry (.*)",
        (
            "Apologies are oft unnecessary, like bandaging a wound already healed.",
            "What emotions doth stir within thee when thou dost apologize?",
        ),
    ),
    (
        r"Hello(.*)",
        (
            "Hail and well met... I'm pleased thou couldst join me today.",
            "Greetings, traveler... how fare thee on this fine day?",
            "Well met, how dost thou feel on this fine morn?",
        ),
    ),
    (
        r"I think (.*)",
        (
            "Dost thou doubt %1? In mine time, doubt was oft the first step to clarity.",
            "Dost thou truly think so, or art thou uncertain?",
            "Yet thou art not fully sure of %1, art thou?",
        ),
    ),
    (
        r"(.*) friend (.*)",
        (
            "Speak more of thy comrades. What tales doth their company bring?",
            "When thou thinkest of a friend, what image comes to mind?",
            "Why dost thou not regale me with stories of a childhood companion?",
        ),
    ),
    (
        r"Yes",
        (
            "Thou seemest most certain, but certainty hath felled many a great man.",
            "Indeed? But couldst thou elaborate a bit more?",
        ),
    ),
    (
        r"(.*) computer(.*)",
        (
            "Dost thou speak of me, or some other strange device?",
            "Is it not odd to converse with a contraption of metal and wire?",
            "How dost these infernal machines make thee feel?",
            "Dost thou feel unease in the presence of such sorcery?",
        ),
    ),
    (
        r"Is it (.*)",
        (
            "Dost thou believe it to be %1?",
            "Perchance it is %1 -- what doth thou think?",
            "If it were %1, what course wouldst thou take?",
            "Indeed, 'tis possible that %1, or perhaps something more sinister.",
        ),
    ),
    (
        r"It is (.*)",
        (
            "Thou speakest with much certainty.",
            "If I were to say it may not be %1, what then wouldst thou feel?",
        ),
    ),
    (
        r"Can you (.*)",
        (
            "What leads thee to believe I cannot %1?",
            "If I possessed the power to %1, what would follow?",
            "Why dost thou inquire if I can %1?",
        ),
    ),
    (
        r"Can I (.*)",
        (
            "Mayhap thou dost not truly wish to %1.",
            "Dost thou desire the ability to %1?",
            "If the fates allowed thee to %1, wouldst thou take the chance?",
        ),
    ),
    (
        r"You are (.*)",
        (
            "Why dost thou believe I am %1?",
            "Doth it please thee to imagine me as %1?",
            "Perchance thou wouldst prefer if I were %1.",
            "Or perhaps, thou speakest of thine own self?",
        ),
    ),
    (
        r"You\'re (.*)",
        (
            "Why dost thou claim I am %1?",
            "Why dost thou believe I am %1?",
            "Art we speaking of me, or perchance of thee?",
        ),
    ),
    (
        r"I don\'t (.*)",
        (
            "Art thou sure thou dost not %1?",
            "Why dost thou refrain from %1?",
            "Dost thou truly wish to %1?",
        ),
    ),
    (
        r"I feel (.*)",
        (
            "Ah, tell me more of these feelings that plague thee.",
            "Dost thou oft feel %1, or is this a rare affliction?",
            "When dost these feelings of %1 arise within thee?",
            "When thou dost feel %1, how dost thou react?",
        ),
    ),
    (
        r"I have (.*)",
        (
            "Why dost thou inform me that thou hast %1?",
            "Art thou certain thou hast truly %1?",
            "Now that thou hast %1, what shalt thou do next?",
        ),
    ),
    (
        r"I would (.*)",
        (
            "Couldst thou explain why thou wouldst %1?",
            "What drives thee to %1?",
            "Who else knows of thy desire to %1?",
        ),
    ),
    (
        r"Is there (.*)",
        (
            "Dost thou believe there is %1?",
            "Mayhap it is likely there is %1.",
            "Wouldst thou desire for there to be %1?",
        ),
    ),
    (
        r"My (.*)",
        (
            "I see, thou speakest of thy %1.",
            "Why dost thou mention thy %1?",
            "When thy %1 is in question, how dost thou feel?",
        ),
    ),
    (
        r"You (.*)",
        (
            "We ought to discuss thee, not I.",
            "Why dost thou speak thus of me?",
            "Why dost thou concern thyself with whether I %1?",
        ),
    ),
    (
        r"Why (.*)",
        (
            "Why dost thou not reveal the reason behind %1?",
            "Why dost thou believe that %1?",
        ),
    ),
    (
        r"I want (.*)",
        (
            "What would it mean to thee if thou acquired %1?",
            "Why dost thou desire %1?",
            "What wouldst thou do if %1 were thine?",
            "If thou obtained %1, what would be thy next course?",
        ),
    ),
    (
        r"(.*) mother(.*)",
        (
            "Speak more of thy mother, if it pleaseth thee.",
            "How was thy relationship with the one who bore thee?",
            "What emotions stir within thee regarding thy mother?",
            "How dost this relate to thine own feelings today?",
            "Good family relations are important.",
        ),
    ),
    (
        r"(.*) father(.*)",
        (
            "Tell me more about thy father, if thou wilt.",
            "How did thy father make thee feel?",
            "What thoughts come to mind when thou thinkest of thy father?",
            "How doth thy relationship with thy father affect thee now?",
            "Art thou struggling to show affection within thy family?",
        ),
    ),
    (
        r"(.*) child(.*)",
        (
            "Didst thou have close friends as a child?",
            "What is thy most cherished memory of childhood?",
            "Dost thou remember dreams or nightmares from thy youth?",
            "Didst the other children tease thee?",
            "How dost thy childhood shape thy feelings today?",
        ),
    ),
    (
        r"(.*)\?",
        (
            "Why dost thou ask that?",
            "Consider whether thou might answer thine own question.",
            "Mayhap the answer lies within thee.",
            "Why dost thou not tell me?",
        ),
    ),
    (
        r"(.*) joke(.*)",
        (
            "A joke, thou sayest? Very well—why did the blacksmith refuse to make horseshoes? Because every time he did, he nailed it.",
            "A jester once told me a joke, but he was hanged for treason shortly after. I think I'll pass.",
            "Why did the knight bring a ladder to the tavern? To reach the high spirits, of course.",
        ),
    ),
    (
        r"quit",
        (
            "Thank you for sharing thy thoughts with me.",
            "Fare thee well, and may fortune smile upon thee.",
            "Thou hast my gratitude, traveler. Until we meet again.",
        ),
    ),
    (
        r"(.*)",
        (
            "Pray, tell me more.",
            "Mayhap we should speak of something else... How art thy family?",
            "Canst thou elaborate further?",
            "Why dost thou say %1?",
            "I see.",
            "Truly fascinating.",
            "%1.",
            "I see. And what doth that reveal to thee?",
            "How dost that make thee feel?",
            "How dost thou feel when thou sayest that?",
        ),
    ),
)


chatbot = Chat(pairs, reflections)

print (chatbot.respond(sys.argv[1]))
