# Copyright (c) 2012, Machinalis S.R.L. # This file is part of quepy and is distributed under the Modified BSD License. # You should have received a copy of license in the LICENSE file. # # Authors: Rafael Carrascosa <*****@*****.**> # Gonzalo Garcia Berrotaran <*****@*****.**> """ Writers related regex. """ from refo import Plus, Question from quepy.dsl import HasKeyword from quepy.parsing import Lemma, Lemmas, Pos, QuestionTemplate, Particle from dsl import IsBook, HasAuthor, AuthorOf, IsPerson, NameOf nouns = Pos("DT") | Pos("IN") | Pos("NN") | Pos("NNS") | Pos("NNP") | Pos( "NNPS") class Book(Particle): regex = Plus(nouns) def interpret(self, match): name = match.words.tokens return IsBook() + HasKeyword(name) class Author(Particle): regex = Plus(nouns | Lemma(".")) def interpret(self, match):
class Country(Particle): regex = Plus(Pos("DT") | Pos("NN") | Pos("NNS") | Pos("NNP") | Pos("NNPS")) def interpret(self, match): name = match.words.tokens.title() return IsCountry() + HasKeyword(name)
class MilitaryConflict(Particle): regex = Question(Pos("DT")) + nouns def interpret(self, match): name = match.words.tokens return IsMilitaryConflict() + LabelOfFixedDataRelation(name)
class Person(Particle): regex = Plus(Pos("NN") | Pos("NNS") | Pos("NNP") | Pos("NNPS")) def interpret(self, match): name = match.words.tokens return IsPerson() + HasKeyword(name)
class SongsAboutStuffQuestion(QuestionTemplate): """ Ex: "List songs about love" "Songs about love" """ regex = (Question(Lemma("list")) + (Lemma("song") | Lemma("songs") | Lemma("track")) + Pos("IN") + Topic()) | ( Topic() + Lemma("song")) def interpret(self, match): _song, i, j = match.topic return IsAlbum() + TrackList(_song + HasId()), ReturnValue(i, j)
class EducationInstitution(Particle): regex = Plus(Pos("DT") | Pos("IN") | nouns) def interpret(self, match): name = match.words.tokens.title() return IsEducation() + InstitutionEducation(HasName(name) + HasId())
class Location(Particle): regex = Plus(Pos("DT") | nouns) def interpret(self, match): name = match.words.tokens.title() return IsLocation() + HasKeyword(name)
class Movie(Particle): regex = Question(Pos("DT")) + nouns def interpret(self, match): name = match.words.tokens return IsMovie() + HasName(name)
class YearAf(Particle): regex = Pos("CD") def interpret(self, match): year = match.words.tokens return IsAfterYear(year)
class SongLength(Particle): regex = Pos("CD") def interpret(self, match): length = match.words.tokens return TrackLengthHigh("\"" + length + "\"")
class Topic(Particle): regex = Pos("IN") | Pos("JJ") | Pos("NN") | Pos("NNP") | Pos("NNS") def interpret(self, match): name = match.words.tokens.title() return NameApproximation(name + u"*")
class BandName(Particle): regex = Plus(Pos("DT") | Pos("POS") | Pos("NN") | Pos("NNP") | Pos("NNS")) def interpret(self, match): name = match.words.tokens.title() return AlbumArtist(name)
class SongsAboutStuffWrittenByPersonQuestion(QuestionTemplate): """ Ex: "List songs about love" "Songs about love" """ regex = Question(Lemma("list")) + (Lemma("song") | Lemma("songs") | Lemma("track")) + Pos("IN") + Topic() + ( Lemma("write") + Lemma("by") | Lemma("by") | Lemma("from")) + BandName() def interpret(self, match): _song, i, j = match.topic _artist, i, j = match.bandname rezultat = _artist + PrimaryRelease(TrackList(HasId() + _song)) return rezultat, ReturnValue(i, j)
class Band(Particle): regex = Question(Pos("DT")) + Plus(Pos("NN") | Pos("NNP")) def interpret(self, match): name = match.words.tokens.title() return IsBand() + HasKeyword(name)
class TvShow(Particle): regex = Plus(Question(Pos("DT")) + nouns) def interpret(self, match): name = match.words.tokens return IsTvShow() + HasName(name)
# You should have received a copy of license in the LICENSE file. # # Authors: Rafael Carrascosa <*****@*****.**> # Gonzalo Garcia Berrotaran <*****@*****.**> """ Movie related regex. """ from refo import Plus, Question from quepy.dsl import HasKeyword from quepy.parsing import Lemma, Lemmas, Pos, QuestionTemplate, Particle from dsl import IsMovie, NameOf, IsPerson, \ DirectedBy, LabelOf, DurationOf, HasActor, HasName, ReleaseDateOf, \ DirectorOf, StarsIn, DefinitionOf nouns = Plus(Pos("NN") | Pos("NNS") | Pos("NNP") | Pos("NNPS")) class Movie(Particle): regex = Question(Pos("DT")) + nouns def interpret(self, match): name = match.words.tokens return IsMovie() + HasName(name) class Actor(Particle): regex = nouns def interpret(self, match): name = match.words.tokens
class MilitaryConflict(Particle): regex = Question(Pos("DT")) + Plus(nouns | Pos("IN")) def interpret(self, match): name = match.words.tokens return IsMilitaryConflict() + HasName(name)
class Thing(Particle): regex = Question(Pos("JJ")) + (Pos("NN") | Pos("NNP") | Pos("NNS")) |\ Pos("VBN") def interpret(self, match): return HasKeyword(match.words.tokens)
class Album(Particle): regex = Plus(Pos("NN") | Pos("NNPS") | Pos("DT") | Pos("NNP")) def interpret(self, match): name = match.words.tokens.title() return IsAlbum() + HasName(name)