Grow the bundled species catalog from 14 hand-curated entries to ~1200 edible/cultivated species, internationalized in 13 languages (es, en, fr, de, it, pt, ca, gl, eu, ar, zh, ja, ru — Latin + Arabic RTL + CJK + Cyrillic). - Add a reproducible generator (tool/gen_species_catalog.dart) that queries Wikidata (CC0, no attribution burden) in two phases, filters out non-vernacular noise (author citations, ranks, initials) and applies a relevance floor, then merges hand-curated, authoritative core-crop data (tool/curated_overrides.json: names, family, viability_years). GBIF is used only as an identifier. The generated species.json (v3) is committed. - Carry wikidata_qid and gbif_key through the parse/seed pipeline; the columns already existed, so no DB migration. - Rewrite seedBundled to one read + one batch (was a SELECT per species on every startup — a real cost at ~1200 rows) and keep it idempotent with backfill of the new reference fields. - Move species search filtering to SQL (LIKE) so a large catalog is not pulled into memory on every keystroke. - Cover the generator transform, the generated asset, and the new fields with tests.
33 lines
1.2 KiB
Dart
33 lines
1.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/services.dart' show rootBundle;
|
|
|
|
import 'species_repository.dart';
|
|
|
|
const _catalogAsset = 'assets/catalog/species.json';
|
|
|
|
/// Parses the bundled catalog JSON into [SpeciesSeed]s. Kept separate from asset
|
|
/// loading so it is trivially unit-testable without a Flutter binding.
|
|
List<SpeciesSeed> parseSpeciesCatalog(String jsonString) {
|
|
final data = jsonDecode(jsonString) as Map<String, dynamic>;
|
|
final entries = (data['species'] as List).cast<Map<String, dynamic>>();
|
|
return entries.map((e) {
|
|
final common = (e['common'] as Map<String, dynamic>? ?? const {}).map(
|
|
(lang, names) => MapEntry(lang, (names as List).cast<String>()),
|
|
);
|
|
return SpeciesSeed(
|
|
scientificName: e['scientific_name'] as String,
|
|
family: e['family'] as String?,
|
|
wikidataQid: e['wikidata_qid'] as String?,
|
|
gbifKey: (e['gbif_key'] as num?)?.toInt(),
|
|
commonNames: common,
|
|
viabilityYears: (e['viability_years'] as num?)?.toInt(),
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
/// Loads and parses the bundled species catalog asset.
|
|
Future<List<SpeciesSeed>> loadBundledSpecies() async {
|
|
final jsonString = await rootBundle.loadString(_catalogAsset);
|
|
return parseSpeciesCatalog(jsonString);
|
|
}
|