예제 #1
0
파일: basic.py 프로젝트: papabalda/stibd
class HowIsRepresented(QuestionTemplate):
    """
    Regex for questions like "How is represented an entity?
    Ex: "How is represented an entity"
    """
	#print Lemma("represented")
    regex = Pos("WRB") + Token("is") + Token("represented") + Question(Pos("DT")) + \
        Thing() + Question(Pos("."))

    def interpret(self, match):
        label = IsRepresented(match.thing)
		#rep = LabelOf(label)
        return label, "define"		
예제 #2
0
파일: basic.py 프로젝트: papabalda/stibd
class WhatContains(QuestionTemplate):
    """
    Regex for questions like "What does a multivalued_attribute contains?
    Ex: "What is a car"
        "What is Seinfield?"
    """

    regex = Lemma("what") + Token("does") + Question(Pos("DT")) + \
        Thing() + Token("contains") + Question(Pos("."))

    def interpret(self, match):
        label = Contains(match.thing)

        return label, "define"	
예제 #3
0
파일: basic.py 프로젝트: papabalda/stibd
class WhatDefines(QuestionTemplate):
    """
    Regex for questions like "What does define a entity_relationship_model?
    Ex: "What does define a entity_relationship_model?"
        "What is Seinfield?"
    """

    regex = Lemma("what") + Token("does") + Token("define") + Question(Pos("DT")) + \
        Thing() + Question(Pos("."))

    def interpret(self, match):
        label = Defines(match.thing)

        return label, "define"	
예제 #4
0
class PopulationOfQuestion(QuestionTemplate):
    """
    Regex for questions about the population of a country.
    Ex: "What is the population of China?"
        "How many people live in China?"
    """

    openings = (Pos("WP") + Token("is") + Pos("DT") +
                Lemma("population") + Pos("IN")) | \
               (Pos("WRB") + Lemma("many") + Lemma("people") +
                Token("live") + Pos("IN"))
    regex = openings + Question(Pos("DT")) + Country() + Question(Pos("."))

    def interpret(self, match):
        population = PopulationOf(match.country)
        return population, "literal"
예제 #5
0
class test(QuestionTemplate):
    """

    """
    regex = Token('hello')

    def interpret(self, match):
        print 'parsed'
        return
예제 #6
0
class LanguageOfQuestion(QuestionTemplate):
    """
    Regex for questions about the language spoken in a country.
    Ex: "What is the language of Argentina?"
        "what language is spoken in Argentina?"
    """

    openings = (Lemma("what") + Token("is") + Pos("DT") +
                Question(Lemma("official")) + Lemma("language")) | \
               (Lemma("what") + Lemma("language") + Token("is") +
                Lemma("speak"))

    regex = openings + Pos("IN") + Question(Pos("DT")) + Country() + \
        Question(Pos("."))

    def interpret(self, match):
        language = LanguageOf(match.country)
        return language, "enum"
예제 #7
0
class IsCapitalOfQuestion(QuestionTemplate):

    regex = Token("is") + Capital() + Pos("DT") + Lemma("capital") + Pos("IN") + \
            Question(Pos("DT")) + Country() + Question(Pos("."))

    def interpret(self, match):
        capital = CapitalOf(match.country)
        label = LabelOf(capital)
        return label, "enum"
예제 #8
0
class WhatTimeIs(QuestionTemplate):
    """
    Regex for questions about the time
    Ex: "What time is it in Cordoba"
    """

    nouns = Plus(Pos("NN") | Pos("NNS") | Pos("NNP") | Pos("NNPS"))
    place = Group(nouns, "place")
    openings = (Lemma("what") +
        ((Token("is") + Token("the") + Question(Lemma("current")) +
        Question(Lemma("local")) + Lemma("time")) |
        (Lemma("time") + Token("is") + Token("it")))) | \
               Lemma("time")
    regex = openings + Pos("IN") + place + Question(Pos("."))

    def interpret(self, match):
        place = HasKeyword(match.place.lemmas.title()) + IsPlace()
        utc_offset = UTCof(place)

        return utc_offset, "time"
class PresidentOfQuestion(QuestionTemplate):
    """
    Regex for questions about the president of a country.
    Ex: "Who is the president of Argentina?"
    """

    regex = Pos("WP") + Token("is") + Question(Pos("DT")) + \
        Lemma("president") + Pos("IN") + Country() + Question(Pos("."))

    def interpret(self, match):
        definition = ToGenerate(match.country)
        return definition, "presidentofquestion"
예제 #10
0
class NationalTree(QuestionTemplate):
    """
        Regex for What is National Tree of India?
    """
    regex1 = Pos('WP') + Token('is')
    regex2 = Pos('NNP') + Lemma('tree') + Pos('IN') + Country()
    regex = regex1 + regex2 | regex1 + regex2 + Pos(
        '.') | regex2 | regex2 + Pos('.')

    def interpret(self, match):
        print 'parsed NationalTree'
        return
예제 #11
0
class WhatIsTime(QuestionTemplate):
    """
    Regex for What is time in India?
    """
    regex1 = Pos('WP') + Token('is')
    regex2 = Lemma('time') + Pos('IN') + Country()
    regex = regex1 + regex2 | regex2 | regex2 + Pos(
        '.') | regex1 + regex2 + Pos('.')

    def interpret(self, match):
        print 'parsed WhatIsTime'
        return
예제 #12
0
class WhatIsGDP(QuestionTemplate):
    """
    Regex for what is GDP of India?
    """
    regex1 = Pos('WP') + Token('is')
    regex2 = Lemma('GDP') + Pos('IN') + Country()
    regex = regex1 + regex2 + Pos('.') | regex2 | regex2 + Pos(
        '.') | regex1 + regex2

    def interpret(self, match):
        print 'parsed WhatIsGDP'
        return
예제 #13
0
class AreaofCountry(QuestionTemplate):
    """
    Regex for What is the Area of India?
    """
    regex1 = Pos('WP') + Token('is') + Pos('DT')
    regex2 = Lemma('area') + Pos('IN') + Country()
    regex = regex1 + regex2 | regex1 + regex2 + Pos(
        '.') | regex2 | regex2 + Pos('.')

    def interpret(self, match):
        print 'Parsed AreaOfCountry'
        return
예제 #14
0
class PresidentOfQuestion(QuestionTemplate):
    """
    Regex for questions about the president of a country.
    Ex: "Who is the president of Argentina?"
    """

    regex = Pos("WP") + Token("is") + Question(Pos("DT")) + \
        Lemma("president") + Pos("IN") + Country() + Question(Pos("."))

    def interpret(self, match):
        president = PresidentOf(match.country)
        label = LabelOf(president)
        return label, "enum"
예제 #15
0
class CapitalOfQuestion(QuestionTemplate):
    """
     "What is the capital of Bolivia?"
    """

    opening = Lemma("what") + Token("is")
    regex = opening + Pos("DT") + Lemma("capital") + Pos("IN") + \
        Question(Pos("DT")) + Country() + Question(Pos("."))

    def interpret(self, match):
        capital = CapitalOf(match.country)
        label = LabelOf(capital)
        return label, "enum"
예제 #16
0
class CapitalOfQuestion(QuestionTemplate):
    """
    Regex for questions about the capital of a country.
    Ex: "What is the capital of Massachussets?"
    """

    opening = Lemma("what") + Token("is")
    regex = opening + Pos("DT") + Lemma("capital") + Pos("IN") + \
        Question(Pos("DT")) + PopulatedPlace() + Question(Pos("."))

    def interpret(self, match):
        capital = CapitalOf(match.populatedplace)
        label = LabelOf(capital)
        return label, "enum"
예제 #17
0
class LanguageOfQuestion(QuestionTemplate):
    """
    Regex for questions about the language spoken in a country.
    Ex: "What is the language of Argentina?"
        "what language is spoken in Argentina?"
        "laguage of India?"
        "India Language?"
    """

    openings = (Lemma("what") + Token("is") + Pos("DT") +
                Question(Lemma("official")) + Lemma("language")) + Pos('IN') | \
               (Lemma("what") + Lemma("language") + Token("is") + \
                Lemma("speak")) + Pos('IN')
    country_language = Country() + Lemma('language')
    language_of_country = Lemma('language') + Pos('IN') + Country()
    regex = openings + Country() | openings + Country() + Question(Pos(".")) | \
            country_language | country_language + question_mark | language_of_country | \
            language_of_country + question_mark

    def interpret(self, match):
        language = LanguageOf(match.country)
        label = LabelOf(language)
        return label, "enum"
예제 #18
0
class CapitalOfQuestion(QuestionTemplate):
    """
    Regex for questions about the capital of a country.
    Ex: "What is the capital of Bolivia?"
    """

    opening = Lemma("what") + Token("is")
    regex = opening + Pos("DT") + Lemma("capital") + Pos("IN") + \
        Question(Pos("DT")) + Country() + Question(Pos("."))

    def interpret(self, match):
        _country, i, j = match.country
        capital = CapitalOf(_country)
        label = NameOf(capital)
        return label, ReturnValue(i, j)
예제 #19
0
class PersonSpouse(QuestionTemplate):
    """
    Regex for who is spouse of Narendra Modi?
    Ex :
    Narendra Modi spouse - regex3
    wife of Narendra Modi
    """
    regex1 = Pos('WP') + Token('is')
    regex2 = Lemma('spouse') + Pos('IN') + Person()
    regex = regex1 + regex2 + Pos('.') | regex2 | regex2 + Pos(
        '.') | regex1 + regex2

    def interpret(self, match):
        print 'parsed PersonSpous'
        return
예제 #20
0
class PopulationOfQuestion(QuestionTemplate):
    """
    Regex for questions about the population of a country.
    Ex: "What is the population of China?"
        "How many people live in China?"
        TO DO
        "What is country population"
        "country population"
        "population country"
    """
    what_is = Pos('WP') + Token('is')
    openings =  Pos("DT") + Lemma("population") + Pos("IN") | \
               (Pos("WRB") + Lemma("many") + Lemma("people") + \
                Token("live") + Pos("IN")) | \
               (Token("population") + Pos("IN"))

    regex = what_is + openings + Country() | what_is + openings + Country() + question_mark | \
            Country() + Lemma('population') + question_mark | (Country() + Lemma('population'))

    # openings + Country() + Question(Pos("."))

    def interpret(self, match):
        population = PopulationOf(match.country)
        return population, "literal"
예제 #21
0
class PlaceOfCountry(QuestionTemplate):
    """
    TODO Place defination
    Regex for question like where is Place?
        Ex: "where is Agra?"
            "Agra Location?"
    """
    regex1 = Pos('WRB') + Token("is") + Pos('VBZ')
    country_s = Country() + Pos('POS') + Lemma('area')
    regex = regex1 | regex1 + Pos(".") | Pos('NNP') + Lemma('location') | \
            country_s | country_s + question_mark

    def interpret(self, match):
        print 'parsed PlaceOfCountry'
        return
예제 #22
0
class CurrencyofQuestion(QuestionTemplate):
    """
    Regex for questions about currency of a country.
        Ex: "what is the currency of India?"
            "Currency of India?"
            "India Currency?"
    """

    what_is_opening = Pos('WP') + Token("is") + Question(Pos("DT"))
    currency_of_country = Lemma('currency') + Pos('IN') + Country()
    regex = what_is_opening + currency_of_country + question_mark| currency_of_country + question_mark | \
            what_is_opening + currency_of_country | currency_of_country

    def interpret(self, match):
        currency = CurrencyOf(match.country)
        label = LabelOf(currency)
        return label, "enum"
예제 #23
0
class PresidentOfQuestion(QuestionTemplate):
    """
    Regex for questions about the president of a country.
    Ex: "Who is the president of Argentina?"
    """
    default = Pos("WP") + Token("is") + Question(Pos("DT")) + \
              Lemma("president") + Pos("IN") + Country()
    president_country = Lemma('president') + Pos('IN') + Country()
    country_president = Country() + Lemma('president')
    regex = default | default + Question(Pos(".")) | president_country | \
            president_country + question_mark | country_president | country_president + question_mark

    def interpret(self, match):
        president = PresidentOf(match.country)
        incumbent = IncumbentOf(president)
        label = LabelOf(incumbent)
        pronouns.fetchHisFromAnswers = True
        return label, "enum"
예제 #24
0
class WhatisHiredate(QuestionTemplate):
    '''
        Regex for questions like: [What is <target> hiredate?]
        ex: What is Heidi hiredate? # The questions are with respect to the mock data table
    '''

    regex = Lemma("what") + Lemma("be") + Group(
        Pos("NNP"), "target") + Token("hiredate") + Question(Pos("."))
    print "Qustion template: What <is / are> <person> hiredate?"

    def interpret(self, match):
        employee_name = match.target.tokens

        # reset the HasKeyword relation
        HasKeyword.relation = "proatt:firstname"
        emp_id = HasKeyword(employee_name)

        solution = Hiredate(emp_id)

        return solution
예제 #25
0
class CapitalOfQuestion(QuestionTemplate):
    """
    TO DO
    Regex for questions about the capital of a country.
    Ex: "What is the capital of Bolivia?"
        "Capital of India?"
        "India capital?"
    """

    opening = Pos('WP') + Token("is")
    capital_country = Lemma('capital') + Pos('IN') + Country()
    country_capital = Country() + Lemma('capital')
    regex = opening + Pos("DT") + capital_country + question_mark | \
            opening + Pos("DT") + capital_country | capital_country | (capital_country + question_mark) | \
            country_capital | (country_capital + question_mark)

    def interpret(self, match):
        capital = CapitalOf(match.country)
        label = LabelOf(capital)
        pronouns.fetchItsFromAnswers = True
        return label, "enum"
예제 #26
0
class GroundOfQuestion(QuestionTemplate):
    """
        Regex for questions about club grounds.
        Ex: "Which is the ground of Barcelona?"
            "Which is the stadium of Porto?"
        """

    opening = Lemma("which") + Token("is")

    regex1 = opening + Pos("DT") + Lemma("ground") + Pos("IN") + \
        Question(Pos("DT")) + Team()

    regex2 = opening + Pos("DT") + Lemma("stadium") + Pos("IN") + \
        Question(Pos("DT")) + Team()

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

    def interpret(self, match):
        ground = IsStadium() + GroundOf(match.team)
        ground_name = NameOf(ground)
        return ground_name, "literal"
예제 #27
0
# coding: utf-8
"""
Files queries for nova quepy.
"""
from quepy.parsing import Lemma, Pos, QuestionTemplate, Particle, Token, Match, Lemmas, Tokens
from refo import Group, Question, Plus, Literal, Predicate, patterns
from dsl import IsError, ErrorIdOf, HasErrorTip, HasErrorCause, IsFile, FileOf, FileExtensionOf, FileLocation

error_tokens = Token("ORA00942") | Token("ORA01034") | Token("ORA12514") | Token("ORA12541") \
               | Token("ORA12543") + Token("ORA28000") + Token("ORA01652") | Token("ORA12502")
file_tokens = Tokens("listener")
extension_tokens = Token("ora")


class WhatIsFile(QuestionTemplate):
    """
    Regex for questions like

    What is Listener.ora (?file)? -- ok
    What is the meaning of Listener.ora (?file)? -- ok
    """

    target = Group(file_tokens, "target_file_name") + Group(
        extension_tokens, "target_file_extension")

    regex = Lemma("what") + Lemma("be") + Question(Pos("DT") + Lemma("meaning") + Pos("IN")) + target + \
            Question(Pos("."))

    def interpret(self, match):

        name = match.target_file_name.tokens
예제 #28
0
class UserData(QuestionTemplate):
    weight = 1.0
    regex = Token("user") + Token("data")

    def interpret(self, match):
        return HasKeyword(match.words[0].token), "<user data>"