class WhatIsBand(QuestionTemplate): regex = (Lemma("what") + Lemma("is") + Lemma("band") + Band()) | (Lemma("band") + Band()) def interpret(self, match): _band, i, j = match.band return _band + HasId(), ReturnValue(i, j)
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"
class WhatIsMovie(QuestionTemplate): regex = (Lemma("what") + Lemma("is") + Lemma("movie") + Movie()) | (Lemma("movie") + Movie()) def interpret(self, match): _movie, i, j = match.movie return _movie + HasId(), ReturnValue(i, j)
class MovieReleaseDateQuestion(QuestionTemplate): """ Ex: "When was The Red Thin Line released?" "Release date of The Empire Strikes Back" """ prob_threshold = 0.95 tables = ["movies"] examples = [ "When was The Red Thin Line released?", "Release date of The Empire Strikes Back" ] regex = ((Lemmas("when be") + Movie() + Lemma("release")) | (Lemma("release") + Question(Lemma("date")) + Pos("IN") + Movie())) + \ Question(Pos(".")) def interpret(self, match): release_date = ReleaseDateOf(match.movie) release_date.tables = ["movies"] movie_name = ''.join(match.movie.nodes[0][1][1].split('"')[:-1]) release_date.nodes = [u' title like "' + movie_name + '"'] release_date.head = u"year" return release_date, ("literal", "MovieReleaseDateQuestion")
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"
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"
class WhatIsBook(QuestionTemplate): regex = (Lemma("what") + Lemma("is") + Lemma("book") + Book()) | (Lemma("book") + Book()) def interpret(self, match): _book, i, j = match.book return _book + HasId(), ReturnValue(i, j)
class WhatCategory(QuestionTemplate): """ Ex: "What is the category of foaf?" """ regex = Lemma("what") + Lemma("be") + Lemma("the") + Lemma("category") + Pos("IN") + Vocabulary() + Question(Pos(".")) def interpret(self, match): category = dsl.HasCategory(match.vocabulary) return category, "category"
class HowOldIsQuestion(QuestionTemplate): """ Ex: "How old is dcterms". """ regex = Pos("WRB") + Lemma("old") + Lemma("be") + Vocabulary() + Question(Pos(".")) def interpret(self, match): birth_date = dsl.ReleaseDateOf(match.vocabulary) return birth_date, "age"
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 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"
class WhatPilot(QuestionTemplate): """ Ex: "What is the pilot of foaf?" """ regex = Lemma("what") + Lemma("be") + Lemma("the") + Lemma("pilot") + Pos("IN") + Vocabulary() + Question(Pos(".")) def interpret(self, match): pilot = dsl.HasPilot(match.vocabulary) return pilot, "pilot"
class WhoIs(QuestionTemplate): #Ex: "Who is Tom Cruise?" regex = Lemma("who") + Lemma("be") + Person() + \ Question(Pos(".")) def interpret(self, match): definition = DefinitionOf(match.person) return definition, "define"
class ConflictThatTookPlaceInCountry(QuestionTemplate): regex = Question(Lemma("list")) + (Lemma("conflict")) + (Pos("IN")| Pos("WP") | Pos("WDT")) + \ Lemma("take") + Lemma("place") + Pos("IN") + Location() def interpret(self, match): _location, i, j = match.location _military_conflict = IsMilitaryConflict() rezultat = DefinitionOf(_military_conflict + IsEvent(_location)) return rezultat, ReturnValue(i, j)
class WhatIs(QuestionTemplate): target = Question(Pos("DT")) + Group(Pos("NN"), "target") regex = Lemma("what") + Lemma("be") + target + Question(Pos(".")) def interpret(self, match): thing = match.target.tokens target = HasKeyword(thing) definition = DefinitionOf(target) return definition, "define"
class BirthdayQuestion(QuestionTemplate): """When was Bill Gates born?""" regex = Pos("WRB") + Lemma("be") + Person() + Lemma("born") + \ Question(Pos(".")) def interpret(self, match): birth_date = BirthDateOf(match.person) return birth_date, "literal"
class HowOldIsQuestion(QuestionTemplate): #Ex: "How old is Bob Dylan". regex = Pos("WRB") + Lemma("old") + Lemma("be") + Person() + \ Question(Pos(".")) def interpret(self, match): birth_date = BirthDateOf(match.person) return birth_date, "age"
class HowOldIs(QuestionTemplate): """ Ex: "How old is Tom Cruise?" """ regex = Pos("WRB") + Lemma("old") + Lemma("be") + Person() + Question( Pos(".")) def interpret(self, match): definition = ToGenerate(match.person) return definition, "howoldis"
class PlacesNearPlace(QuestionTemplate): """ Ex: "List Places near Ernakulam?" """ regex = Lemma("list") + Lemma("place") + Lemma( "near") + Place() + Question(Pos(".")) def interpret(self, match): place = PlaceOf(match.place) return place, "define"
class ActorsOfQuestion(QuestionTemplate): """ Ex: "who are the actors of Titanic?" # ok "who acted in Alien?" # ok "who starred in Depredator?" # ok "who starred in Depredator" # ok "actors of Fight Club" # ok list actors of Mulan """ who = Lemma("who") act_verb = (Lemma("star") | Lemma("act") | Lemma("feature")) actor = (Lemma("actor") | Lemma("actors")) maybe_list = Question(Lemma("list")) regex1 = who + Lemma("be") + Pos("DT") + Lemma("actor") + Pos( "IN") + Movie() regex2 = who + act_verb + Pos("IN") + Movie() regex3 = maybe_list + actor + Pos("IN") + Movie() regex = (regex1 | regex2 | regex3) \ + maybe_dot_or_qmark def interpret(self, match): actor = NameOf(IsPerson() + StarsIn(match.movie)) print(actor) return actor, "enum"
class WhenIsDead(QuestionTemplate): """ Ex: 'Death date of Tom Cruise?' """ regex = Lemma("death") + Lemma("date") + Pos("IN") + Person() + Question( Pos(".")) def interpret(self, match): death_date = DeathDateOf(match.person) return death_date, "date"
class WhenIsBorn(QuestionTemplate): """ Ex: 'Birth date of Tom Cruise?' """ regex = Lemma("birth") + Lemma("date") + Pos("IN") + Person() + Question( Pos(".")) def interpret(self, match): birth_date = BirthDateOf(match.person) return birth_date, "date"
class ListMoviesQuestion(QuestionTemplate): """ Ex: "list movies" """ regex = Lemma("list") + (Lemma("movie") | Lemma("film")) def interpret(self, match): movie = IsMovie() name = NameOf(movie) return name, "enum"
class PoliticiansFromCountry(QuestionTemplate): """ Ex: "List politicians that are from France" """ regex = Question(Lemma("list")) + (Lemma("politician") | Lemma("politicians")) + ( Pos("IN") | Pos("WP") | Pos("WDT")) + Lemma("be") + Pos("IN") + Location() def interpret(self, match): _location, i, j = match.location result = IsPerson() + IsPolitician() + _location + HasId() return result, ReturnValue(i, j)
class WhoAreChildrenOfQuestion(QuestionTemplate): """ EX: "Who are the children's of Bill Gates" """ regex = Lemma("who") + Lemma("be") + Pos("DT") + Lemma("child") + Pos("IN") + Person() + \ Question(Pos(".")) | Lemma("child") + Pos("IN") + Person() + Question(Pos(".")) def interpret(self, match): _person, i, j = match.person child_name = HasChild(_person) return child_name, ReturnValue(i, j)
class WhoIs(QuestionTemplate): """ Ex: "Who is Tom Cruise?" """ regex = Lemma("who") + Lemma("be") + Person() + \ Question(Pos(".")) def interpret(self, match): definition = ToGenerate(match.person) return definition, "whois"
class WhenBornQuestion(QuestionTemplate): """ Ex: "When was Bob Dylan born?". """ regex = Pos("WRB") + Lemma("be") + Person() + Lemma("born") + \ Question(Pos(".")) def interpret(self, match): birth_date = BirthDateOf(match.person) return birth_date
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"
class CapitalOf(QuestionTemplate): """ Ex: "What is the capital of France?" """ regex = Lemma("what") + Lemma("be") + Pos("DT") + Lemma("capital") + Pos( "IN") + Country() + Question(Pos(".")) def interpret(self, match): definition = ToGenerate(match.country) return definition, "capital"
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"