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.
- Host: GitHub
- URL: https://github.com/nodef/pg-english
- Owner: nodef
- License: mit
- Created: 2018-06-03T18:50:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-07T18:16:22.000Z (over 4 years ago)
- Last Synced: 2025-02-15T23:03:27.749Z (8 months ago)
- Topics: database, english, interface, language, natural, nlidb, nlp, pg, postgresql, processing
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/pg-english
- Size: 32.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pg-english
[](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