A tool for matching Indian addresses to determine if they refer to the same location
Project description
Indian Address Matcher
A Python library for matching Indian addresses to determine if they refer to the same location, even when formatted differently or containing variations.
Features
- Robust Address Matching: Determine if two differently formatted Indian addresses refer to the same location
- Component Extraction: Extract key components from addresses (pincode, state, city, district, locality, etc.)
- Fuzzy Matching: Handle typos, abbreviations, and formatting differences
- Detailed Analysis: Get detailed similarity scores and component-wise comparison
- Command-line Interface: Easy-to-use CLI for quick address matching
- Interactive Demo: Visual demonstration of the matching process
- Configurable Neighboring Cities: Easy to add neighboring city relationships for improved matching
Installation
# Install directly from GitHub
pip install git+https://github.com/Karan-Choudhary/indian-address-matcher.git
# Or clone and install from source
git clone https://github.com/Karan-Choudhary/indian-address-matcher.git
cd indian-address-matcher
pip install -e .
Quick Start
Python API
from address_matcher.src.address_matcher import AddressMatcher
# Initialize the matcher
matcher = AddressMatcher(threshold=0.75)
# Compare two addresses
address1 = "123, Lakshmi Nagar, Bangalore, Karnataka - 560001"
address2 = "123 Lakshmi Ngr, Bengaluru, KA, 560001"
# Get simple match result
score, is_match = matcher.match(address1, address2)
print(f"Match score: {score:.2f}")
print(f"Is match: {is_match}")
# Get detailed match information
details = matcher.match_with_details(address1, address2)
print(details)
Command-line Interface
# Basic usage
address-matcher "123, Lakshmi Nagar, Bangalore, Karnataka - 560001" "123 Lakshmi Ngr, Bengaluru, KA, 560001"
# With detailed output
address-matcher --detailed "123, Lakshmi Nagar, Bangalore, Karnataka - 560001" "123 Lakshmi Ngr, Bengaluru, KA, 560001"
# Output as JSON
address-matcher --json "123, Lakshmi Nagar, Bangalore, Karnataka - 560001" "123 Lakshmi Ngr, Bengaluru, KA, 560001"
# Adjust matching thresholds
address-matcher --threshold 0.8 --fuzzy-threshold 90 "123, Lakshmi Nagar, Bangalore, Karnataka - 560001" "123 Lakshmi Ngr, Bengaluru, KA, 560001"
Interactive Demo
# Run the interactive demo
python -m address_matcher.demo
How It Works
The address matcher uses a multi-step approach to determine if two addresses refer to the same location:
- Preprocessing: Normalizes addresses by removing punctuation, converting to lowercase, etc.
- Component Extraction: Extracts key components like pincode, state, city, district, locality, etc.
- Similarity Calculation:
- Pincode Similarity: Exact match of pincodes (with tolerance for typos)
- Full Address Similarity: Overall text similarity using weighted algorithms
- Component Similarity: Component-wise comparison using fuzzy matching
- Final Score Calculation: Weighted combination of the above similarities
- Match Determination: Comparison of final score against a threshold
Advanced Usage
Customizing Weights
You can customize the weights for different components of the matching algorithm:
# Custom weights for address components
component_weights = {
'pincode': 0.3,
'full_address': 0.3,
'components': 0.4
}
# Initialize matcher with custom weights
matcher = AddressMatcher(threshold=0.75, component_weights=component_weights)
Configuring Neighboring Cities
You can configure city relationships to handle neighboring cities that are often used interchangeably in addresses:
# Define neighboring cities during initialization
neighboring_cities = {
'mumbai': ['thane', 'navi mumbai'],
'bangalore': ['electronic city', 'whitefield'],
'delhi': ['gurgaon', 'noida', 'faridabad']
}
matcher = AddressMatcher(neighboring_cities=neighboring_cities)
# Or add them after initialization
matcher = AddressMatcher()
matcher.add_neighboring_cities('pune', ['pimpri-chinchwad', 'hinjewadi', 'wakad'])
matcher.add_neighboring_cities('chennai', ['tambaram', 'chromepet', 'porur'])
Adjusting Fuzzy Matching Threshold
# Set a higher threshold for fuzzy matching (more strict)
matcher = AddressMatcher(threshold=0.75, fuzzy_threshold=90)
# Set a lower threshold for fuzzy matching (more lenient)
matcher = AddressMatcher(threshold=0.75, fuzzy_threshold=70)
Project Structure
address_matcher/
├── __init__.py
├── cli.py # Command-line interface
├── demo.py # Interactive demo
├── src/
│ ├── __init__.py
│ ├── address_matcher.py # Main address matcher class
│ ├── data_loader.py # Dataset loader for address components
│ ├── entity_extraction.py # Address component extraction
│ ├── fuzzy_matching.py # Fuzzy matching algorithms
│ ├── similarity.py # Similarity calculation functions
│ └── utils.py # Utility functions
└── tests/
├── __init__.py
└── test_*.py # Unit tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Thanks to all the contributors who have helped with the development of this project.
- Special thanks to the open-source community for providing the tools and libraries that made this project possible.
Project details
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 indian_address_matcher-0.1.1.tar.gz.
File metadata
- Download URL: indian_address_matcher-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39e58e29d0914358ed789ddc069b676eb42880e7a6fb4bf15d49380f2bb74a40
|
|
| MD5 |
eb4820bd29d11ac880ebd8b114cb7784
|
|
| BLAKE2b-256 |
1642aefab6dd3a2e5b253f9ccab0eada01ca41d49382633a3a8a24537fcfe093
|
File details
Details for the file indian_address_matcher-0.1.1-py3-none-any.whl.
File metadata
- Download URL: indian_address_matcher-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf137ec569c7b0c44f645d3131662fe27906543907794ce8ed0e6f8bac21cc58
|
|
| MD5 |
079e5d550faa67fa004179be9e1958a6
|
|
| BLAKE2b-256 |
31827e5e2c60f36ec938fc3e53f24f49982cb07801c18b5925e360b0efc6b1cf
|