An open API service indexing awesome lists of open source software.

https://github.com/nodef/pg-english

English interface to PostgreSQL.
https://github.com/nodef/pg-english

database english interface language natural nlidb nlp pg postgresql processing

Last synced: 8 months ago
JSON representation

English interface to PostgreSQL.

Awesome Lists containing this project

README

          

# pg-english

[![pg-english](https://i.imgur.com/UN74CCi.jpg)](https://npmjs.com/package/pg-english)

Convert [english query] to [informal] [SQL SELECT].
> NOTE: [pg-slang] can convert informal SQL to formal SQL.

```javascript
var english = require('pg-english');
// english.token([type], [value]): token
// english.number(): processed text
// english.unit(): processed text
// english.reserved(): processed text
// english.entity(, , [this]): Promise (processed text)
// english(, , [this], [options])
// -> Promise (processed text)

// ()
// - texts: array of text
// -> Promise {type, value, length}
// - type: token type (table/column/row)
// - value: token value
// - hint: token hint (identifies table)
// - length: token length (from start of texts)

// options: {
// table: undefined, // default table: none
// columns: {: []}, // default columns per table: none
// }

function match(txts) {
var z = null, txt = txts.join(' ');
if(txt.startsWith('ascorbic acid')) z = {type: 'column', value: 'ASCORBIC ACID', length: 2};
else if(txt.startsWith('food')) z = {type: 'table', value: 'FOOD', length: 1};
return Promise.resolve(z);
};
await english('show food with ascorbic acid less than twenty nine mg', match);
// SELECT "ASCORBIC ACID" FROM "FOOD" WHERE ("ASCORBIC ACID" < 0.029)
```

Methods:
- [token](https://www.npmjs.com/package/@pg-english/token)
- [number](https://www.npmjs.com/package/@pg-english/number)
- [unit](https://www.npmjs.com/package/@pg-english/unit)
- [reserved](https://www.npmjs.com/package/@pg-english/reserved)
- [entity](https://www.npmjs.com/package/@pg-english/entity)

[english query]: https://www.nexthink.com/blog/natural-language-interfaces-to-databases-nlidb/
[informal]: https://www.npmjs.com/package/pg-slang
[SQL SELECT]: https://www.postgresql.org/docs/10/static/sql-select.html
[pg-slang]: https://www.npmjs.com/package/pg-slang