Database Model for Storing Random Boolean Expressions

I have expressions like this:

(cat OR cat OR kitten OR kitten) AND (dog OR dog) NOT (blueberry OR firefly)

Does anyone have ideas on how to make tables to save them?

Before I get a request to use parentheses, I limited the use of operators to avoid ambiguous situations. Thus, only ANDs and NOT or only ORs are stored in this form:

Operators

id | name  
1  | AND  
2  | OR  
3  | NOT  

keywords

id | keyword  
1  | cat  
2  | dog  
3  | firefly  

expressions

id | operator | keywordId  
1  | 0        | 1   
1  | 1        | 2  
1  | 3        | 3  

which was: cat AND dog NOT firefly

But now I'm really puzzled ...

+3
source share
5 answers

, "". NULL- , ( )?

0

(, ), , , .

+3

/ :

cat cats OR dog dogs OR AND
pigeon firefly OR NOT

, , .

, (, A-Z) AND, OR, NOT:

cat A cats B dog C dogs : DAB+CD+&
pigeon A firefly : AB+~

.

+3

, . :

-

Cat  Dog  Firefly
---  ---  ------
1     2     4

, . , , . :

5 = 101 = , , .

id | locationName | options
---------------------------
1  | loc 1        | 5
2  | loc 2        | 2
3  | loc 3        | 7
4  | loc 4        | 6

, , . :

, , , :

2 options = 2

2,3 4.


, , :

6 options = 6

3 4


, , :

5 = 5

1 3.


:

4 | = 4


:

4 options = 0


, , , , , , , - . , , , .

+2

( ) ( ) ( OR firefly)

​​

NOT, ( ).

, . . .. :

Id | | 1 | 2 | 1 | 2

, 1, keyword2, expression1 expression2 NULL, 0, 1 2 0, 1, 2 . 1 , . , .

, . , , , , (CAT AND CATS) DOG CAT AND (CATS AND DOG). , .

, . , .

0

Source: https://habr.com/ru/post/1746401/


All Articles