class ActedOnQuestion(QuestionTemplate):
    """
    Ex: "List movies with Hugh Laurie"                      # ok
        "Movies with Matt LeBlanc"                          # not ok: yes, the problem is the big "M" (lemmatizer should do it already or not??)
        "movies with Matt LeBlanc"                          # ok
        "In what movies did Jennifer Aniston appear?"       # ok
        "Which movies did Mel Gibson starred?"              # ok
        "Movies starring Winona Ryder"                      # not ok
        movies where Matt LeBlanc starred                   # ok
        movies in which Matt LeBlanc played in              # ok
        list movies in which Matt LeBlanc appears           # ok
    """

    maybe_list = Question(
        Lemma("list") | Lemma("elencate")
        | Lemmas("spell out") + Lemmas("write down") + Lemmas("tell me the"))
    acted_on = (Lemma("appear") | Lemma("act") | Lemma("star")
                | Lemmas("play in"))

    regex1 = maybe_list + movie_lemmas + Lemma("with") + Actor()
    regex2 = maybe_list + Question(
        Pos("IN")) + (Lemma("what") | Lemma("which")) + movie_lemmas + (
            Lemma("do") | Lemma("have")) + Actor() + acted_on
    regex3 = maybe_list + movie_lemmas + (
        Lemma("where") | Lemmas("in which")) + Actor() + acted_on

    regex = (regex1 | regex2 | regex3) \
            + maybe_dot_or_qmark

    def interpret(self, match):
        movie = IsMovie() + HasActor(match.actor)
        movie_name = NameOf(movie)
        print(movie_name.__dict__)
        return movie_name, "enum"
class MovieReleaseDateQuestion(QuestionTemplate):
    """
    Ex: "Show me release date of Pocahontas"    # ok
        show me release date of Pocahontas      # ok
        release date of Bambi                   # ok
        release date of Bambi?                  # ok
        the release date of Bambi?              # ok
        "Tell me the release date of Bambi"     # ok
        when was Big Fish released?             # ok

    """
    tellme = Question(Lemmas("show me") | Lemmas("tell me"))
    maybe_the = Question(Lemma("the"))
    release_date = Lemmas("release date")

    regex1 = tellme + maybe_the + release_date + Pos("IN") + Movie()
    regex2 = Lemma("when") + Lemma("be") + Movie() + Lemma("release")

    regex = (regex1 | regex2) \
            + maybe_dot_or_qmark

    def interpret(self, match):
        release_date = ReleaseDateOf(match.movie)
        print(release_date)
        return release_date, "literal"
Beispiel #3
0
class NicknameOfQuestion(QuestionTemplate):
    """
    Regex for questions about the nickname for the university
    Ex: "What is the nickname of York University?"
        "What is University of Toronto nickname?"
    """

    regex = (Lemmas("what be") + University() + Lemma("nickname") + Question(Pos("."))) | \
        (Lemmas("what be") + Lemma("the") + Lemma("nickname") + Pos("IN") + University() + Question(Pos(".")))

    def interpret(self, match):
        nick = NicknameOf(match.university)
        return nick, "enum"
Beispiel #4
0
class MottoOfQuestion(QuestionTemplate):
    """
    Regex for questions about the motto for a university
    Ex: "What is the motto of York University?"
        "What is University of Toronto motto?"
    """

    regex = (Lemmas("what be") + University() + Lemma("motto") + Question(Pos("."))) | \
        (Lemmas("what be") + Lemma("the") + Lemma("motto") + Pos("IN") + University() + Question(Pos(".")))

    def interpret(self, match):
        motto = MottoOf(match.university)
        return motto, "enum"
Beispiel #5
0
class InstructorEmailQuestion(QuestionTemplate):
    """
       Ex: "What is the email of instructor of cmpe 273?"
           "Which email is used to communicate with instructor of cmpe 273?"
    """
    regex = Lemmas("what be") + Question(Pos("DT")) + Lemma("email") + Pos("IN") + Lemma("instructor") + Pos("IN") + Course() + Question(Pos(".")) | \
            Lemmas("which email be ") + Lemma("use") + Pos("TO") + Lemma("communicate") + Pos("IN") + Lemma("instructor") + Pos("IN") + Course() + Question(Pos("."))

    def interpret(self, match):
        answer = "The instructor's email of %s is %s"
        email = IsInstructorInfoRelated() + match.course + HasFields(
            'email'.decode('utf-8')) + HasAnswer(answer.decode('utf-8'))
        return email
Beispiel #6
0
class ModifiedDateQuestion(QuestionTemplate):
    """
    Ex: when was voaf last update?
        When was voaf last update
    """
    regex1 = Lemmas("when be") + Vocabulary() + Lemmas("last update")
    regex2 = Lemmas("when be") + Vocabulary() + Lemmas("last modify")

    regex = (regex1 | regex2) + Question(Pos("."))

    def interpret(self, match):
        modif_date = dsl.ModifiedDateOf(match.vocabulary)
        return modif_date, "literal"
Beispiel #7
0
class WhoWroteQuestion(QuestionTemplate):
    """
        "who is the author of A Game Of Thrones?"
    """

    regex = ((Lemmas("who write") + Book()) |
             (Question(Lemmas("who be") + Pos("DT")) +
              Lemma("author") + Pos("IN") + Book())) + \
            Question(Pos("."))

    def interpret(self, match):
        author = NameOf(IsPerson() + AuthorOf(match.book))
        return author, "literal"
Beispiel #8
0
class BooksByAuthorQuestion(QuestionTemplate):
    """
    Ex: "list books by George Orwell"
        "which books did Suzanne Collins wrote?"
    """

    regex = (Question(Lemma("list")) + Lemmas("book by") + Author()) | \
            ((Lemma("which") | Lemma("what")) + Lemmas("book do") +
             Author() + Lemma("write") + Question(Pos(".")))

    def interpret(self, match):
        book = IsBook() + HasAuthor(match.author)
        book_name = NameOf(book)
        return book_name, "enum"
Beispiel #9
0
class GradingQuestion(QuestionTemplate):
    """
        Ex: "How is the grading for cmpe 273"
        Ex: "What is the grading for cmpe 273"
    """
    grading = Group(Lemma("grading"), "grading")
    regex = Lemmas("How be") + Question(Pos("DT")) + grading + Pos("IN") + Course() + Question(Pos(".")) | \
    Lemmas("what be") + Question(Pos("DT")) + Lemma("grading") + Pos("IN") + Course() + Question(Pos("."))

    def interpret(self, match):
        answer = "%s has %s ."
        grading = IsClassRelated() + match.course + HasFields('grading'.decode('utf-8')) \
                       + HasAnswer(answer.decode('utf-8'))
        return grading
Beispiel #10
0
class GradingPolicy(QuestionTemplate):
    """
        Ex: "What is the assignment breakdown for cmpe 273?"
        Ex: "What is the grading policy for cmpe 273"
    """
    gradingpolicy = Group(Lemma("gradingpolicy"), "gradingpolicy")
    regex = Lemmas("What be") + Question(Pos("DT")) + Lemma("grading") + Lemma("policy") + Pos("IN") + Course() + Question(Pos(".")) | \
    Lemmas("what be") + Question(Pos("DT")) + Lemma("assignment") + Lemma("breakdown") + Pos("IN") + Course() + Question(Pos("."))

    def interpret(self, match):
        answer = "%s has the following weightage: %s."
        gradingpolicy = IsClassRelated() + match.course + HasFields('GradingPolicy'.decode('utf-8')) \
                       + HasAnswer(answer.decode('utf-8'))
        return gradingpolicy
Beispiel #11
0
class AddressOfQuestion(QuestionTemplate):
    """
    Regex for questions asking about the address of a restaurant
    Ex: "What is the address of Square Boy restaurant?"
        "where is Brasserie Julien located?"  
    """

    regex = (Lemmas("what be") + Pos("DT") + Lemma("address") + Pos("IN") + \
            Restaurant() + Question(Lemma("restaurant")) + Question(Pos("."))) | \
            (Lemmas("where be") + Restaurant() + Lemma("locate") + Question(Lemma("restaurant")) + Question(Pos(".")))

    def interpret(self, match):
        address = AddressOf(match.restaurant)
        return address, "enum"
Beispiel #12
0
class SpeakersOfQuestion(QuestionTemplate):
    """
    Regex for questions about the number of people that speaks a language
    Ex: "How many people speaks English language?"
        "How many people speak Canadian French?"
        "How many people in the world can speak Arabic language?"
    """

    regex = (Lemmas("how many") + Lemma("people") + (Lemma("speaks") | Lemma("speak")) + Language() + Question(Pos("."))) | \
        (Lemmas("how many") + Lemma("people") + Pos("IN") + Pos("DT") + Lemma("world") + Lemma("can") + (Lemma("speak") | Lemma("speaks")) + Language() + Question(Pos(".")))

    def interpret(self, match):
        NumberOfSpeakers = SpeakersOf(match.language)
        return NumberOfSpeakers, "literal"
Beispiel #13
0
class MovieDurationQuestion(QuestionTemplate):
    """
    Ex: "How long is Pulp Fiction"
        "What is the duration of The Thin Red Line?"
    """

    regex = ((Lemmas("how long be") + Movie()) |
            (Lemmas("what be") + Pos("DT") + Lemma("duration") +
             Pos("IN") + Movie())) + \
            Question(Pos("."))

    def interpret(self, match):
        duration = DurationOf(match.movie)
        return duration, ("literal", "{} minutes long")
Beispiel #14
0
class PlotOfQuestion(QuestionTemplate):
    """
    Ex: "what is Shame about?"
        "plot of Titanic"
    """

    regex = ((Lemmas("what be") + Movie() + Lemma("about")) | \
             (Question(Lemmas("what be the")) + Lemma("plot") +
              Pos("IN") + Movie())) + \
            Question(Pos("."))

    def interpret(self, match):
        definition = DefinitionOf(match.movie)
        return definition, "define"
class InstructorOfficeHour(QuestionTemplate):
    """
        Ex: "What time does the cmpe 273 instructor have office hours?"
            "When does the cmpe 273 instructor have office hours?"
    """
    regex = Plus(Lemmas("what time") | Lemma("when")) + Lemma("do") + Question(Pos("DT")) + Course() + Lemma("instructor") \
            + Lemma("have") + Lemmas("office hours") + Question(Pos("."))

    def interpret(self, match):
        answer = "The instructor for %s is available from %s"
        instructor_office_hour = IsInstructorInfoRelated(
        ) + match.course + HasFields(
            'office_hour'.decode('utf-8')) + HasAnswer(answer.decode('utf-8'))
        return instructor_office_hour
class ClassTimeQuestion(QuestionTemplate):
    """
        Ex: "What is the class time for cmpe 273?"
            "When is the class for cmpe 273?"
    """
    classTime = Group(Lemma("class") + Question(Lemma("time")), "classTime")
    regex = (Lemmas("what be") | Lemmas("when be")) + Question(
        Pos("DT")) + classTime + Pos("IN") + Course() + Question(Pos("."))

    def interpret(self, match):
        answer = "The class time for %s is at %s"
        class_time = IsClassRelated() + match.course + HasFields(
            'class time'.decode('utf-8')) + HasAnswer(answer.decode('utf-8'))
        return class_time
Beispiel #17
0
class ReleaseDateQuestion(QuestionTemplate):
    """
    Ex: when was voaf release?
        When was voaf release
    """
    regex1 = Lemmas("when be") + Vocabulary() + Lemma("release")
    regex2 = Lemmas("when be") + Vocabulary() + Lemma("issue")
    regex3 = Lemmas("when be") + Vocabulary() + Lemma("create")

    regex = (regex1 | regex2 | regex3) + Question(Pos("."))

    def interpret(self, match):
        release_date = dsl.ReleaseDateOf(match.vocabulary)
        return release_date, "literal"
Beispiel #18
0
class ColorOfQuestion(QuestionTemplate):
    """
    Regex for questions about the colors for a university
    Ex: "What is York University colors?"
        "What is York University color?"
        "What is the colors of University of Toronto?"
        "What is the color of University of Toronto?"
    """

    regex = (Lemmas("what be") + University() + (Lemma("colors")|Lemma("color")) + Question(Pos("."))) | \
        (Lemmas("what be") + Lemma("the") + (Lemma("colors")|Lemma("color")) + Pos("IN") + University() + Question(Pos(".")))

    def interpret(self, match):
        color = ColorOf(match.university)
        return color, "enum"
Beispiel #19
0
class InstructorQuestion(QuestionTemplate):
    """
        Ex: "Who is the instructor of cmpe 273?"
            "Who teaches cmpe 273?"
            "By whom is cmpe 273 taught?"
    """
    regex = Lemmas("who be") + Question(Pos("DT")) + Lemma("instructor") + Pos("IN") + Course() + Question(Pos(".")) | \
            Lemma("who") + Lemma("teach") + Course() + Question(Pos("."))| \
            Pos("IN") + Lemmas("whom be") + Course() + Lemma("taught") + Question(Pos("."))

    def interpret(self, match):
        answer = "The instructor for %s is %s"
        instructor = IsInstructorInfoRelated() + match.course + HasFields(
            'name'.decode('utf-8')) + HasAnswer(answer.decode('utf-8'))
        return instructor
Beispiel #20
0
class WhoWroteQuestion(QuestionTemplate):
    """
    Ex: "who wrote The Little Prince?"
        "who is the author of A Game Of Thrones?"
    """

    regex = ((Lemmas("who write") + Book()) |
             (Question(Lemmas("who be") + Pos("DT")) +
              Lemma("author") + Pos("IN") + Book())) + \
            Question(Pos("."))

    def interpret(self, match):
        _book, i, j = match.book
        author = NameOf(IsPerson() + AuthorOf(_book))
        return author, ReturnValue(i, j)
Beispiel #21
0
class NumberOfStaffQuestion(QuestionTemplate):
    """
    Regex for questions about the number of staff in a university
    Ex: "How many staff in York University?"
        "How many staff working in McGill University?"
        "Number of staff in University of Toronto?"
        "Number of staff working in University of Toronto?"
    """

    regex = ((Lemmas("how many") | Lemmas("number of")) + Lemma("staff") + Pos("IN") + University() + Question(Pos("."))) | \
        ((Lemmas("how many") | Lemmas("number of")) + Lemma("staff") + Lemma("work") + Pos("IN") + University() + Question(Pos(".")))

    def interpret(self, match):
        staff = StaffOf(match.university)
        return staff, "literal"
Beispiel #22
0
class MovieDurationQuestion(QuestionTemplate):
    """
    Ex: "How long is Pulp Fiction"
        "What is the duration of The Thin Red Line?"
    """

    regex = ((Lemmas("how long be") + Movie()) |
             (Lemmas("what be") + Pos("DT") + Lemma("duration") +
              Pos("IN") + Movie())) + \
            Question(Pos("."))

    def interpret(self, match):
        _movie, i, j = match.movie
        duration = DurationOf(_movie)
        return duration, ReturnValue(i, j)
Beispiel #23
0
class OpeningDateQuestion(QuestionTemplate):
    """
    Regex for questions about the opening date of a hotel
    Ex: "When was the opening of Novotel Century Hong Kong hotel?"
        "Which date the Hyatt Regency Atlanta was opened?"
        "When did Hilton Chicago hotel opened?"
    """
    
    regex = (Lemmas("when be") + Lemma("the") + Lemma("open") + Pos("IN") + Hotel() + Question(Lemma("hotel")) + Question(Pos("."))) | \
        (Lemma("which") + Lemma("date") + Lemma("the") + Hotel() + Question(Lemma("hotel")) + Lemma("be") + Lemma("open") + Question(Pos("."))) | \
        (Lemmas("when do") + Hotel() + Question(Lemma("hotel")) + Lemma("open") + Question(Pos("."))) 
    
    def interpret(self, match):
        Date = OpeningDateOf(match.hotel)
        return Date, "literal"
Beispiel #24
0
class MostWinsQuestionCountry(QuestionTemplate):
    """
    Ex: "Who won more in Spain?"
        "Who won more Spain titles?"
    """

    regex = ((Lemmas("who win") + Lemma("more") + Lemma("in") + Country()) |
             (Lemmas("who win") + Lemma("more") + Country() + Lemma("title"))) + \
            Question(Pos("."))

    def interpret(self, match):
        league = IsLeague() + IsCountryLeagueOf(match.country)
        team = IsTeam() + MostSuccessfulOf(league)
        team_name = NameOf(team)
        return team_name, "literal"
Beispiel #25
0
class WhereIsFile(QuestionTemplate):
    """
    Regex for questions like

    Where is Listener.ora (?locate)? -- ok
    What is the (?file) location of Listener.ora ((?file)? -- ok
    How to find Listener.ora? -- ok
    """

    target = Group(file_tokens, "target_file_name") + Group(
        extension_tokens, "target_file_extension")

    regex = (Lemmas("how to") + Lemma("find") + target + Question(Lemma("file"))) | \
            (Lemma("where") + Lemma("be") + target + Question(Lemma("file")) + Question(Lemma("locate"))) | \
            (Pos("WP") + Lemma("be") + Question(Pos("DT")) + Question(Lemma("file")) + Lemma("location") + Pos("IN") +
             target + Question(Lemma("file")))

    def interpret(self, match):

        name = match.target_file_name.tokens
        extension = match.target_file_extension.tokens

        target = IsFile() + FileOf(name + "." + extension)
        meta = "fileLocationNlg", "WHERE", str(name + "." + extension)

        return FileLocation(target), meta
Beispiel #26
0
class WhoIsActorQuestion(QuestionTemplate):
    """
    Ex: "Who is Michelle Pfeiffer?"
    """
    prob_threshold = 0.95

    examples = ["Who is Michelle Pfeiffer?"]

    tables = ["actors", "actresses"]

    regex = (
                (
                    Lemmas("who be") + Question(Pos("DT")) + Actor() \
                )
            ) \
            + Question(Pos("."))

    def interpret(self, match):
        definition = DefinitionOf(match.actor)
        #print("Match ",match.movie)
        actor_name = ''.join(match.actor.nodes[0][1][1].split('"')[:-1])
        print("Actor name ", actor_name)
        definition.nodes = [
            u' concat(name, " ", surname) like concat("%", replace("' +
            actor_name + '", " ", "%"), "%")'
        ]
        # what to extract
        definition.head = u" distinct name, surname, title"
        definition.tables = ["actors", "actresses"]
        #print("definition ",definition)
        return definition, ("define", "WhoIsActorQuestion")
Beispiel #27
0
class InstructorOfficeLocation(QuestionTemplate):
    """
        Ex: "What is the office location of cmpe 273 instructor?"
            "Where is the office of cmpe 273 instructor?"
            "Where is the office of cmpe 273 instructor located?"
    """
    regex = Lemmas("what be") + Question(Pos("DT")) + Lemma("office") + Question(Lemma("location")) + Pos("IN") + Course() + Lemma("instructor")  + Question(Pos(".")) | \
            Lemmas("where be") + Question(Pos("DT")) + Lemma("office") + Pos("IN") + Course() + Lemma("instructor") + Question(Lemma("locate")) + Question(Pos("."))

    def interpret(self, match):
        answer = "The instructor's office for %s is %s"
        instructor_office = IsInstructorInfoRelated(
        ) + match.course + HasFields(
            'office_location'.decode('utf-8')) + HasAnswer(
                answer.decode('utf-8'))
        return instructor_office
class DirectorOfQuestion(QuestionTemplate):
    """
    Ex: "Who is the director of Big Fish?"      # ok
        "who directed Pocahontas?"              # ok
        director of Sparta?                     # ok
        tell me who directed Nemo                   # ok
        tell me who is the director of Gran Torino  # ok, grammatically wrong
    """

    who = Lemma("who")
    director = Lemma("director")
    maybe_tellme = Question(Lemmas("tell me"))

    regex1 = maybe_tellme + Question(who + Lemma("be") + Pos("DT") +
                                     director) + Pos("IN") + Movie()
    regex2 = maybe_tellme + who + Lemma("direct") + Movie()
    regex3 = director + Pos("IN") + Movie()

    regex = (regex1 | regex2 | regex3) \
            + maybe_dot_or_qmark

    def interpret(self, match):
        director = IsDirector() + DirectorOf(match.movie)
        director_name = NameOf(director)
        return director_name, "literal"
Beispiel #29
0
class DressOfQuestion(QuestionTemplate):
    """
    Regex for questions about the dress code in a restaurant
    Ex: "What is the dress code in The Ivy restaurant?"
        "What can I wear at the Oyster Bar?" 
        "What should you wear at 21 Club restaurant?"
    """

    regex = (Lemmas("what be") + Pos("DT") + Lemma("dress") + Lemma("code") + Pos("IN") + \
            Restaurant() + Question(Lemma("restaurant")) + Question(Pos("."))) | \
            ((Lemmas("what should") | Lemmas("what can")) + (Lemma("you") | Lemma("i")) + Lemma("wear") + \
            Pos("IN") + Question(Lemma("the")) + Restaurant() + Question(Lemma("restaurant")) + Question(Pos(".")))

    def interpret(self, match):
        DressType = DressOf(match.restaurant)
        return DressType, "enum"
Beispiel #30
0
class PlotOfQuestion(QuestionTemplate):
    """
    Ex: "what is (the movie/film) Shame about(?)"
        "what is the plot/story of Shame(?)"
        "plot of Titanic"
    """

    regex1 = Lemmas("what be") + \
             Question(Literal("the") + (Lemma("movie") | Lemma("film"))) + \
             Movie() + Question(Lemma("about")) +  Question(Pos("."))

    regex = regex1

    def interpret(self, match):
        match.movie.add_data(u"dbpprop:counter", u"?counter")
        plot = PlotOf(match.movie)
        #plot.add_data(u"dbpprop:counter",u"?counter")
        old_value = replace_prop(plot, u"dbpprop:name", u"?name")
        #replace_prop(plot,u"dbpprop:plot", u"?plot")

        extra = MyExtra('FILTER regex(?name, "%s", "i").' % old_value)
        plot.add_data(extra, u"")
        #plot.add_data(OrderBy("DESC(xsd:integer(?counter))"),u"")
        #plot.head = "*"
        return plot, "list"