SearchString is a custom implementation for searching strings for overvaagning.app.
Project description
Search String
Installation
You can install search-string from PyPI:
$ pip install search-string-overvaagning
The package is supported on Python 3.8+. However, the package is only compiled using mypyc starting from Python 3.10 which makes it about twice as fast. As such, it is strongly advised to run it on Python 3.10+.
About
This package implements the search string object that is used across km24.dk for different types of surveillance.
It is used for searching a text. For something to be deemed a match, the text must match the first_str and if the second_str is not empty, the text must also match the second_str. If the not_str is not empty, the text must not match the not_str. A logical AND is used between the three conditions. The three strings can each be a collection of strings separated by semicolons wherein a match is deemed by logical OR. You can use '~' to make a word boundary. Finally, you can use !global at the end of a string to signal that that part should check globally.
Quick examples:
>>> ss = SearchString('example;hello', 'text', 'elephant', data=None)
>>> ss.match('This is an example text')
True
>>> ss.match('This text says hello')
True
>>> ss.match('This is just an example')
False
Usage
Creating Search Strings
Start by importing the SearchString class:
>>> from search_string import SearchString
Construct a new search string by supplying the first_str, second_str, not_str and any data that can be useful to refer back to later, such as an ID:
>>> ss = SearchString('first', '', '', data=2)
Optionally, you can also supply a third_str that works in the same was as first_str and not_str but has to be supplied as a keyword argument:
>>> ss = SearchString('first', '', '', data=2, third_str='third')
Matching text
If you just need to find out whether a given search string matches a text, you can use the method .match on a SearchString instance.
Often, what you want to do, is to match a collection of search strings across a list of text, e.g. sentences. You can do that the following way:
>>> from search_string import SearchString
>>> search_strings = [
... SearchString('kan', '', 'ritzau', data=1),
... SearchString('kan', '', 'ritzau!global', data=2)
... ]
>>> sentences = [
... 'Du kan skrive din tekst her.',
... 'Den kan bestå af flere sætninger.',
... 'Dig og Ritzau kan bestemme hvordan det skal være.',
... 'Nogle kan være lange, andre kan være korte.'
... ]
>>> res = SearchString.find_all(sentences, search_strings)
>>> res
[SearchString(kan, -, ritzau, data=1)]
For each of the matched search strings (in the above example, only one), you can extract the data and the matched text as follows:
>>> res[0].data
1
>>> res[0].matched_text
'Du kan skrive din tekst her. Den kan bestå af flere sætninger. (...) Nogle kan være lange, andre kan være korte.'
>>> res[0].matched_text_highligthed
'Du <b>kan</b> skrive din tekst her. Den <b>kan</b> bestå af flere sætninger. (...) Nogle <b>kan</b> være lange, andre <b>kan</b> være korte.'
Matching when you have many search strings
If you have a problem where you repeatedly will be matching new texts against the same collection of search strings, it is highly advised to use the SearchStringCollection which behind the scenes uses a trie for efficient search when many search strings are present. There is some initial cost in building the trie. Thus, it is recommended that you initialize the collection once and then continue to use it.
The most important method on SearchStringCollection is find_all, which takes a sentence (str) or list of sentences (list[str]) and returns the matched search strings, very similar to the familiar SearchString.find_all.
>>> from search_string import SearchString, SearchStringCollection
>>> search_strings = [
... SearchString('kan', '', 'ritzau', data=1),
... SearchString('kan', '', 'ritzau!global', data=2)
... ]
>>> ss_collection = SearchStringCollection(search_strings)
>>> res = ss_collection.find_all()
>>> res
[SearchString(kan, -, ritzau, data=1)]
Importantly, SearchStringCollection relies on the data variable being set on the collection of search strings. If it is set to None or multiple search strings have the same value, the behavior is undefined.
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 Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file search_string_overvaagning-0.3.11-py3-none-any.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcc1198d9b06a753272919dae248060fe4f422066024c931c7fda11a3087921d
|
|
| MD5 |
7dbf679629a0409ec88f5e1a83f5c3c1
|
|
| BLAKE2b-256 |
1f9ab8e67646ad2dc21324fdae9c0b64301a0f77727755b91e5e4432c871963e
|
File details
Details for the file search_string_overvaagning-0.3.11-cp312-cp312-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 220.3 kB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
419171417d7d69b229249b0f7ada6b99cf320e3ceda17b67c273124330a31394
|
|
| MD5 |
2e4a663238974636a202fc55f9a06086
|
|
| BLAKE2b-256 |
1268bea3bc1f50bfb9dd0e226f8102456f5e26182d58f8c9ccc935976de77c6b
|
File details
Details for the file search_string_overvaagning-0.3.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 227.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e08a6a88180631b0e8ecfcdde581818763ff2d26e9e3d1a7dfe2a952b0d25a
|
|
| MD5 |
a3eaea342512606cf273e61585efd617
|
|
| BLAKE2b-256 |
7c29dc706fea8047045f4c57cbccd5c0bc1d97390998d323a3eb5dac8d47ccb3
|
File details
Details for the file search_string_overvaagning-0.3.11-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 125.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c587f72fdbaa05eb69ecfa689358d9d5928a0bb89594ce204155fc41d0b3a38f
|
|
| MD5 |
4706bcb03487993d3c4829b4977feb08
|
|
| BLAKE2b-256 |
029b51e79fef074d1cfafb625d63737e094ae1641aa9f61967c63c02abe56505
|
File details
Details for the file search_string_overvaagning-0.3.11-cp312-cp312-macosx_10_9_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 130.7 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f83ad0713c84e3083ea2c5f2e1fa785f772b36b64f84e2dc04602ce425e8c621
|
|
| MD5 |
03adcff1433a6867e6662b5d383e8131
|
|
| BLAKE2b-256 |
4133ba284e26535ffb4c05123b137c108695998f5746262421155ea89ea3e719
|
File details
Details for the file search_string_overvaagning-0.3.11-cp312-cp312-macosx_10_9_universal2.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp312-cp312-macosx_10_9_universal2.whl
- Upload date:
- Size: 239.9 kB
- Tags: CPython 3.12, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be9d8de4a66257434e0f7f1cc9e2b9300216ba54d985d3c4d15a334b7dcd6d92
|
|
| MD5 |
f255e0c3541077b6e694b8ac088fc401
|
|
| BLAKE2b-256 |
0cb671764ba5bbbb02b2f912413052ac344bc643e18cca299983b880c0737164
|
File details
Details for the file search_string_overvaagning-0.3.11-cp311-cp311-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp311-cp311-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 212.5 kB
- Tags: CPython 3.11, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3586bf1dee7ad8c0854fa509c91068773a1745388384f066e0bafcac9714909a
|
|
| MD5 |
e7c1cf7adfc0aacb07e7ca252ea27bad
|
|
| BLAKE2b-256 |
48335d8609244084986493a8593d9b558941d3f2444526acccb88c60d0c72470
|
File details
Details for the file search_string_overvaagning-0.3.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 218.7 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bb9b3c9271a1efb01c0b4db876e867475c19b5eea131d6c01eca43daa8f2c3a
|
|
| MD5 |
4b6222ec348a987fb3613b7c3b123d27
|
|
| BLAKE2b-256 |
72546b2671096431db40e4cfbc48b00a810f94552dda1e4da226bc0d8e27b18c
|
File details
Details for the file search_string_overvaagning-0.3.11-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 124.5 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9930c00b97a6dcdc0df591439ff8ce9c5aba3d71a0e279de4b465658af21af19
|
|
| MD5 |
142fccd66c6b6395f86643b7186c0211
|
|
| BLAKE2b-256 |
ca9267038b7e077f2042ac373d460f5c5de8d205cdf92b80568a404bbc370980
|
File details
Details for the file search_string_overvaagning-0.3.11-cp311-cp311-macosx_10_9_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 128.7 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af618512dc3976addb076d62e83cf4cc8724ba4f7c2dd563b91a1ff69982b904
|
|
| MD5 |
a58ee149456a5f8d51f02c663a883918
|
|
| BLAKE2b-256 |
1a36baba65fafe84fc8bec26a06d4abb1cba2d084ff2184e78e118814898d7f2
|
File details
Details for the file search_string_overvaagning-0.3.11-cp311-cp311-macosx_10_9_universal2.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 236.9 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5f055da07e9b5e60e8799dfcf3b5437de84e7a4cdea292c9e3ae3546b5f84de
|
|
| MD5 |
6fa1c8aa9bd6ac7bbaf12ec2278c2c34
|
|
| BLAKE2b-256 |
32443a249ec554b25e75c5eac233a9694d73286ad683f549fe9d8e06e7ba2410
|
File details
Details for the file search_string_overvaagning-0.3.11-cp310-cp310-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 213.3 kB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8800d993303c33c0dfcd5ebd3191fce72ff76aafd0f9d93820abf75e14f97dd1
|
|
| MD5 |
211e4e6b2dee2a3a7439a2e400401c25
|
|
| BLAKE2b-256 |
b1e1e1cd7475607e84a9c6add256a2f790b04022254c03849a6659b5902896c2
|
File details
Details for the file search_string_overvaagning-0.3.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 219.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f9e47f7d0e7ae4c6d786dde812c6198e1f5a929fdd1ab6a4035d1acc357640
|
|
| MD5 |
85ee0a4dfbaddae61d8bd7ef8daef2fc
|
|
| BLAKE2b-256 |
a44af076f421dac71c973c1466ed189f638c452632edc25bea0e9f9f74239cd6
|
File details
Details for the file search_string_overvaagning-0.3.11-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 125.9 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4815fac385b4eef519992db5d0aef59385ff9d25e320c609b55e42c7febf03f5
|
|
| MD5 |
80fce94e2bbb4cea3058aca55598558c
|
|
| BLAKE2b-256 |
cb315703fb6d68d3e62b9df68d4fdb42eef4c128a26926af8b542ae574ea6461
|
File details
Details for the file search_string_overvaagning-0.3.11-cp310-cp310-macosx_10_9_x86_64.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 130.0 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c909957f06c01eb1bc0b97269702b5f61596f2c7f637b3e95e06174764872afd
|
|
| MD5 |
071bd99b43aeb14520d4ae79b4f7ac17
|
|
| BLAKE2b-256 |
c906fa67f6d781eb56e5c738efaecdad3e029889374afe3ae6a8106a12ebbda8
|
File details
Details for the file search_string_overvaagning-0.3.11-cp310-cp310-macosx_10_9_universal2.whl.
File metadata
- Download URL: search_string_overvaagning-0.3.11-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 239.8 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d157d15ecd51278024325ac3da9cd986251ee4ba60467ad9721099ea37739cf4
|
|
| MD5 |
9b85f199af28d92aa906d542c880f58e
|
|
| BLAKE2b-256 |
7a1575cbfba45cd442a22ed715d53c01ccd7f36f445bf3b5ef7b004c0174aaa9
|