A python framework to transform natural language questions to queries in a database query language.

Overview
  __ _ _   _  ___ _ __  _   _
 / _` | | | |/ _ \ '_ \| | | |
| (_| | |_| |  __/ |_) | |_| |
 \__, |\__,_|\___| .__/ \__, |
    |_|          |_|    |___/

What's quepy?

Quepy is a python framework to transform natural language questions to queries in a database query language. It can be easily customized to different kinds of questions in natural language and database queries. So, with little coding you can build your own system for natural language access to your database.

Currently Quepy provides support for Sparql and MQL query languages. We plan to extended it to other database query languages.

An example

To illustrate what can you do with quepy, we included an example application to access DBpedia contents via their sparql endpoint.

You can try the example online here: Online demo

Or, you can try the example yourself by doing:

python examples/dbpedia/main.py "Who is Tom Cruise?"

And it will output something like this:

SELECT DISTINCT ?x1 WHERE {
    ?x0 rdf:type foaf:Person.
    ?x0 rdfs:label "Tom Cruise"@en.
    ?x0 rdfs:comment ?x1.
}

Thomas Cruise Mapother IV, widely known as Tom Cruise, is an...

The transformation from natural language to sparql is done by first using a special form of regular expressions:

person_name = Group(Plus(Pos("NNP")), "person_name")
regex = Lemma("who") + Lemma("be") + person_name + Question(Pos("."))

And then using and a convenient way to express semantic relations:

person = IsPerson() + HasKeyword(person_name)
definition = DefinitionOf(person)

The rest of the transformation is handled automatically by the framework to finally produce this sparql:

SELECT DISTINCT ?x1 WHERE {
    ?x0 rdf:type foaf:Person.
    ?x0 rdfs:label "Tom Cruise"@en.
    ?x0 rdfs:comment ?x1.
}

Using a very similar procedure you could generate and MQL query for the same question obtaining:

[{
    "/common/topic/description": [{}],
    "/type/object/name": "Tom Cruise",
    "/type/object/type": "/people/person"
}]

Installation

You need to have installed docopt and numpy. Other than that, you can just type:

pip install quepy

You can get more details on the installation here:

http://quepy.readthedocs.org/en/latest/installation.html

Learn more

You can find a tutorial here:

http://quepy.readthedocs.org/en/latest/tutorial.html

And the full documentation here:

http://quepy.readthedocs.org/

Join our mailing list

Contribute!

Want to help develop quepy? Welcome aboard! Find us in http://groups.google.com/group/quepy

Comments
  • Conflicting queries

    Conflicting queries

    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?

    opened by iScienceLuvr 7
  • Error in Demo

    Error in Demo

    Hi in the online demo given at http://quepy.machinalis.com/ I'm getting result for "what is the plot of Titanic?" but not for "what is the plot of titanic?"

    Is this expected?

    opened by jithurjacob 3
  • Not installed on ubuntu 14 and windows 10

    Not installed on ubuntu 14 and windows 10

    After installing with pip,It doesn't found any module quepy,(on windows)->and on "quepy --version" it opens up the quepy file in text editor. please help me,I tries different way,but not any work for me.

    opened by myounus96 2
  • Adding support for additional query languages

    Adding support for additional query languages

    Each Quepy application can define its own query output language by including a printout.py file and an appropriately named expression_to_myquerylang function. When generating a query you can now pass a query_lang='myquerylang' parameter. The query language defaults to SPARQL if no query_lang is specified.

    See freebase-quepy for an example of adding a new query language (MQL): https://github.com/narphorium/quepy-freebase

    opened by narphorium 2
  • Missing wrapper on Windows install

    Missing wrapper on Windows install

    To work on Windows, you'll need a quepy.bat wrapper for the quepy Python script. All the other things in my Scripts directory have them, but I'm not sure what is needed to get the installer to create it (or if you have to do it yourself). I installed using pip, not easy_install, if it makes a difference.

    opened by tfmorris 2
  • Broken NLTK setup

    Broken NLTK setup

    While running quepy nltkdata /some/pathdownloads the resources "wordnet" and "maxent_treebank _pos_tagger", trying to run the applicaion gives the following error:

    Resource u'taggers/averaged_perceptron_tagger/averaged_perceptron_tagger.pickle' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download()

    I believe this is because of the perceptron tagger being made the default tagger in the nltk project, which is a dependency for quepy.

    opened by TestSubjector 1
  • Resource u 'corpora/wordnet' not found

    Resource u 'corpora/wordnet' not found

    I just installed quepy to start working with some examples as shown in the tutorials. But I get the following errors while running main.py.

    
    Traceback (most recent call last):
      File "main.py", line 9, in <module>
        target, query, metadata = testquepy.get_query("what is a blowtorch?")
      File "/usr/local/lib/python2.7/dist-packages/quepy/quepyapp.py", line 106, in get_query
        for target, query, userdata in self.get_queries(question):
      File "/usr/local/lib/python2.7/dist-packages/quepy/quepyapp.py", line 123, in get_queries
        for expression, userdata in self._iter_compiled_forms(question):
      File "/usr/local/lib/python2.7/dist-packages/quepy/quepyapp.py", line 137, in _iter_compiled_forms
        words = list(self.tagger(question))
      File "/usr/local/lib/python2.7/dist-packages/quepy/tagger.py", line 68, in wrapper
        words = tagger_function(string)
      File "/usr/local/lib/python2.7/dist-packages/quepy/tagger.py", line 64, in <lambda>
        tagger_function = lambda x: run_nltktagger(x, settings.NLTK_DATA_PATH)
      File "/usr/local/lib/python2.7/dist-packages/quepy/nltktagger.py", line 49, in run_nltktagger
        u'NN': wordnet.NOUN,
      File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", line 99, in __getattr__
        self.__load()
      File "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py", line 64, in __load
        except LookupError: raise e
    LookupError: 
    **********************************************************************
      Resource u'corpora/wordnet' not found.  Please use the NLTK
      Downloader to obtain the resource:  >>> nltk.download()
      Searched in:
        - u'/'
        - u'h'
        - u'o'
        - u'm'
        - u'e'
        - u'/'
        - u'g'
        - u'u'
        - u'r'
        - u'u'
        - u'p'
        - u'a'
        - u'd'
        - u'/'
        - u'n'
        - u'l'
        - u't'
        - u'k'
        - u'_'
        - u'd'
        - u'a'
        - u't'
        - u'a'
    **********************************************************************
    

    Also this is how i set he nltk_data variable in settings.py:

    # NLTK config
    NLTK_DATA_PATH = "/home/gurupad/nltk_data"  # List of paths with NLTK data
    
    

    Can someone help me out?

    opened by Protino 1
  • Added PopulatedPlace (Fixes #3)

    Added PopulatedPlace (Fixes #3)

    There might be more questions that can be asked about population places, but this solves the

    what is the population of massachusetts?

    question (note the spelling difference with the issue question).

    opened by DrDub 1
  • Change community message

    Change community message

    change message: "Want to help develop quepy? Welcome aboard! Find us in

    quepy at freenode

    quepydev at librelist.com"

    to: "Want to help develop quepy? Welcome aboard! Find us in http://groups.google.com/group/quepy"

    opened by copybin 1
  • Chile fix

    Chile fix

    It seems that the latest dbpedia dump has slightly updated information for the timezone of Chile.

    This pull request fixes this problem by introducing "and" as a split word (dbpedia currently returns "-4 and -6" for Chile) and also slightly altering the response.

    opened by mrshu 1
  • docs: fix simple typo, beacuse -> because

    docs: fix simple typo, beacuse -> because

    There is a small typo in quepy/mql_generation.py.

    Should read because rather than beacuse.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 0
  • Filtering (where clause), show multiple items and SERVICE clause to join is missing?

    Filtering (where clause), show multiple items and SERVICE clause to join is missing?

    @j0hn @dmoisset I am trying to build SPARQL queries using QUEPY and was looking for any example where you guys have used FILTER clause. I did not find any. Could you please provide a sample code or a tutorial. This issue has also been reported by another user https://github.com/machinalis/quepy/issues/44. Moreover, I tried to build queries extracting multiple items but query is not being generated. For example, i was trying to generate query for "list proteins with symbols and chromosome where protein symbol is ACT" How can I build query like this? 3- To generate a federated query you have to join the query with SERVICE clause. Does quepy support for joining (SERVICE) clause.

    opened by bukharilab 0
  • how to start a project

    how to start a project

    as there is no quepy.py file then how can we start a new project I have tried with quepyapp.py file to start a new project but nothing happened

    "$ quepy.py startapp dbpedia" how to do this

    opened by vyaslkv 2
Owner
Machinalis
Machinalis
QVHighlights: Detecting Moments and Highlights in Videos via Natural Language Queries

Moment-DETR QVHighlights: Detecting Moments and Highlights in Videos via Natural Language Queries Jie Lei, Tamara L. Berg, Mohit Bansal For dataset de

Jie Lei 雷杰 133 Dec 22, 2022
Indobenchmark are collections of Natural Language Understanding (IndoNLU) and Natural Language Generation (IndoNLG)

Indobenchmark Toolkit Indobenchmark are collections of Natural Language Understanding (IndoNLU) and Natural Language Generation (IndoNLG) resources fo

Samuel Cahyawijaya 11 Aug 26, 2022
Implementation of Natural Language Code Search in the project CodeBERT: A Pre-Trained Model for Programming and Natural Languages.

CodeBERT-Implementation In this repo we have replicated the paper CodeBERT: A Pre-Trained Model for Programming and Natural Languages. We are interest

Tanuj Sur 4 Jul 1, 2022
A natural language modeling framework based on PyTorch

Overview PyText is a deep-learning based NLP modeling framework built on PyTorch. PyText addresses the often-conflicting requirements of enabling rapi

Facebook Research 6.4k Dec 27, 2022
A very simple framework for state-of-the-art Natural Language Processing (NLP)

A very simple framework for state-of-the-art NLP. Developed by Humboldt University of Berlin and friends. IMPORTANT: (30.08.2020) We moved our models

flair 12.3k Dec 31, 2022
A natural language modeling framework based on PyTorch

Overview PyText is a deep-learning based NLP modeling framework built on PyTorch. PyText addresses the often-conflicting requirements of enabling rapi

Facebook Research 6.1k Feb 12, 2021
A very simple framework for state-of-the-art Natural Language Processing (NLP)

A very simple framework for state-of-the-art NLP. Developed by Humboldt University of Berlin and friends. IMPORTANT: (30.08.2020) We moved our models

flair 10k Feb 18, 2021
:mag: End-to-End Framework for building natural language search interfaces to data by utilizing Transformers and the State-of-the-Art of NLP. Supporting DPR, Elasticsearch, HuggingFace’s Modelhub and much more!

Haystack is an end-to-end framework that enables you to build powerful and production-ready pipelines for different search use cases. Whether you want

deepset 1.4k Feb 18, 2021
A natural language modeling framework based on PyTorch

Overview PyText is a deep-learning based NLP modeling framework built on PyTorch. PyText addresses the often-conflicting requirements of enabling rapi

Facebook Research 6.1k Feb 18, 2021
A very simple framework for state-of-the-art Natural Language Processing (NLP)

A very simple framework for state-of-the-art NLP. Developed by Humboldt University of Berlin and friends. Flair is: A powerful NLP library. Flair allo

flair 12.3k Jan 2, 2023
FedNLP: A Benchmarking Framework for Federated Learning in Natural Language Processing

FedNLP is a research-oriented benchmarking framework for advancing federated learning (FL) in natural language processing (NLP). It uses FedML repository as the git submodule. In other words, FedNLP only focuses on adavanced models and dataset, while FedML supports various federated optimizers (e.g., FedAvg) and platforms (Distributed Computing, IoT/Mobile, Standalone).

FedML-AI 216 Nov 27, 2022
LegalNLP - Natural Language Processing Methods for the Brazilian Legal Language

LegalNLP - Natural Language Processing Methods for the Brazilian Legal Language ⚖️ The library of Natural Language Processing for Brazilian legal lang

Felipe Maia Polo 125 Dec 20, 2022
A design of MIDI language for music generation task, specifically for Natural Language Processing (NLP) models.

MIDI Language Introduction Reference Paper: Pop Music Transformer: Beat-based Modeling and Generation of Expressive Pop Piano Compositions: code This

Robert Bogan Kang 3 May 25, 2022
NL. The natural language programming language.

NL A Natural-Language programming language. Built using Codex. A few examples are inside the nl_projects directory. How it works Write any code in pur

null 2 Jan 17, 2022
Reading Wikipedia to Answer Open-Domain Questions

DrQA This is a PyTorch implementation of the DrQA system described in the ACL 2017 paper Reading Wikipedia to Answer Open-Domain Questions. Quick Link

Facebook Research 4.3k Jan 1, 2023
GooAQ 🥑 : Google Answers to Google Questions!

This repository contains the code/data accompanying our recent work on long-form question answering.

AI2 112 Nov 6, 2022
An ActivityWatch watcher to pose questions to the user and record her answers.

aw-watcher-ask An ActivityWatch watcher to pose questions to the user and record her answers. This watcher uses Zenity to present dialog boxes to the

Bernardo Chrispim Baron 33 Dec 3, 2022
IEEEXtreme15.0 Questions And Answers

IEEEXtreme15.0 Questions And Answers IEEEXtreme is a global challenge in which teams of IEEE Student members – advised and proctored by an IEEE member

Dilan Perera 15 Oct 24, 2022