Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
🍌 nlp: use hackey way with brackets instead of proper approach
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfram77 committed Apr 21, 2018
1 parent 1d3ee28 commit 5681d5d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ NLP:
= show total vitamins
- SELECT FROM <table> WHERE <condition>
= show food where toxic minerals is more than catechin and catechin is less than or equal to epigallo catechin plus aluminium minus available carbohydrate
= show food where toxic minerals is more than catechin and catechin is less than or equal to epigallo catechin plus aluminium minus available carbohydrate or vitamin b3 into vitamin b2 greater than total oxalates
= show food where (toxic minerals is more than catechin) and (catechin is less than or equal to epigallo catechin plus aluminium minus available carbohydrate) or (vitamin b3 plus two) into vitamin b2 greater than total oxalates
```
Expand Down
15 changes: 8 additions & 7 deletions inp/nlp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ const VALUE = [
{t: [T.KEYWORD], v: [/NULL/], f: (s, t, i) => token(T.VALUE, t[i].value)},
{t: [T.KEYWORD], v: [/TRUE|FALSE/], f: (s, t, i) => token(T.BOOLEAN, t[i].value)},
];
// T.VALUE: t[i].type
const EXPRESSION = [
{t: [T.OPERATOR, T.BINARY, T.EXPRESSION], v: [null, /\+|\-/, null], f: (s, t, i) => [t[i], token(T.VALUE, `${t[i+1].value}${t[i+2].value}`)]},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /\^/, null], f: (s, t, i) => token(T.VALUE, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[\*\/%]/, null], f: (s, t, i) => token(T.VALUE, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[\+\-]/, null], f: (s, t, i) => token(T.VALUE, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.UNARY, T.EXPRESSION], v: [/[^(NOT)]/, null], f: (s, t, i) => token(T.VALUE, `${t[i].value} ${t[i+1].value}`)},
{t: [T.OPERATOR, T.BINARY, T.EXPRESSION], v: [null, /\+|\-/, null], f: (s, t, i) => [t[i], token(t[i+2].type, `${t[i+1].value}${t[i+2].value}`)]},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /\^/, null], f: (s, t, i) => token(t[i].type & t[i+2].type, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[\*\/%]/, null], f: (s, t, i) => token(t[i].type & t[i+2].type, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[\+\-]/, null], f: (s, t, i) => token(t[i].type & t[i+2].type, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.UNARY, T.EXPRESSION], v: [/[^(NOT)]/, null], f: (s, t, i) => token(t[i+1].type, `${t[i].value} ${t[i+1].value}`)},
{t: [T.EXPRESSION, T.UNARY], v: [null, /IS.*/], f: (s, t, i) => token(T.BOOLEAN, `${t[i].value} ${t[i+1].value}`)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[^\w\s=!<>]+/, null], f: (s, t, i) => token(T.VALUE, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.TERNARY, T.EXPRESSION, T.OPERATOR, T.EXPRESSION], v: [null, null, null, /AND/, null], f: (s, t, i) => token(T.BOOLEAN, `${t[i].value} ${t[i+1].value} ${t[i+2].value} AND ${t[i+4].value}`)},
Expand All @@ -50,8 +51,8 @@ const EXPRESSION = [
{t: [T.KEYWORD, T.VALUE, T.OPERATOR, T.VALUE, T.BINARY, T.VALUE], v: [null, null, /OR|AND/, null, null, null], f: (s, t, i) => i+6>=t.length? [t[i], token(T.BOOLEAN, `${t[i+1].value} ${t[i+4].value} ${t[i+5].value} AND ${t[i+3].value} ${t[i+4].value} ${t[i+4].value}`)]:t.slice(i, i+6)},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, /[^(OR)(AND)]/, null], f: (s, t, i) => token(T.BOOLEAN, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.UNARY, T.EXPRESSION], v: [null, null], f: (s, t, i) => token(T.BOOLEAN, `${t[i].value} ${t[i+1].value}`)},
{t: [T.VALUE, T.BINARY, T.VALUE], v: [null, null, null], f: (s, t, i) => { s.columns.push(t[i].value); s.columns.push(t[i+2].value); return null; }},
{t: [T.BINARY, T.VALUE], v: [null, null], f: (s, t, i) => { s.columns.push(t[i+1].value); return null; }},
{t: [T.VALUE, T.BINARY, T.VALUE], v: [null, /AND/, null], f: (s, t, i) => { s.columns.push(t[i].value); s.columns.push(t[i+2].value); return null; }},
{t: [T.BINARY, T.VALUE], v: [/AND/, null], f: (s, t, i) => { s.columns.push(t[i+1].value); return null; }},
{t: [T.EXPRESSION, T.BINARY, T.EXPRESSION], v: [null, null, null], f: (s, t, i) => token(T.BOOLEAN, `${t[i].value} ${t[i+1].value} ${t[i+2].value}`)},
{t: [T.EXPRESSION, T.EXPRESSION, T.CLOSE], v: [null, null, null], f: (s, t, i) => [token(T.EXPRESSION, `${t[i].value}, ${t[i+1].value}`), t[i+2]]},
{t: [T.FUNCTION, T.OPEN, T.EXPRESSION, T.CLOSE], v: [null, null, null, null], f: (s, t, i) => token(T.EXPRESSION, `${t[i].value}(${t[i+2].value})`)},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ifct2017",
"version": "0.0.742",
"version": "0.0.743",
"description": "Website for Indian Food Composition Tables 2017.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5681d5d

Please sign in to comment.