Text processing tool for detecting Danish CPR-numbers.
Project description
os2ds-rules
: Next-generation, high-performance rule system for OS2datascanner
os2ds-rules
is the next-generation rules system for use in OS2datascanner
by Magenta ApS, which aimes to deliver high-performance
with regards to processing speed and detection accuracy.
The project consists of several components:
- A shared-library backend written in modern
C++20
. - A Python C/C++ extension that exposes functionality from the backend to
python
. - A
python
library that provides a safe, easy-to-use interface to the aforementioned extension.
WARNING: This is currently in a very early stage of development and frequently undergoes substantial changes, so it is not ready for prime time, yet.
Getting Started
You can install either or both of the C++
library or the python
extension.
C++ backend library: libos2dsrules
For the C++
library you need a few different things:
- A compiler that supports
C++20
. We recommend using eitherg++
(GCC) orclang
(LLVM). cmake>=3.20
: Primary (meta) build system.ninja
: Cross-platform backend for cmake.gtest
(Google Test): For building and running the test suite.
For development, you additionally want:
cppcheck
orclang-analyzer
: For static code analysis.clang-format
: For formatting C++ code. We adhere to the LLVM style guide.clang-tidy
: For C++ code linting.gdb
orlldb
: A suitable debugger.
To make a debug build on linux
, run the following:
# Make a build directory
cmake . --preset linux-debug
cmake --build --preset linux-build-debug
This will build the shared library libos2dsrules.so
and the test suite testsuite
.
To install the library, run the following from the build directory:
sudo cmake --install build_cmake/debug
By default, this will install headers into /usr/include
and shared objects to
/usr/lib
.
To run the test suite:
ctest --preset linux-test-debug
Currently, this has only been tested on linux
.
It remains to be tested on windows
and macos
.
Using CMake preset workflows
There are four preconfigured workflows that has been automated with cmake:
linux-debug-workflow
: Configures, Builds and Tests the debug version of the library forlinux
.linux-release-workflow
: Configures, Builds and Packages the release version of the library forlinux
.windows-debug-workflow
: Configures, Builds and Tests the debug version of the library forwindows
.windows-release-workflow
: Configures, Builds and Packages the release version of the library forwindows
.
The Python extension: os2ds-rules
You need the following:
- A compiler that supports
C++20
. We recommend using eitherg++
(GCC) orclang
(LLVM). - The CPython development headers and libraries.
setuptools
: For building the extension.pytest
: For python tests.pytest-benchmark
: For python benchmarks.
NOTE: Depending on what OS you use and how CPython
was installed on your system,
the development headers and libraries may or may not be installed.
The development headers and libraries can be installed using a package manager on the following systems:
ubuntu
/debian
:sudo apt install python3-dev
fedora
:sudo dnf install python3-devel
To build the extension:
# From the project root.
python3 -m setup build
To install the extension locally:
# From the project root.
# You may want to use the `-e` option during development.
python3 -m pip install .
Uninstalling is as easy as running:
pip uninstall os2ds-rules
Running the benchmark
After having installed the extension as described above, run the benchmarks with:
python3 -m pytest --benchmark-only test/benchmarks/
Currently, you need to build and install the extension before running the benchmark until this gets fixed.
Python Interpreter support
The Python3 extension uses the CPython
C-API, which is supported by
CPython
as standard.
We aim to support the PyPy
interpreter as well.
Usage Examples
In Python
Let us scan a python str
for occurances for CPR-Numbers:
from os2ds_rules import CPRDetector
detector = CPRDetector()
matches = detector.find_matches('This is a fake, but valid CPR-Number: 1111111118')
for m in matches:
print(m)
In C++
Consider this simple file, test.cpp
:
#include <os2dsrules.hpp>
#include <name_rule.hpp>
#include <iostream>
#include <string>
using namespace OS2DSRules::NameRule;
int main(void) {
NameRule rule;
std::string s = "This is my friend, John.";
auto results = rule.find_matches(s);
std::cout << "Found matches: \n";
for (auto m : results) {
std::cout << m.match() << '\n';
}
return 0;
}
To compile, using clang
, simply run:
clang++ -los2dsrules -std=c++20 test.cpp -o test
This will produce an executable test
in the current working directory.
Running it:
$ ./test
Found matches:
John
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 Distributions
Hashes for os2ds_rules-0.0.8-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b9788b7a8b2246ae582e733565777f42fde78a0f6f5756c02aa8e1bafa4e94e |
|
MD5 | fd3edb0217bf3ce63def0c0831fe9025 |
|
BLAKE2b-256 | b63264e64f3ab85b47aba9e1e183f1e30dd57b8eff7f7e8d392ee0cc8006b962 |
Hashes for os2ds_rules-0.0.8-pp39-pypy39_pp73-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b4a32d2e0bc45620134d52f806c7ba2119f9480a51a5f2792683cdba9c8b0cd |
|
MD5 | 972083c977d53e1715fefd5ce70908a5 |
|
BLAKE2b-256 | 3f68ed7b695e9dfb15c7e85e53a7903755e0d14d12bedf3475e5a8c3b35dc4fb |
Hashes for os2ds_rules-0.0.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97dbd014bd06b4de7eeeef21d5a0079b9f9f33092aa21afd9396385aae351393 |
|
MD5 | 2b3006e016a8ce4c69991f49a65ccb14 |
|
BLAKE2b-256 | 8d7f5b7ffbc0ae2dd97488754894f07d6d191ac0aedf931ef6cae792327d7d51 |
Hashes for os2ds_rules-0.0.8-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fd5c04b7b9305714931805e11ebb76e6b9cdd9d345ae2f9ce53d85f98dc470e |
|
MD5 | 6892e443a518ae744074d1c32fdd229d |
|
BLAKE2b-256 | 29dd9cad8157d9d5fe1a7d3d9c23f5d77bd9f677bf37e6ce0bc459d1f2a8fbec |
Hashes for os2ds_rules-0.0.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e999669a1780d1a0004ef08781f5f39bbe20dea25e7074456854c6a72ef5a549 |
|
MD5 | 9fbb2d532451fb3483b962b6b1f2b30d |
|
BLAKE2b-256 | 5c0a5e79f6139e95d58afeb71205200011c35f245b8a599612e81268cfa771a1 |
Hashes for os2ds_rules-0.0.8-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c58720f1be537fcd1602e0db6d32729da199e201e81a0fd1553014f90ffffc0b |
|
MD5 | b9722b1b593e153e649c2eeeacc7b827 |
|
BLAKE2b-256 | 778704977ffc3a3f3d7ab1f06a57cc8cea878d7ff71448d8362198b2c0c10414 |
Hashes for os2ds_rules-0.0.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba3d01a1efc0b0f82f6556bff3e47ea1b8b866b375a0f90b16c09db98c8df645 |
|
MD5 | 77f88872ddde66673d0f85690a4574ba |
|
BLAKE2b-256 | c88a69b18af65fdcfe72c70861aa0e08de57cb34c52e29f5377b47cc424c2bd6 |
Hashes for os2ds_rules-0.0.8-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2f4527c332daf3c3678d32a2c29440b1527b816ec370f0713b192fc367ee4bc |
|
MD5 | b930fc3502ab2486bde091d2cbf73e18 |
|
BLAKE2b-256 | 85bbfe4421c6a3ec4036b1aa3f75d8a143585ddef378b557cf8f8ffd5bd00c5b |