Python utilities for string matching
Project description
rexpand-pyutils-matching
A Python library providing various string matching utilities including exact matching, fuzzy matching, and LLM-powered search capabilities.
Installation
pip install rexpand-pyutils-matching
Features
- Exact string matching
- Fuzzy string matching with customizable threshold
- Levenshtein distance calculation
- Longest common subsequence finding
- LLM-powered search with exact matching and value suggestion
- Multiple similarity measures for string comparison
Usage
from rexpand_pyutils_matching import (
exact_match,
fuzzy_match,
fuzzy_search,
search, # Main search function with LLM capabilities
SimilarityMeasure, # Enum for different similarity measures
SIMILARITY_FUNCTIONS, # Dictionary of available similarity functions
)
# Basic string matching
exact_match("hello", "hello") # True
exact_match("hello", "world") # False
# Fuzzy matching
fuzzy_match("hello", "helo", threshold=0.6) # True
fuzzy_match("hello", "world", threshold=0.6) # False
# Fuzzy search with multiple candidates
fuzzy_search(
search_key="Stanford",
standard_values=["Stanford University", "Stanford", "Harvard University"],
threshold=None,
candidate_count=3,
similarity_measure=SimilarityMeasure.COMMON_PREFIX
) # [('Stanford', 1), ('Stanford University', 0.6481481481481481), ('Harvard University', 0.0)]
# Advanced search with LLM capabilities
search(
search_key="Stanford University",
standard_values=["Stanford University", "Stanford", "Harvard University"],
threshold=0.8,
candidate_count=3,
use_llm_for_exact_match=True, # Enable LLM for exact matching
use_llm_for_suggestion=True, # Enable LLM for suggesting new values
chatgpt_api_key="your-api-key" # Required for LLM features
) # {"candidate": "Stanford University", "is_suggested": False}
Requirements
- Python >= 3.11
- OpenAI API key (for LLM features)
Development
The project includes a Makefile with common development commands. First, set up your development environment:
# Create virtual environment
make venv
# Activate virtual environment (you need to do this every time you start a new shell)
source .venv/bin/activate
# Install development dependencies (this will also create venv if it doesn't exist)
make install
Other available commands:
# Run tests
make test
# Run linting checks
make lint
# Format code
make format
# Clean build artifacts
make clean
# Clean everything including virtual environment
make clean-all
# Build package
make build
# Upload to PyPI
make publish
# Run all checks before commit
make pre-commit
To deactivate the virtual environment when you're done:
deactivate
Publishing to PyPI
To publish to PyPI while excluding local test files, create or update your .gitignore file to include:
# Local test files
some_file.txt
Then follow these steps:
- Update your
setup.pyorpyproject.tomlto exclude these files from the package distribution - Build the package:
make build - Upload to PyPI:
make publish
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 Distribution
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 rexpand_pyutils_matching-0.0.9.tar.gz.
File metadata
- Download URL: rexpand_pyutils_matching-0.0.9.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e33d7b18f5473d80ec9b77f892d2648f288a051aee66942931e116121e6ae636
|
|
| MD5 |
913a6727ca2f122c6ce9ca0eadc106d3
|
|
| BLAKE2b-256 |
9e98d6a01315ea5a5c2050c6cecf60c0e1c0a79947fe3b02fb739751ae215ccf
|
File details
Details for the file rexpand_pyutils_matching-0.0.9-py3-none-any.whl.
File metadata
- Download URL: rexpand_pyutils_matching-0.0.9-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44105c58e64604a7a7dc5bf5ced932730ee516cf32dd8306d3cd713beedc9065
|
|
| MD5 |
05185eabfc07a81ac8014b0a3e06501f
|
|
| BLAKE2b-256 |
cd802bec64122b14bacf110c0c2c6c0ae15e721efc756d01311654de5dab32f3
|