Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "[SET-OPERATION] supersetof, subsetof and disjointof filter for filter_compare"" #1005

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- [Multipart](docs/docs/Developing_with_JAC/Language_Features/multipart.md)
- [Report Custom](docs/docs/Developing_with_JAC/Language_Features/report_custom.md)
- [Walker Callback](docs/docs/Developing_with_JAC/Language_Features/walker_callback.md)
- [Set Filtering](docs/docs/Developing_with_JAC/Language_Features/set_filtering.md)

## Jaseci Archetype and Graphs
- [Nodes](docs/docs/jaseci_architype/nodes.md)
Expand Down
67 changes: 67 additions & 0 deletions docs/docs/Developing_with_JAC/Language_Features/set_filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# **FILTERING REFERENCE USING SET OPERATION**

## **USE CASE**
- This is to simplify that kind of structure


### **[Current]**
```js
root -> color(value=BLUE);
root -> color(value=RED);
root -> color(value=YELLOW);
root -> color(value=GREEN);
root -> color(value=ORANGE);
root -> color(value=VIOLET);
color(value=BLUE) -> color(value=GREEN);
color(value=YELLOW) -> color(value=GREEN);
color(value=RED) -> color(value=ORANGE);
color(value=YELLOW) -> color(value=ORANGE);
color(value=RED) -> color(value=VIOLET);
color(value=BLUE) -> color(value=VIOLET);

// mostly this will be the best structure for relational referencing
// for example I need to find all colors comes from BLUE or can be created using BLUE
// you just need to traverse starting on BLUE node
// but this requires to create the relational tree ferencing so that you can traverse on any color

// the syntax will look like this
// for example I need to find all colors comes from BLUE or can be created using BLUE
root {
take --> node::color(value=BLUE);
}

color {
take --> node::color;
// just have a handling to stop repetition
}
```
### **[New]**
```js
// the simplified version will now look like this

root -> color(value=BLUE, var=[blue]);
root -> color(value=RED, var=[red]);
root -> color(value=YELLOW, var=[yellow]);
root -> color(value=GREEN, var=[blue,yellow]);
root -> color(value=ORANGE, var=[red,yellow]);
root -> color(value=VIOLET, var=[red,blue]);
root -> color(value=LITE_VIOLET, var=[red,blue,white]);

root {

// I need to find all colors comes from BLUE or can be created using BLUE
for color in --> node::color(var supersetof [blue]) {
// BLUE GREEN VIOLET
}

// I need to find all colors that I can produce using sets of colors [red, blue, white]
for color in --> node::color(var subsetof [red, blue, white]) {
// VIOLET, LITE_VIOLET
}

// I need to find all colors that are not present(or made of) on the list [red, blue, white]
for color in --> node::color(var disjointof [red, blue, white]) {
// YELLOW
}
}
```
8 changes: 7 additions & 1 deletion jaseci_core/jaseci/jac/interpreter/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def run_compare(self, jac_ast):

def run_cmp_op(self, jac_ast, val1, val2):
"""
cmp_op: EE | LT | GT | LTE | GTE | NE | KW_IN | nin;
cmp_op: EE | LT | GT | LTE | GTE | NE | KW_IN | nin | SUB_OF | SUPER_OF | DISJOINT_OF;
"""
kid = self.set_cur_ast(jac_ast)
if kid[0].name == "EE":
Expand All @@ -638,6 +638,12 @@ def run_cmp_op(self, jac_ast, val1, val2):
self.push(JacValue(self, value=val1.value in val2.value))
elif kid[0].name == "nin":
self.push(JacValue(self, value=val1.value not in val2.value))
elif kid[0].name == "SUB_OF":
self.push(JacValue(self, value=set(val1.value).issubset(set(val2.value))))
elif kid[0].name == "SUPER_OF":
self.push(JacValue(self, value=set(val1.value).issuperset(set(val2.value))))
elif kid[0].name == "DISJOINT_OF":
self.push(JacValue(self, value=set(val1.value).isdisjoint(set(val2.value))))

def run_arithmetic(self, jac_ast):
"""
Expand Down
5 changes: 4 additions & 1 deletion jaseci_core/jaseci/jac/jac.g4
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ logical: compare ((KW_AND | KW_OR) compare)*;

compare: NOT compare | arithmetic (cmp_op arithmetic)*;

cmp_op: EE | LT | GT | LTE | GTE | NE | KW_IN | nin;
cmp_op: EE | LT | GT | LTE | GTE | NE | KW_IN | nin | SUB_OF | SUPER_OF | DISJOINT_OF;

nin: NOT KW_IN;

Expand Down Expand Up @@ -420,6 +420,9 @@ LTE: '<=';
GTE: '>=';
NE: '!=';
KW_IN: 'in';
SUB_OF: 'subsetof';
SUPER_OF: 'supersetof';
DISJOINT_OF: 'disjointof';
KW_ANCHOR: 'anchor';
KW_HAS: 'has';
KW_GLOBAL: 'global';
Expand Down
8 changes: 7 additions & 1 deletion jaseci_core/jaseci/jac/jac_parse/jac.interp

Large diffs are not rendered by default.

94 changes: 50 additions & 44 deletions jaseci_core/jaseci/jac/jac_parse/jac.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,36 @@ LTE=83
GTE=84
NE=85
KW_IN=86
KW_ANCHOR=87
KW_HAS=88
KW_GLOBAL=89
KW_PRIVATE=90
COMMA=91
KW_CAN=92
PLUS=93
MINUS=94
STAR_MUL=95
DIV=96
MOD=97
POW=98
LPAREN=99
RPAREN=100
LSQUARE=101
RSQUARE=102
FLOAT=103
STRING=104
BOOL=105
INT=106
NULL=107
NAME=108
COMMENT=109
LINE_COMMENT=110
PY_COMMENT=111
WS=112
ErrorChar=113
SUB_OF=87
SUPER_OF=88
DISJOINT_OF=89
KW_ANCHOR=90
KW_HAS=91
KW_GLOBAL=92
KW_PRIVATE=93
COMMA=94
KW_CAN=95
PLUS=96
MINUS=97
STAR_MUL=98
DIV=99
MOD=100
POW=101
LPAREN=102
RPAREN=103
LSQUARE=104
RSQUARE=105
FLOAT=106
STRING=107
BOOL=108
INT=109
NULL=110
NAME=111
COMMENT=112
LINE_COMMENT=113
PY_COMMENT=114
WS=115
ErrorChar=116
'version'=1
'-->'=2
'->'=3
Expand Down Expand Up @@ -189,20 +192,23 @@ ErrorChar=113
'>='=84
'!='=85
'in'=86
'anchor'=87
'has'=88
'global'=89
'private'=90
','=91
'can'=92
'+'=93
'-'=94
'*'=95
'/'=96
'%'=97
'^'=98
'('=99
')'=100
'['=101
']'=102
'null'=107
'subsetof'=87
'supersetof'=88
'disjointof'=89
'anchor'=90
'has'=91
'global'=92
'private'=93
','=94
'can'=95
'+'=96
'-'=97
'*'=98
'/'=99
'%'=100
'^'=101
'('=102
')'=103
'['=104
']'=105
'null'=110
11 changes: 10 additions & 1 deletion jaseci_core/jaseci/jac/jac_parse/jacLexer.interp

Large diffs are not rendered by default.

Loading