Skip to content

Commit

Permalink
chore: migrate docs to material for mkdocs (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
mesejo authored Feb 19, 2025
1 parent f003f08 commit e34a5ef
Show file tree
Hide file tree
Showing 31 changed files with 1,763 additions and 458 deletions.
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"prHourlyLimit": 3,
"automerge": false,
"printConfig": true
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: publish package
run: |
uv build
uv publish --trusted-publishing always
uv publish --trusted-publishing always
36 changes: 15 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
# isort should run before black as black sometimes tweaks the isort output
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.2
hooks:
- id: isort
# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 20.8b1
# Run the linter.
- id: ruff
args: ["--output-format=full", "--fix", "trrex", "docs"]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.22
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.2
hooks:
- id: blackdoc
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790 # Must match ci/requirements/*.yml
hooks:
- id: mypy
exclude: "properties|asv_bench"
# Update the uv lockfile
- id: uv-lock
- id: uv-export
args: [ "--frozen", "--no-hashes", "--no-emit-project", "--group=docs", "--all-extras", "--output-file=docs/requirements.txt" ]
13 changes: 13 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.12"

python:
install:
- requirements: docs/requirements.txt

mkdocs:
configuration: mkdocs.yml
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

# Efficient string matching with regular expressions

This package includes a pure Python function that enables you to represent a set of strings as a regular expression.
With this regular expression, you can perform various operations, such as replacing, extracting and matching keywords.
This package includes a pure Python function that enables you to represent a set of strings as a regular expression.
With this regular expression, you can perform various operations, such as replacing, extracting and matching keywords.
The name of the package comes from the internal trie used to build the regular expression (**TR**ie to **RE**ge**X**)

## Install trrex
Expand Down Expand Up @@ -69,7 +69,7 @@ for examples.

## Issues

If you have any issues with this repository, please don't hesitate to [raise them](https://github.com/mesejo/trex/issues/new).
If you have any issues with this repository, please don't hesitate to [raise them](https://github.com/mesejo/trex/issues/new).
It is actively maintained, and we will do our best to help you.

## Acknowledgments
Expand All @@ -80,5 +80,5 @@ This project is based on the following resources:
- [Triegex](https://github.com/ZhukovAlexander/triegex)

## Liked the work?
If you've found this repository helpful, why not give it a star? It's an easy way to show your appreciation and support for the project.
Plus, it helps others discover it too!
If you've found this repository helpful, why not give it a star? It's an easy way to show your appreciation and support for the project.
Plus, it helps others discover it too!
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

File renamed without changes.
File renamed without changes
52 changes: 52 additions & 0 deletions docs/how_to_guides.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Integrations

As trrex builds a regular expression pattern, it can be used by any
library that expects a regular expression

## Working with pandas

```python

import trrex as tx
import pandas as pd

df = pd.DataFrame(["The quick brown fox", "jumps over", "the lazy dog"], columns=["text"])
pattern = tx.make(["dog", "fox"])
df["text"].str.contains(pattern)
```

As you can see from the above example it works with any pandas function
that receives a regular expression.

## Efficient gazetteer for spacy

It can be used in conjunction with spacy EntityRuler to build a
gazetteer

```python
import trrex as tx
from spacy.lang.en import English

nlp = English()
ruler = nlp.add_pipe("entity_ruler")
patterns = [ {
"label": "ORG", "pattern": [ {"TEXT": {"REGEX": tx.make(["Amazon", "Apple", "Netflix", "Netlify"])}} ], },
{"label": "GPE", "pattern": [{"LOWER": "san"}, {"LOWER":
"francisco"}]}, ]
ruler.add_patterns(patterns)

doc = nlp("Netflix HQ is in Los Gatos.")
[(ent.text, [ent.label]()) for ent in doc.ents]
```

## Fuzzy matching with regex

We can take advantage of the fuzzy matching of the regex module:

```python
import regex
import trrex as tx

pattern = tx.make(["monkey", "monster", "dog", "cat"], prefix="", suffix=r"{1<=e<=2}")
regex.search(pattern, "This is really a master dag", regex.BESTMATCH)
```
56 changes: 56 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# trrex: efficient keyword mining with regular expressions

The package includes a function that represents a collection of keywords
(strings) as a regular expression. This regular expression can be used
for multiple purposes, such as keyword replacement, keyword extraction,
fuzzy matching, and other similar tasks.

```python
import re
import trrex as tx

pattern = tx.make(["baby", "bat", "bad"])
re.findall(pattern, "The baby was scared by the bad bat.")
```

## Installation

First, obtain at least Python 3.6 and virtualenv if you do not already
have them. Using a virtual environment is strongly recommended, since it
will help you to avoid clutter in your system-wide libraries. Once the
requirements are met, you can use pip:

```bash
pip install trrex
```

## Examples

Here are some quick examples of what you can do with trrex.

To begin, import re and trrex:

```python
import re
import trrex as tx
```

### Search for any keyword

You can search for keywords by using re.search:

```python
keywords = tx.make(["baby", "bad", "bat"])
match = re.search(keywords, "I saw a bat")
```

In this case we find *bat* the only keyword appearing in the text.

### Replace a keyword

You can replace a keyword by using re.sub:

```python
keywords = tx.make(["baby", "bad", "bat"])
replaced = re.sub(keywords, "bowl", "The bat is round")
```
35 changes: 0 additions & 35 deletions docs/make.bat

This file was deleted.

1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: trrex
Loading

0 comments on commit e34a5ef

Please sign in to comment.