Пример #1
0
class ProteinOfQuestion(QuestionTemplate):
    """
    Regex for questions about the protein in species
    Ex: "How much protein in an apple?"
        "How much protein an Apple have?"
        "Do Apple have protein?"
    """

    regex = Lemmas("how much") + Lemma("protein") + Pos("IN") + Pos("DT") + Group(Pos("NNP"), 'species') + Question(Pos(".")) | \
        (Lemmas("how much") + Lemma("protein") + Pos("DT") + Group(Pos("NNP"), 'species') + Lemma("have") + Question(Pos("."))) | \
        (Lemma("do") + Group(Pos("NNP"), 'species') + Lemma("have") + Lemma("protein") + Question(Pos(".")))

    def interpret(self, match):
        name = match.species.tokens
        species = IsSpecies() + HasKeyword(name)
        protein = ProteinOf(species)
        return protein, "enum"
Пример #2
0
class SugarOfQuestion(QuestionTemplate):
    """
    Regex for questions about the sugar in species
    Ex: "How much sugar in an Apple?"
        "How much sugar an Apple have?"
        "Do Apple have sugar?"
    """

    regex = Lemmas("how much") + Lemma("sugar") + Pos("IN") + Pos("DT") + Group(Pos("NNP"), 'species') + Question(Pos(".")) | \
        (Lemmas("how much") + Lemma("sugar") + Pos("DT") + Group(Pos("NNP"), 'species') + Lemma("have") + Question(Pos("."))) | \
        (Lemma("do") + Group(Pos("NNP"), 'species') + Lemma("have") + Lemma("sugar") + Question(Pos(".")))

    def interpret(self, match):
        name = match.species.tokens
        species = IsSpecies() + HasKeyword(name)
        suger = SugarOf(species)
        return suger, "enum"
Пример #3
0
class CarbsOfQuestion(QuestionTemplate):
    """
    Regex for questions about the carbs in species
    Ex: "How much carbs in an apple?"
        "How much carbs an Apple have?"
        "Do Apple have carbs?"
    """

    regex = Lemmas("how much") + Lemma("carbs") + Pos("IN") + Pos("DT") + Group(Pos("NNP"), 'species') + Question(Pos(".")) | \
        (Lemmas("how much") + Lemma("carbs") + Pos("DT") + Group(Pos("NNP"), 'species') + Lemma("have") + Question(Pos("."))) | \
        (Lemma("do") + Group(Pos("NNP"), 'species') + Lemma("have") + Lemma("carbs") + Question(Pos(".")))

    def interpret(self, match):
        name = match.species.tokens
        species = IsSpecies() + HasKeyword(name)
        carbs = CarbsOf(species)
        return carbs, "enum"
Пример #4
0
class FatOfQuestion(QuestionTemplate):
    """
    Regex for questions about the fat in species
    Ex: "How much fat in an apple?"
        "How much fat an Apple have?"
        "Do Apple have fat?"
    """

    regex = Lemmas("how much") + Lemma("fat") + Pos("IN") + Pos("DT") + Group(Pos("NNP"), 'species') + Question(Pos(".")) | \
        (Lemmas("how much") + Lemma("fat") + Pos("DT") + Group(Pos("NNP"), 'species') + Lemma("have") + Question(Pos("."))) | \
        (Lemma("do") + Group(Pos("NNP"), 'species') + Lemma("have") + Lemma("fat") + Question(Pos(".")))

    def interpret(self, match):
        name = match.species.tokens
        species = IsSpecies() + HasKeyword(name)
        fat = FatOf(species)
        return fat, "enum"
Пример #5
0
class GradStudentQuestion(QuestionTemplate):
    """
    Regex for questions about the number of graduate students in a university
    Ex: "How many postgraduate students in York University?"
        "How many post grad students in University of Toronto?"
        "How many post graduate students in University of Toronto?"
        "Number of postgraduate students in York University?"
        "Number of post grad students in Harvard University?"
        "Number of post graduate students in Harvard University?"    
    """

    regex = ((Lemmas("how many")| Lemmas("number of")) + Lemma("postgraduate") + Lemma("student") + Pos("IN") + University() + Question(Pos("."))) | \
        ((Lemmas("how many") | Lemmas("number of")) + Lemma("post") + (Lemma("grad") | Lemma("graduate")) + Lemma("student") + Pos("IN") + University() + Question(Pos(".")))

    def interpret(self, match):
        GradStudent = GradStudentOf(match.university)
        return GradStudent, "literal"
Пример #6
0
class CastOfQuestion(QuestionTemplate):
    """
    Ex: "What is the cast of Friends?"
        "Who works in Breaking Bad?"
        "List actors of Seinfeld"
    """

    regex = (Question(Lemmas("what be") + Pos("DT")) +
             Lemma("cast") + Pos("IN") + TvShow() + Question(Pos("."))) | \
            (Lemmas("who works") + Pos("IN") + TvShow() +
             Question(Pos("."))) | \
            (Lemmas("list actor") + Pos("IN") + TvShow())

    def interpret(self, match):
        cast = CastOf(match.tvshow)
        actor = IsPerson() + IsActorOf(cast)
        name = NameOf(actor)
        return name
Пример #7
0
class ShowsWithQuestion(QuestionTemplate):
    """
    Ex: "List shows with Hugh Laurie"
        "In what shows does Jennifer Aniston appears?"
        "Shows with Matt LeBlanc"
    """

    regex = (Lemmas("list show") + Pos("IN") + Actor()) | \
            (Pos("IN") + (Lemma("what") | Lemma("which")) + Lemmas("show do") +
             Actor() + (Lemma("appear") | Lemma("work")) +
             Question(Pos("."))) | \
            ((Lemma("show") | Lemma("shows")) + Pos("IN") + Actor())

    def interpret(self, match):
        cast = HasActor(match.actor)
        show = IsTvShow() + HasCast(cast)
        show_name = NameOf(show)
        return show_name
Пример #8
0
class WhatIsNamespaceQuestion(QuestionTemplate):
    """
    Ex: "what is the namespace of dcterms?"
    """
    regex = Lemma("what") + Lemma("be") + Lemmas("the namespace") + Pos("IN") + Vocabulary() + Question(Pos("."))

    def interpret(self, match):
        uri = dsl.HasURI(match.vocabulary)
        return uri, "url"
Пример #9
0
class WhereIsHomePageQuestion(QuestionTemplate):
    """
    Ex: "Where to find foaf documentation?"
    """
    regex = Lemmas("where to") + Lemma("find") + Vocabulary() + Lemma("documentation") + Question(Pos("."))

    def interpret(self, match):
        home_uri = dsl.IsHomePageOf(match.vocabulary)
        return home_uri, "url"
class ExamQuestion(QuestionTemplate):
    """
        Ex: "When is the final exam for cmpe 273?"
            "When is the midterm exam for cmpe 273?"
            "What time is the final exam for cmpe 273?"
            "What time is the midterm exam for cmpe 273?"
    """
    opening = Lemmas("what time be") | Lemmas("when be")
    exam = Group(Plus(Lemmas("final exam") | Lemmas("midterm exam")), "exam")
    regex = opening + Question(
        Pos("DT")) + exam + Pos("IN") + Course() + Question(Pos("."))

    def interpret(self, match):
        exam = "The %s" % match.exam.tokens
        answer = exam + " for %s is on %s"
        exam_time = IsExamRelated() + match.course + HasFields(
            match.exam.tokens) + HasAnswer(answer.decode('utf-8'))
        return exam_time
Пример #11
0
class CastOfQuestion(QuestionTemplate):
    """
    Ex: "What is the cast of Friends?"
        "Who works in Breaking Bad?"
        "List actors of Seinfeld"
    """

    regex = (Question(Lemmas("what be") + Pos("DT")) +
             Lemma("cast") + Pos("IN") + TvShow() + Question(Pos("."))) | \
            (Lemmas("who works") + Pos("IN") + TvShow() +
             Question(Pos("."))) | \
            (Lemmas("list actor") + Pos("IN") + TvShow())

    def interpret(self, match):
        tv_show, i, j = match.tvshow
        actor = IsPerson() + StarsIn(tv_show)
        name = LabelOf(actor)
        return name, ReturnValue(i, j)
Пример #12
0
class IngredientOfQuestion(QuestionTemplate):
    """
    Regex for questions about ingredient that uses a species
    Ex: "what type of food uses Apple as ingredient?"
        "what kind of food uses Apple as ingredient?"
        "what food uses Apple as ingredient?"
        "list food uses Apple as ingredient?"
        "food uses Apple as ingredient"
    """

    regex = (Lemmas("what type") | Lemmas("what kind")) + Pos("IN") + Lemma("food") + Lemma("use") + Group(Pos("NNP"), 'species') + Pos("IN") + Lemma("ingredient") + Question(Pos(".")) | \
        (Question((Lemma("list")) | (Lemma("what")))+ Lemma("food") + Lemma("use") + Group(Pos("NNP"), 'species') + Pos("IN") + Lemma("ingredient") + Question(Pos(".")))

    def interpret(self, match):
        name = match.species.tokens
        species = IsSpecies() + HasKeyword(name)
        Ingredient = IngredientOf(species)
        label = NameOf(Ingredient)
        return label, "enum"
Пример #13
0
class VocabCreatorQuestion(QuestionTemplate):
    """
    regex for creators of vocabs.
    Ex: "adms creator"
        "What are the creators of adms?"
        Note: seems not to work. Todo: Fix me
    """
    regex0 = Lemmas("who is") + Lemmas("creator of") + Vocabulary()
    regex1 = Vocabulary() + Lemma("creator")
    regex2 = Lemma("creator") + Pos("IN") + Vocabulary()
    regex3 = Pos("WP") + Lemma("be") + Pos("DT") + Lemma("creator") + \
        Pos("IN") + Vocabulary()

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

    def interpret(self, match):
        creator = dsl.IsCreatorOf(match.vocabulary)
        creator_name = dsl.Name(creator)
        return creator_name, "agent"
Пример #14
0
class MovieFollowsQuestion(QuestionTemplate):
    """
    Ex: sequels of Big Fish
    """
    tellme = Question(
        Lemma("show") | Lemmas("show me") | Lemmas("tell me") | Lemma("list"))
    maybe_the = Question(Lemma("the"))
    sequels = Lemma("spin-off") | Lemma("sequel")

    regex1 = tellme + maybe_the + sequels + Pos("IN") + Movie()

    regex = (regex1) \
            + maybe_dot_or_qmark

    def interpret(self, match):
        movie_name = NameOf(Follows(match.movie))

        print(movie_name)
        return movie_name, "enum"
Пример #15
0
class CreatorOfQuestion(QuestionTemplate):
    """
    Ex: "Who is the creator of Breaking Bad?"
    """

    regex = Question(Lemmas("who be") + Pos("DT")) + \
        Lemma("creator") + Pos("IN") + TvShow() + Question(Pos("."))

    def interpret(self, match):
        creator = CreatorOf(match.tvshow)
        label = LabelOf(creator)
Пример #16
0
class DeathPlaceQuestion(QuestionTemplate):


    regex = Lemmas("where do") + Person() + Lemma("die") + \
        Question(Pos("."))

    def interpret(self, match):
        birth_place = DeathPlace(match.person)
        label = LabelOf(birth_place)

        return label, "enum"
Пример #17
0
class WhoAllFromPlace(QuestionTemplate):
    """
    Ex: "Who all are from Ernakulam?"
    """

    regex = Lemmas("who") + Lemma("all") + Lemma("be") + Lemma(
        "from") + Place() + Question(Pos("."))

    def interpret(self, match):
        people = DefinitionOfFN(match.place)
        return people, "define"
Пример #18
0
class WhereIsFromQuestion(QuestionTemplate):
    """
    Ex: "Where is Bill Gates from?"
    """

    regex = Lemmas("where be") + Person() + Lemma("from") + \
        Question(Pos("."))

    def interpret(self, match):
        place = PlaceOf(match.person)
        return place, "define"
Пример #19
0
class NumberOfRoomsQuestion(QuestionTemplate):
    """
    Regex for questions about the number of rooms in a hotel
    Ex: "How many rooms in Jumeirah Beach Hotel?"
    """
    
    regex = (Lemmas("how many") + Lemma("rooms") + Pos("IN") + Hotel() + Question(Lemma("hotel")) + Question(Pos(".")))
    
    def interpret(self, match):
        Rooms = NumOfRooms(match.hotel)
        return Rooms, "literal"
Пример #20
0
class NumberOfRestaurantsQuestion(QuestionTemplate):
    """
    Regex for questions about the number of restaurants in hotel
    Ex: "How many restaurants in The Peninsula Hong Kong hotel?"
    """
    
    regex = (Lemmas("how many") + Lemma("restaurant") + Pos("IN") + Hotel() + Question(Lemma("hotel")) + Question(Pos(".")))
    
    def interpret(self, match):
        Restaurants = NumOfRestaurants(match.hotel)
        return Restaurants, "literal"
Пример #21
0
class OwnerOfQuestion(QuestionTemplate):
    """
    Regex for questions about the owner of a hotel
    Ex: "who is the owner of Capital Hilton?"
    """
    
    regex = (Lemmas("who be") + Lemma("the") + Lemma("owner") + Pos("IN") + Hotel() + Question(Lemma("hotel")) + Question(Pos("."))) 
    
    def interpret(self, match):
        Owner = OwnerOf(match.hotel)
        return NameOf(Owner), "enum"
Пример #22
0
class WhereIsFromQuestion(QuestionTemplate):
    #Ex: "Where is Bill Gates from?"

    regex = Lemmas("where be") + Person() + Lemma("from") + \
        Question(Pos("."))

    def interpret(self, match):
        birth_place = BirthPlaceOf(match.person)
        label = LabelOf(birth_place)

        return label, "enum"
Пример #23
0
class FloorCountQuestion(QuestionTemplate):
    """
    Regex for questions about the number of floors in a hotel
    Ex: "How many floors in The Peninsula New York hotel?"
    """
    
    regex = (Lemmas("how many") +  Lemma("floor") + Pos("IN") + Hotel() + Question(Lemma("hotel")) + Question(Pos(".")))
    
    def interpret(self, match):
        FloorCount = FloorCountOf(match.hotel)
        return FloorCount, "literal"
Пример #24
0
class HowOldIsQuestion(QuestionTemplate):
    """
    Ex: "How old is Bob Dylan".
    """

    regex = Lemmas("when be") + Person() + Lemma("born") +\
        Question(Pos("."))

    def interpret(self, match):
        birth_date = BirthDateOf(match.person)
        return birth_date, "age"
Пример #25
0
class ListTvShows(QuestionTemplate):
    """
    Ex: "List TV shows"
    """

    regex = Lemmas("list tv show")

    def interpret(self, match):
        show = IsTvShow()
        label = LabelOf(show)
        return label, "enum"
Пример #26
0
class ReleaseDateQuestion(QuestionTemplate):
    """
    Ex: when was Friends released?
    """

    regex = Lemmas("when be") + TvShow() + Lemma("release") + \
        Question(Pos("."))

    def interpret(self, match):
        release_date = ReleaseDateOf(match.tvshow)
        return release_date, "literal"
Пример #27
0
class LocationOfQuestion(QuestionTemplate):
    """
    Ex: "where in the world is the Eiffel Tower"
        "Where is Jumeirah Beach Hotel?"
        "Where is the location of Marriott London Park Lane?"
        "Show me the location of Jumeirah Beach Hotel?"
        "Give me the location of Jumeirah Beach Hotel?"
    """


    regex = Lemma("where") + Question(Lemmas("in the world")) + Lemma("be") + Question(Pos("DT")) + Thing() + Question(Pos(".")) | \
        (Lemma("where") + Lemma("be") + Thing() + Question(Pos("."))) | \
        (Question(Lemmas("where be")) + Lemma("the") + Lemma("location") + Pos("IN") + Thing() + Question(Pos("."))) | \
        (Question(Lemma("show")|Lemma("give")) + Lemma("me") + Lemma("the") + Lemma("location") + Pos("IN") + Thing() + Question(Pos(".")))

    def interpret(self, match):
        location = LocationOf(match.thing)
        location_name = NameOf(location)

        return location_name, "enum"
Пример #28
0
class WhatIsTitleQuestion(QuestionTemplate):
    """
    Ex: "What is the title of dcterms?"
    """
    regex1 = Lemma("what") + Lemma("be") + Lemmas("the title") + Pos("IN") + Vocabulary()
    regex2 = Vocabulary() + Lemma("title")

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

    def interpret(self, match):
        title = dsl.TitleOf(match.vocabulary)
        return title, "enum"
Пример #29
0
class HowManyVocabQuestion(QuestionTemplate):
    """
    regex for reusing vocabs.
    Ex: "how many vocabularies reuse adms?"
    """
    regex1 = Lemmas("how many") + (Lemma("vocabularies") | Lemma("vocabulary")) + Lemma("reuse") + Vocabulary()

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

    def interpret(self, match):
        number = dsl.ReuseVocab(match.vocabulary)
        return number, "literal"
Пример #30
0
class WhereIsQuestion(QuestionTemplate):
    """
    Ex: "where in the world is the Eiffel Tower"
    """

    regex = Lemma("where") + Question(Lemmas("in the world")) + Lemma("be") + \
        Question(Pos("DT")) + Thing() + Question(Pos("."))

    def interpret(self, match):
        location = LocationOf(match.thing)
        location_name = NameOf(location)
        return location_name