Skip to main content

No project description provided

Project description

nl2query

Convert natural language text inputs to Pandas, MongoDB, Kusto, and Cypher(Neo4j) queries. The models used are fine-tuned versions of CodeT5+ 220m models.

PyPI version Support Python versions License: MIT

nl2query

Getting started

You can get nl2query from PyPI, using

python -m pip install nl2query

Example usage

1. Pandas Query

Suppose you want to convert the textual question to pandas query, follow the code below

from nl2query import PandasQuery

titanic = pd.read_csv('/path/titanic.csv')
queryfier = PandasQuery(titanic, 'titanic')

queryfier.generate_query('''list all people who paid more fare than the fare paid by 'Braund, Mr. Owen Harris' ''')
queryfier.generate_query('''find the names of passengers with age greater than 35 and containing Heath in their name''')
queryfier.generate_query('''which cabinet has average age less than 21?''') #Groupby Query

2. MongoDB Query

Suppose you want to convert the textual question to Mongo query, follow the code below

from nl2query import MongoQuery
import pymongo # import if performing analysis using python client
keys = ['_id', 'index', 'passengerid', 'survived', 'Pclass', 'name', 'sex', 'age', 'sibsp', 'parch', 'ticket', 'fare', 'cabin', 'embarked'] #keys present in the collection to be queried.
queryfier = MongoQuery(keys, 'titanic')
queryfier.generate_query('''which pclass has the minimum average fare?''')

keys = ['_id', 'index', 'total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size'] 
queryfier = MongoQuery(keys, 'tips')
queryfier.generate_query('''find the day on which combined sales was highest''')

In the above code the keys can be found by running the following piece db.tips.find_one({}).keys()

3. Kusto Query

Suppose you want to convert the textual question to Kusto query, follow the code below

from nl2query import KustoQuery
cols = ['vendor_id', 'pickup_datetime', 'dropoff_datetime', 'passenger_count', 'trip_distance', 'pickup_longitude', 'pickup_latitude', 'rate_code', 'store_and_fwd_flag', 'dropoff_longitude', 'dropoff_latitude', 'payment_type', 'fare_amount', 'surcharge', 'mta_tax', 'Tip_amount', 'tolls_amount', 'total_amount']

queryfier = KustoQuery(cols, 'nyc_taxi')
queryfier.generate_query('''find the vendor ids for all the tips that are greater than the average tip''')

4. Cypher(Neo4j) Query

Suppose you want to convert the textual question to Cypher query, follow the code below

from nl2query import CypherQuery

node_labels = {'User': ['display_name', 'uuid'], 'Comment': ['score', 'link', 'uuid']}
relationships = ['COMMENTED']
queryfier = CypherQuery(node_labels, relationships)
queryfier.generate_query('list the links of all the comments done by "jose_bacoy"')

node_labels = {'Case': ['gender', 'reportdate', 'ageunit', 'reporteroccupation', 'primaryid', 'age', 'eventDate'], 'Outcome': ['code', 'outcome']}
relationships = ['RESULTED_IN']
queryfier = CypherQuery(node_labels, relationships)
queryfier.generate_query('find the outcomes of people who are female and below the age of 32')

node_labels = {'Person': ['id', 'name', 'dob']}
relationships = []
queryfier = CypherQuery(node_labels, relationships)
res = queryfier.generate_query('find the dob of people who have "Andreia" in their name')

Changelog

Refer to the CHANGELOG.md file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nl2query-0.1.3.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

nl2query-0.1.3-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file nl2query-0.1.3.tar.gz.

File metadata

  • Download URL: nl2query-0.1.3.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for nl2query-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ef689fc176d7bc2b43fdc6b789c8e64d34de75d79209b73c0c796f05b46c13b9
MD5 ff49963a2f7dd1c3549542c1c8cfce1d
BLAKE2b-256 61f29ede5a7d8557969fc7f68c5a1d4a6d85d026a15c9fee3548ba774759ece1

See more details on using hashes here.

Provenance

File details

Details for the file nl2query-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nl2query-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for nl2query-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b94386d9eb8343bc5b7ab3874e310e72a6dfd8990a96263b1e29dc8809657727
MD5 fd7f114faf2bdcafd73d49203685d44b
BLAKE2b-256 029e8cec740acf74fa6bed36ba7193b58fd6d191af3ea687507acdf7ccdec139

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page