Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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"
Ejemplo n.º 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