The system for determining the compliance of the text with the specified rules
Project description
Forseti Language
The system for determining the compliance of the text with the specified rules
How to install:
PyPi installation guide
pip install forseti-lang
How to use:
from forseti_lang.execute import execute_condition
condition = "TRUE AND FALSE"
text = ""
execute_condition(condition, text) # False
All regular expressions should be in lowercase.
Supported logic operators
English
Below is a table of available logical operators and their description.
Operator | Description | Priority |
---|---|---|
() | The conditions in quotes will be met first | 0 |
AND | Logical AND | 1 |
AND NOT | Logical AND NOT | 2 |
OR | Logical OR | 3 |
Atoms (TRUE and FALSE) | Minimum logical unit | 4 |
Russian
Forseti was developed for the analysis of texts in Russian. So, you can use:
RU | ENG |
---|---|
И | AND |
ИЛИ | OR |
Note
You can combine ru and eng operators.
Supported functions
We really lacked a simple syntax (but regular expressions did not allow us to achieve this), so we created our own functions!
Function | In Forseti | Description | Priority |
---|---|---|---|
f text length | ll, lg | Text length in characters check function | 5 |
f words distance | wN, cN, N | Checks whether the words are in the specified interval | 6 |
f words nearby | nearby | Checks the words that are next to another word | 7 |
f regex search | Checks the occurrence of a regular expression in the text | 8 |
Explanations
|ll
- length less (in characters)|lg
- length great (in characters)|wN
- word in distanceN words
|cN
- word in distanceN characters
|N
- alias of|wN
|nearby
- the word is nearby to the wordsword1 |nearby word2 | word3 | word4
Notes
- All function starts with special character:
|
. That's why we don't support it in regular expressions - It is also forbidden to use the
-
character, it is used in the distance function - The function of finding words at a distance will allow you to exclude constructions with a word at a distance, for example:
condition - "hello |w1 -world"
text - "Hello beautiful world!"
result - False
- You cannot combine two functions in one expression
- Text length and word distance functions don't work with negative values
Priority table
Operator | Description | Priority |
---|---|---|
() |
The conditions in quotes will be met first | 0 |
AND |
Logical AND |
1 |
AND NOT |
Logical AND NOT |
2 |
OR |
Logical OR |
3 |
Atoms (TRUE and FALSE ) |
Minimum logical unit | 4 |
f text length | Text length in characters check function | 5 |
f words distance | Checks whether the words are in the specified interval | 6 |
f words nearby | Checks the words that are next to another word | 7 |
f regex search | Checks the occurrence of a regular expression in the text | 8 |
Examples
Checking the length of the text
from forseti_lang.execute import execute_condition
condition = '|ll5'
execute_condition(condition, "Hello world!") # False
execute_condition(condition, "Hi") # True
condition = '|lg5'
execute_condition(condition, "Hello world!") # True
execute_condition(condition, "Hi") # False
Checking the words distance
from forseti_lang.execute import execute_condition
condition = 'hello |w1 world'
execute_condition(condition, "Hello world!") # True
execute_condition(condition, "Hello sunny world!") # True
execute_condition(condition, "Hello dirty and dark world!") # False
condition = 'hi\W? |c1 how are you'
execute_condition(condition, "Hi, how are you?") # True
execute_condition(condition, "Hi, hmm.. how ary you?") # False
condition = 'hello |1 world'
execute_condition(condition, "Hello world!") # True
Checking nearby words
from forseti_lang.execute import execute_condition
condition = 'hello |nearby world | people | notalib'
execute_condition(condition, "Hello world!") # True
execute_condition(condition, "Hello notalib!") # True
Logic processing
from forseti_lang.execute import execute_condition
execute_condition("TRUE AND FALSE", "") # False
execute_condition("TRUE OR FALSE", "") # True
execute_condition("FALSE OR TRUE AND (TRUE OR FALSE)", "") # True
execute_condition("FALSE OR TRUE AND (FALSE AND TRUE)", "") # False
execute_condition("(TRUE OR FALSE) AND NOT (TRUE AND FALSE)", "") # TRUE
Difficult rules example
короб AND NOT короб |2 конфет
минимальн\w,{,2} |1 стоимо
балл AND NOT (сн[ия]\w* балл ИЛИ 10\s?балл ИЛИ десять\sбаллов) AND |lg15
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file forseti_lang-1.0.3.tar.gz
.
File metadata
- Download URL: forseti_lang-1.0.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.4.0-170-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aefc5ba0ed98ae3479b378b59aaef6c10e095bd727a8f5d1960825fa1498a87a |
|
MD5 | 7b1b5e0b69f8f1115b85d3e7663a354b |
|
BLAKE2b-256 | 5fc0d07c15b7a0c9ddf8434aba8206048fe208520e2271cb87217fb351cc6ea2 |
File details
Details for the file forseti_lang-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: forseti_lang-1.0.3-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.4.0-170-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5efef37b1a690103bd40dcd4b95c98357f05e19ae0c149f2bed1429aa8e86ab |
|
MD5 | a238af3aa7e896f1d4942360df4f8905 |
|
BLAKE2b-256 | d27e3f8fa788f31dee5e447506e6c702da976c333f75d1897e0c80d57f73f7b1 |