Beispiel #1
0
# 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):
Beispiel #2
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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())
Beispiel #7
0
class Location(Particle):
    regex = Plus(Pos("DT") | nouns)

    def interpret(self, match):
        name = match.words.tokens.title()
        return IsLocation() + HasKeyword(name)
Beispiel #8
0
class Movie(Particle):
    regex = Question(Pos("DT")) + nouns

    def interpret(self, match):
        name = match.words.tokens
        return IsMovie() + HasName(name)
Beispiel #9
0
class YearAf(Particle):
    regex = Pos("CD")

    def interpret(self, match):
        year = match.words.tokens
        return IsAfterYear(year)
Beispiel #10
0
class SongLength(Particle):
    regex = Pos("CD")

    def interpret(self, match):
        length = match.words.tokens
        return TrackLengthHigh("\"" + length + "\"")
Beispiel #11
0
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"*")
Beispiel #12
0
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)
Beispiel #13
0
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)
Beispiel #14
0
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)
Beispiel #15
0
class TvShow(Particle):
    regex = Plus(Question(Pos("DT")) + nouns)

    def interpret(self, match):
        name = match.words.tokens
        return IsTvShow() + HasName(name)
Beispiel #16
0
# 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
Beispiel #17
0
class MilitaryConflict(Particle):
    regex = Question(Pos("DT")) + Plus(nouns | Pos("IN"))

    def interpret(self, match):
        name = match.words.tokens
        return IsMilitaryConflict() + HasName(name)
Beispiel #18
0
class Thing(Particle):
    regex = Question(Pos("JJ")) + (Pos("NN") | Pos("NNP") | Pos("NNS")) |\
            Pos("VBN")

    def interpret(self, match):
        return HasKeyword(match.words.tokens)
Beispiel #19
0
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)