machinalis / quepy

A python framework to transform natural language questions to queries in a database query language.
Other
1.25k stars 296 forks source link

Conflicting queries #23

Closed iScienceLuvr closed 8 years ago

iScienceLuvr commented 9 years ago

I have been adding functions to, for example, ask the release date of a song. However, there are TWO other functions for this, except for different domains, movies and TV shows. How can we deal with this? Can you add some function that can determine whether the movies query yields no results, so try the TV show query, then the song query? Or is there a way to show all query results?

iScienceLuvr commented 8 years ago

It seems nobody has seen this thread? @j0hn @rafacarrascosa etc. have you seen?

rafacarrascosa commented 8 years ago

@iScienceLuvr I'm really sorry for taking so long to answer :S

You can use the QuepyApp.get_queries method to iterate over all interpretations of a question and then implement whatever policy you want in case more than two queries match.

You might want to checkout this option too to choose the preference between question templates (templates are tried in order, from higher weight to lower), this could help to implement simpler policies in case more than two question templates match.

Cheers!

iScienceLuvr commented 8 years ago

@rafacarrascosa is there docs for both of these functions? I am not understanding how to use them.

rafacarrascosa commented 8 years ago

Kind of...

For get_queries: You have the docstrings and a use case for it's sister function get_query on main.py.

For weight: It's not documented, but is simple to use:

class FoundationQuestion(QuestionTemplate):
    """
    Regex for questions about the creation of a band.
    Ex: "When was Pink Floyd founded?"
        "When was Korn formed?"
    """

    weight = 1.5  # By default is 1, so this template is used before all others

    regex = Pos("WRB") + Lemma("be") + Band() + \
        (Lemma("form") | Lemma("found")) + Question(Pos("."))

    def interpret(self, match):
        active_years = ActiveYears(match.band)
        return active_years, "literal"

You can add weight as shown above, if you don't it will be 1 by default.

iScienceLuvr commented 8 years ago

@rafacarrascosa ah, so I use get_queries instead of get_query in main.py and it will do all three?

rafacarrascosa commented 8 years ago

@iScienceLuvr list(get_queries(question)) if a list in which get_query(question) is the first element. So if you replace that in main.py you should put everything below that line in a for loop, so that you can print all interpretations to the question.

Try playing with it for a while, perhaps in the python interpreter or a in a ipython notebook to get the hang of it.

iScienceLuvr commented 8 years ago

@rafacarrascosa thanks! you can close