semkit
Обработка семантического ядра: чтение и запись фраз в любом формате, леммы, n-граммы, дубли
Library
import pandas as pd
import rb_semkit as sk
phrases = pd.Series(["купить диван", "Диван бу", None])
sk.find(phrases, sk.words(["диван"])) # [True, True, False]
sk.remove(phrases, sk.words(["диван"])) # ["купить", "бу", ""]
sk.extract(phrases, sk.words(["диван"])) # ["диван", "Диван", ""]
sk.lemmatize(pd.Series(["купила диваны"])) # ["купить диван"]
sk.part_of_speech(pd.Series(["москве"])) # ["n"]
sk.wordforms("москва") # [..., "москве", ...]
sk.decline(pd.Series(["купить красный диван"]), "genitive") # ["купить красного дивана"]
sk.decline_full_name(pd.Series(["Петрова Анна Ивановна"]), "accusative") # ["Петрову Анну Ивановну"]
sk.agree(pd.Series(["растаможить машина", "легковой машина"]))["agreed"] # ["растаможить машину", "легковая машина"]
df = pd.DataFrame({"phrase": ["купить диван бу"], "freq": [10]})
sk.remove(df, sk.words("бу"), column="phrase") # adds "phrase_remove" right after "phrase"
sk.remove(df, sk.words("бу"), column="phrase", inplace=True) # replaces "phrase"
sk.pipe(df, "phrase").remove(sk.words("бу")).remove(sk.words("купить")).phrases
- Input: a Series of phrases, or a DataFrame with
column=. NaN and None are empty strings. - Output: a Series with the input index, or the input DataFrame itself with the new column
<column>_<operation>(the function adds it to your object and returns that object; passdf.copy()to keepdf). - One matcher (
sk.words(...)), three verbs:find(bool mask),remove(cleaned text),extract(found part). A phrase splits on any whitespace; words compare by case and ё = е; the output keeps the original text. sk.words(items, mode="any"|"all", where="anywhere"|"start"|"end", ignore_punct=False, lemmatizer=None). With alemmatizerit compares lemmas («диваны» = «диван»); without one, words as they are.- Lemmas: the !SEMTools dictionary, then pymorphy3, then the add-in's suffix table;
fallback="pymorphy"gives every word missing from the dictionary the pymorphy3 guess instead; any object withlemma(word),pos(word)andforms(lemma)works aslemmatizer=. sk.text_stats(data, lemmatizer=..., column=None): per text,chars,chars_no_spaces,words,unique,water,nausea_classic,nausea_academic,top,ttr,mtld,zipf(definitions in the docstring); withcolumn=the metric columns followcolumn;no_digits=Trueandexclude=[...]leave words out of every count.sk.summary(df): per numeric column,count,mean,median,min,max.sk.compare_statsandsk.compare_gramsgive ameanbeside the median (norm="mean"sets the verdict by it);compare_gramsalso givesneed,have,addandmed_count(words=sets the size) andper_text=Truea density column per competitor.- Wrong input raises
sk.InvalidArguments, naming the argument and the allowed values.
The bundled data (src/rb_semkit/data/) is built from the !SEMTools sources (paths in
scripts/build_data.toml) by uv run scripts/build_data.py; the same sources give byte-identical files.
CLI
One command is a pipeline: semkit read IN STEP… write OUT. Every function of the library is a step with its own
--help (semkit read IN STEP --help); semkit --ai prints the guide for agents and the list of steps. A step
works on the working column (--column, by default the first text column), a second input is a file option
(--against, --competitors, --freq, --dictionary), and a list is @name, @file or a,b. Typical pipelines
(src/rb_semkit/data/SKILL.md shows their output; the tests run them):
# clean a core: drop the phrases with the universal minus-words by lemmas (a list of phrases: drop-phrases; single
# words go to drop-words), remove punctuation and extra spaces, drop duplicates by lemmas
semkit read core.csv drop-phrases @minus/universal --lemmas remove-chars punctuation remove-spaces extra \
dupes --kind lemmas --action drop write clean.csv
# the same with your own list: lists/niche/minus.txt (one word per line) is @niche/minus; `semkit lists` shows the names
SEMKIT_LISTS=lists semkit read core.csv drop-words @niche/minus --lemmas remove-chars punctuation remove-spaces extra \
dupes --kind lemmas --action drop write clean.csv
# the frequency dictionary of an article
semkit read --whole article.txt split-text ngrams -n 1 --lemmas write words.csv
# my text against the texts of the competitors
semkit read --whole mine.txt compare-grams --competitors competitors.csv write verdicts.csv
# a quick try: phrases from the command line, the result as a table in the terminal (no write)
semkit read --text "растаможка авто" synonym-candidates --all
# which core phrases stand in the texts
semkit read core.csv coverage --against texts.csv write coverage.csv
# SERP clusters (the table has phrase, position, url)
semkit read serp.csv cluster-serp --method hard --common 3 write clusters.csv
# the phrases only the second list has
semkit read first.csv compare-lists --against second.csv --op second write only-second.csv
# a core from word variants (one column per list): combine them into phrases, agree the words, match them to the
# pages by meaning (the extra vectors)
semkit read variants.csv linear-combinations agree nearest --against page_texts.csv --top 2 write matches.csv
A topic's phrases get a class at each other (relate-phrases): same, variation (another word of the same meaning),
refinement (the phrase of another plus more words) or other, with of (the phrase it belongs to), group (the
first phrase of its group) and reason (the rule and the link). It works by lemmas and the dictionary
(semkit models pull ruwordnet once), with no network and no vectors; 1000 phrases run in seconds. --synonyms FILE
adds the links of your topic: a column synonyms, a group in each row, items split by |
(ремонт | починка | починить), or the columns word and synonyms (split by spaces) as dupes --synonyms has.
The dictionary has gaps, and a gap is other (сделать ≁ создать, починить ≁ ремонт): the file fills them.
semkit read --text "купить диван" --text "диван купить" --text "купить угловой диван" --text "диван" relate-phrases write -
# купить диван: refinement of диван (+купить); диван купить: same as купить диван (lemmas);
# купить угловой диван: refinement of купить диван (+угловой); диван: other, group купить диван
semkit read topic.csv relate-phrases --synonyms links.csv write classes.csv
Columns keep the types of the file (numbers stay numbers). Every step, option and file an option names is checked
before the input is read; a refusal exits 2 and names the step and the option. --as NAME writes a change to a new
column NAME, which the next steps work on. --lemmas on a words or phrases step compares lemmas, as the bundled
lists hold them. --json, --quiet and --dry-run go before the steps: semkit --json read … prints one envelope
{"ok": true, "output", "rows", "written", "steps"} (steps: one summary per step, with a note when the step tells
more), --quiet hides the lines on stderr, --dry-run runs the steps and writes nothing (it also keeps init, config set, skill install, lists add and lists rm from writing).
--trace FILE records every cell a step changed (row 1 is the first row under the header), write OUT --overwrite
replaces an existing file (and an existing trace). write OUT --columns NAME,NAME --rename OLD=NEW chooses, orders and
renames the output columns (… nearest --to Q write - --columns phrase,similarity --rename similarity=сходство); an
unknown name or a clash exits 2 and lists the columns there are. read --text TEXT (repeatable) takes the phrases from the command
line instead of IN: a table with the column phrase, a row for each --text. A pipeline without write prints the
result as a table (every column, every row) in the terminal; with --json, or when stdout is not a terminal, it writes
JSONL to stdout as write - does.
A frequent chain runs by its name: semkit run NAME runs a workflow, a named chain of semkit's own steps, as one read
pipeline. semkit run --help lists the workflows, semkit run NAME --help shows the parameters with their defaults
and the steps. A project adds its own as .rb_semkit/workflows/NAME.toml (one of the same name overrides the bundled
one).
# phrase synonyms of one intent: every variation of the phrase by the thesaurus, scored by meaning against it
semkit run intent-synonyms --text "растаможка авто"
# a parameter, and an option of one of the steps
semkit run intent-synonyms core.csv --set threshold=0.85 --set nearest.model=e5-small write synonyms.csv
Your own lists: SEMKIT_LISTS=DIR (a relative folder is from the current one) or semkit config set lists '["DIR"]';
SEMKIT_LISTS wins over the config. semkit lists shows every list, semkit lists show @NAME its items.
Development
uv sync
uv run semkit --help
# the full gate (run before every commit; CI runs it too), at the template tag of .copier-answers.yml
uvx --from "git+https://github.com/bolandeu/cli-generator.git@v1.27.3#subdirectory=gate" gate check
uv run pytest -m speed # the timed tests, left out of the gate: run on an idle machine
uv run pytest --snapshot-update # after changing a command's help; review tests/snapshots/help/
pytest fails below the coverage floor in pyproject.toml; ruff includes
the security (S) rules; the gate also scans the git history for committed
secrets when gitleaks is installed (brew install gitleaks) and uv.lock
for known vulnerabilities when osv-scanner is installed (brew install osv-scanner), and says it skipped a scan otherwise. CI is optional and only repeats
gate check.
Release
The version is the git tag (vX.Y.Z) — pyproject.toml has no version =.
Work and releases go through Antagor. Nobody tags or pushes by hand.
Install
On this machine, from a local checkout:
uv tool install .
From the Gitea registry (the package is released there):
</code></pre>
<p><strong>Or from the git tag, on any other machine (any OS):</strong></p>
<pre><code class="language-bash">uv tool install "rb-semkit @ git+https://github.com/bolandeu/rb-semkit.git@vX.Y.Z"
Replace vX.Y.Z with the latest release tag (never install a branch). This is also how an AI agent
bootstraps this CLI on a fresh machine/sandbox where it isn't installed
yet — see src/rb_semkit/data/SKILL.md.
Update an installed copy to the latest commit:
uv tool upgrade rb-semkit
After install, the command semkit is available globally, on
macOS, Linux and Windows alike (no shelling out, no hardcoded POSIX paths).
To pick up later architecture changes from the cli-generator template
itself, run copier update in this repo (requires this repo and the
template to both be git repos; see the cli-generator plugin's README).
Architecture
This project follows a fixed CLI architecture:
src/rb_semkit/commands/— argument parsing only, no business logic.src/rb_semkit/core/— services, models, errors: the real logic.src/rb_semkit/providers/— external APIs/integrations.src/rb_semkit/credentials/— secrets via the OS keychain (keyring) and environment variables. Secrets never live in.rb_semkit/config.toml.src/rb_semkit/output/— human (rich) and--jsonrendering.
Run semkit doctor to check environment/config/auth readiness, and
semkit --help for the full command surface. Every command supports
--json for machine/agent consumption; errors are structured (error.code,
fixed exit codes, error.action telling you what to do next) and go to
stderr in human mode, so stdout is always safe to pipe.
A project can require a minimum CLI version in its .rb_semkit/config.toml
([cli] min_version = "...", set or lowered by semkit config set cli.min_version X); every command checks it, an
older install refuses with exit 6 and uv tool upgrade rb-semkit fixes it.
See src/rb_semkit/data/SKILL.md for the agent-facing usage guide
bundled with this package — install it into an AI tool with
semkit skill install, or get it as plain text with
semkit --ai (works even without file access).
Metadata
Release files for rb-semkit 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rb_semkit-0.2.5.tar.gz | 9.1 MB | Without provenance | Details for rb_semkit-0.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rb_semkit-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for rb_semkit-0.2.5-py3-none-any.whl |
Total release size: 17.9 MB
Release files / rb_semkit-0.2.5.tar.gz
| Download URL | rb_semkit-0.2.5.tar.gz |
|---|---|
| Size | 9.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7151a505eaf883bca281ac5f38b4e1fe4a2ed1fdb233651e7054a09bb2de3c22
|
|
BLAKE2b-256 checksum How to use checksums |
9b6b92edce3f8e1cd5bf81c2928dc6211026ee9bd6dcf90276a511ac073d13be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / rb_semkit-0.2.5-py3-none-any.whl
| Download URL | rb_semkit-0.2.5-py3-none-any.whl |
|---|---|
| Size | 8.7 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7875b068b536a01844bd33a10d7efb583c53e176cea103e37374108e8944d158
|
|
BLAKE2b-256 checksum How to use checksums |
a432ebb763c4fb8295f654760b35a83c1fcdd044133a565a58256a78738c767e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for rb-semkit 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.