semvec/pypi-packages huggingface dataset:
permtab 0.1.0
A simple permission rule parsing library.
License: MIT
Requires Python: >=3.8

# permtab

A simple permission rule parsing library.

## Installation

Install permtab via `pip`:

```console
pip install permtab
```

## Format

Permtab uses a syntax similar to crontab, although it is actually a reversed version. Actually, the `shlex` is used for parsing.

```bash
# *.permtab
<rulename> <filter...>
```

Here `filter` has the same meaning with `rule` and `condition`.

> NOTE: Leading a rule to `True` only needs one filter that returns `True`.

Here is an example:

```bash
myrule1     owner_1234  operator_8525   operator_8390
myrule2     text_hello  text_world      "text_hello world!"
*           user_any
# The tab rule with name '*' is considered a base rule.
# If not defined, the default rule will pass everything to other rules.
```

## Rule factory

Rule factory is a function which exports a checker function.

This is a generic definition:

```python
import permtab

def factory(*args, **kwargs):
    def _checker(*args, **kwargs):
        return CONDITION
    return _checker

permtab.register_rulefactory(REGEX_FOR_THE_FACTORY, factory)
```

Exactly, the parameters for rule factory and checker depend on their use.

The parameters for rule factory is decided by groups in provided regex.
All groups that matched are unpacked to positional arguments, and all named
groups that matched are unpacked to keyword arguments.

Checkers' parameters are decided by where the checker called.

> NOTE: Parameters provided by named groups are all in common groups.
>
> NOTE: Dependency injection will not work by default, so you must patch some
> functions to export new functions that support dependency injection if
> needed.

## Loading and using permtab

This step is quite easy:

```python
import permtab

permtab.load("/path/to/your.permtab")  # load "/path/to/your.permtab"

rule = permtab.find_rule("your_rule_name")  # get rule function, then use it

def f():
    if rule(...):
        ...  # run if the condition is satisfied
    else:
        ...  # otherwise
```

## Editing a permtab

Editing uses a `+` and `-` marker on a rule to control changes.

Here is an example:

```python
import permtab

parsed = permtab.parse("test.permtab")
# DO NOT parse and edit the SAME FILE at the same time
# Otherwise your data may be lost

with open("test.permtab", "w") as f:
    f.writelines(
        permtab.edit(
            parsed,
            {
                "myrule1": ("-t_aeiou", "-t_hello world!"),
                # add a `-` to remove an existing rule
                "myrule2": ("+t_hellp",),
                # add a `+` to add a new rule
                "myrule3": ("+t_foo", "+t_bar", "-t_foo")
                # `+` and `-` operation can take effect at the same time
                # duplicate changes will be evaluated
            }
        )
    )

permtab.reset_rule()  # remove rules previously loaded
permtab.load("test.permtab")  # reload new permtab
```
IESEGRecSys 0.23.8
Recommendation Systems - IESEG School of Management
License: MIT
Keywords: IESEG

<!-- DOCUMENT STYLE -->
<style>
    body {
        font-family: "Calibri";
        padding-left:1.5cm;
        padding-right:1.5cm;
    }
</style>

<!-- HEADER -->
<img src="https://www.ieseg.fr/wp-content/uploads/IESEG-Logo-2012-rgb.jpg" alt="drawing" style="width:50%;padding-bottom:1cm;"/>
<span style="float:right;">
    <br>
    Recommendation Systems
    <br>
    Module
    <br>
    Class: 2022 & 2023
</span>

<!-- CONTENT -->

---

## Package dependencies:
<center> 
 <a href="https://surpriselib.com/"><image src="https://surpriselib.com/logo_white.svg" width="30%"></a>
 <a href="https://scikit-learn.org/stable/"><image src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Scikit_learn_logo_small.svg/2560px-Scikit_learn_logo_small.svg.png" width="25%" style="padding-left:0.5cm;"></a>
</center>

---

## Overview

- Model evaluation (`eval.py`):
    - Regression metrics
        - RMSE
        - MAE
    - Classification metrics
        - Precision
        - Recall
        - F1
    - Ranking metrics
        - NDCG
    - `eval.evaluate` computes all above mentioned metrics 
- Content based Recommender System (`model.py`)
- Helper functions (`utils.py`)
    - `get_top_n`: Compute Top-N recommendations from predictions 
    - `predict_user_topn`: Compute Top-N recommendations for a user