nepal_address 0.1.1
nepal_address: ^0.1.1 copied to clipboard
Offline database and bilingual search for Nepal administrative divisions: provinces, districts, local levels, and wards.
nepal_address #
An offline, zero-dependency Dart package providing an embedded database and bilingual search for Nepal's administrative divisions: provinces, districts, local levels (municipalities and rural municipalities), and wards.
Features #
- Zero Runtime Dependencies: Pure Dart implementation that runs entirely offline in any Dart or Flutter environment.
- Relational Administrative Hierarchy: Hierarchical relations from Province -> District -> Local Level -> Ward.
- Bilingual Models: English and Nepali (Devanagari) names for every province, district, local level, and local level type.
- Bilingual Search Engine: Search supporting English, Devanagari, and Romanized phonetic spellings, with alias matching and fuzzy tolerance.
- Structured Address Formatting:
SelectedAddressutility for composing, formatting, and serializing addresses in English, Nepali, or bilingual styles. - Dataset Provenance & Metadata: Programmatic access to upstream data sources, release dates, and verification metrics via
DataInfo.
Installation #
Add nepal_address to your pubspec.yaml:
dependencies:
nepal_address: ^0.1.0
Then import the package in your Dart code:
import 'package:nepal_address/nepal_address.dart';
Quick Start #
1. Data-Only Lookups #
All administrative collections and hierarchical lookup methods are accessible statically through NepalAddress:
import 'package:nepal_address/nepal_address.dart';
void main() {
// Read dataset counts and release date from DataInfo
final info = NepalAddress.dataInfo;
print('Release Date: ${info.releaseDate}');
print('Last Reviewed: ${info.lastReviewed}');
print('Provinces: ${NepalAddress.provinces.length}');
print('Districts: ${NepalAddress.districts.length}');
print('Local Levels: ${NepalAddress.localLevels.length}');
print('Wards: ${NepalAddress.wards.length}');
// Hierarchical Queries
final districtsInKoshi = NepalAddress.getDistrictsByProvinceId(1);
for (final d in districtsInKoshi) {
print('${d.nameEn} (${d.nameNp})');
}
final localLevelsInBhojpur = NepalAddress.getLocalLevelsByDistrictId(1);
for (final ll in localLevelsInBhojpur) {
print('${ll.nameEn} (${ll.nameNp}) - ${ll.type.nameEn}');
}
// Wards are generated on demand:
final wardsInShadanand = NepalAddress.getWardsByLocalLevelId(1);
print('Wards count: ${wardsInShadanand.length}');
}
2. Bilingual Search #
NepalAddress.search provides indexed query execution across names and aliases:
import 'package:nepal_address/nepal_address.dart';
// Basic English search
final results = NepalAddress.search('Kathmandu');
// Nepali search (handles Unicode normalization and variants automatically)
final nepaliResults = NepalAddress.search('काठमाडौँ');
// Romanized phonetic search (e.g. "Katmandu" matches "Kathmandu")
final phoneticResults = NepalAddress.search('Katmandu');
// Scoped and filtered search
final scopedResults = NepalAddress.search(
'Patan',
scope: const SearchScope(provinceId: 3),
levels: {SearchLevel.localLevel},
limit: 10,
);
Search Ranking Order
Results are ranked strictly by match precision and hierarchy:
- Match Type:
exact>prefix>wordPrefix>contains>fuzzy(Levenshtein edit distance $\le 1$ for queries up to 6 characters, $\le 2$ for longer queries). - Score: Higher match ratio score breaks ties.
- Primary Name vs Alias: Within the same match type and score, a match on the primary name (
nameEnornameNp) ranks before a match on an alias. - Text Length: Shorter matching names/aliases rank higher.
- Administrative Level: Higher tiers rank first (
province>district>localLevel). - Deterministic Tie-Breaker: Alphabetical sorting by
fullPathEn.
Spelling Variants, Old Names & Aliases
Spelling variants and old names are matched through aliases (e.g., "Province No. 1" matches Koshi Province; "Pokhara Lekhnath" matches Pokhara; "Pachthar" matches Panchthar).
When searching "Patan", two distinct places match exactly on that spelling and both are returned with their full hierarchical paths:
Patan, Baitadi, Sudurpaschim Province(via municipality primary name"Patan")Lalitpur, Lalitpur, Bagmati Province(via common name of Lalitpur city"Patan")
Because primary-name matches rank before alias matches for the same match type and score, Patan (Baitadi) ranks first and Lalitpur ranks second.
3. SelectedAddress Model #
SelectedAddress represents a completed or partial address, providing helpers for formatting and JSON serialization:
final address = SelectedAddress.fromEntities(
province: NepalAddress.getProvinceById(3),
district: NepalAddress.getDistrictById(27),
localLevel: NepalAddress.getLocalLevelById(307),
wardNumber: 1,
);
// Formatting helpers
print(address.en); // "Ward 1, Kathmandu, Kathmandu, Bagmati Province"
print(address.np); // "वडा नं. १, काठमाण्डौं, काठमाडौँ, बाग्मती प्रदेश"
print(address.bilingual); // "Ward 1 (वडा नं. १), Kathmandu (काठमाण्डौं), Kathmandu (काठमाडौँ), Bagmati Province (बाग्मती प्रदेश)"
// Custom formatting
final custom = address.formatted(
separator: ' | ',
order: AddressOrder.descending,
language: NepalAddressLanguage.bilingual,
);
// Serialization
final jsonMap = address.toJson();
final restored = SelectedAddress.fromJson(jsonMap);
assert(restored == address);
Language Options #
SelectedAddress and entity models support three language representation styles via NepalAddressLanguage:
- English: Romanized names (
NepalAddressLanguage.english). - Nepali: Native Devanagari names with Devanagari numerals for wards (
NepalAddressLanguage.nepali). - Bilingual: Formatted combination
English (नेपाली)(NepalAddressLanguage.bilingual).
Wards & Identifiers #
- Wards: Wards are numbered 1..wardCount per local level. No ward names, codes or boundaries are included.
- IDs: IDs are this package's own and stable within a major version. They are not official government codes.
Dataset Provenance #
Cross-checked from three open MIT-licensed sources (sagautam5/local-states-nepal, younginnovations/nepal-locallevel-map, bedbyaspokhrel/nepal-geo-data). Not an official government dataset. 12 known source conflicts are listed as unverified.
See VERIFICATION.md for detailed conflict listings, pending matches, and verification status, and THIRD_PARTY_NOTICES.md for complete upstream copyright notices, source dataset repository URLs, and licenses.
Known Limitations #
- Not Official: This package is not an official government dataset, nor is it endorsed by the Government of Nepal or the Ministry of Federal Affairs and General Administration (MoFAGA).
- No Geographic Polygons: Spatial boundaries, GeoJSON polygons, and GPS centroid coordinates are deliberately excluded to maintain a lightweight, zero-dependency pure Dart library.
- Source Dataset Discrepancies: Names come from source datasets, so the same city can be spelled differently at different administrative levels (for example, Kathmandu district is spelled
काठमाडौँwhile the local level is spelledकाठमाण्डौंin Nepali). - Unverified Conflicts: Upstream source conflicts that could not be reconciled definitively are cataloged in
DataInfo.verification.unverifiedConflictsand detailed in VERIFICATION.md.
Version Compatibility #
- Dart SDK:
>=3.8.0 <4.0.0 - Flutter:
>=3.32.0
Contributing #
Contributions, bug reports, and alias additions are welcome! Please read CONTRIBUTING.md for guidelines on reporting data issues and running the data build pipeline.