Package: os2ds-rules
os2ds-rules: Next-generation, high-performance rule system for OS2datascanneros2ds-rulesis the next-generation rules system for use inOS2datascannerbyMagenta 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 modernC++20.A Python C/C++ extension that exposes functionality from the backend topython.Apythonlibrary 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 StartedYou can install either or both of theC++library or thepythonextension.C++ backend library:libos2dsrulesFor theC++library you need a few different things:A compiler that supportsC++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:cppcheckorclang-analyzer: For static code analysis.clang-format: For formatting C++ code. We adhere to the LLVM style guide.clang-tidy: For C++ code linting.gdborlldb: A suitable debugger.To make a debug build onlinux, run the following:# Make a build directorycmake.--presetlinux-debug
cmake--build--presetlinux-build-debugThis will build the shared librarylibos2dsrules.soand the test suitetestsuite.To install the library, run the following from the build directory:sudocmake--installbuild_cmake/debugBy default, this will install headers into/usr/includeand shared objects to/usr/lib.To run the test suite:ctest--presetlinux-test-debugCurrently, this has only been tested onlinux.
It remains to be tested onwindowsandmacos.Using CMake preset workflowsThere 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.For example, to run a debugging workflow on linux, use:cmake--workflow--presetlinux-debug-workflowThe Python extension:os2ds-rulesYou need the following:A compiler that supportsC++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 howCPythonwas 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-devfedora:sudo dnf install python3-develTo build the extension:# From the project root.python3-msetupbuildTo install the extension locally:# From the project root.# You may want to use the `-e` option during development.python3-mpipinstall.Uninstalling is as easy as running:pipuninstallos2ds-rulesRunning the benchmarkAfter having installed the extension as described above, run the benchmarks with:python3-mpytest--benchmark-onlytest/benchmarks/Currently, you need to build and install the extension before running the benchmark
until this gets fixed.Python Interpreter supportThe Python3 extension uses theCPythonC-API, which is supported byCPythonas standard.We aim to support thePyPyinterpreter as well.Usage ExamplesIn PythonLet us scan a pythonstrfor occurances for CPR-Numbers:fromos2ds_rulesimportCPRDetectordetector=CPRDetector()matches=detector.find_matches('This is a fake, but valid CPR-Number: 1111111118')forminmatches:print(m)In C++Consider this simple file,test.cpp:#include<os2dsrules.hpp>#include<name_rule.hpp>#include<iostream>#include<string>usingnamespaceOS2DSRules::NameRule;intmain(void){NameRulerule;std::strings="This is my friend, John.";autoresults=rule.find_matches(s);std::cout<<"Found matches:\n";for(autom:results){std::cout<<m.match()<<'\n';}return0;}To compile, usingclang, simply run:clang++-los2dsrules-std=c++20test.cpp-otestThis will produce an executabletestin the current working directory.Running it:$./test
Foundmatches:
John