improve parsing
This commit is contained in:
@@ -25,6 +25,8 @@ class ReceiptParseConfig {
|
||||
required this.trailingCategoryLetter,
|
||||
required this.noiseKeywords,
|
||||
required this.itemCountKeywords,
|
||||
this.rowClusterHeightFactor = 1.2,
|
||||
this.priceColumnWidthFraction = 0.25,
|
||||
});
|
||||
|
||||
final List<String> knownStores;
|
||||
@@ -44,6 +46,8 @@ class ReceiptParseConfig {
|
||||
final RegExp trailingCategoryLetter;
|
||||
final List<String> noiseKeywords;
|
||||
final List<String> itemCountKeywords;
|
||||
final double rowClusterHeightFactor;
|
||||
final double priceColumnWidthFraction;
|
||||
|
||||
factory ReceiptParseConfig.fromJson(Map<String, dynamic> json) {
|
||||
List<String> list(String section, [String key = 'list']) {
|
||||
@@ -99,9 +103,31 @@ class ReceiptParseConfig {
|
||||
),
|
||||
noiseKeywords: list('noise_footer_keywords'),
|
||||
itemCountKeywords: list('line_item_count_keywords'),
|
||||
rowClusterHeightFactor: _spatialDouble(
|
||||
json,
|
||||
'row_cluster_height_factor',
|
||||
fallback: 1.2,
|
||||
),
|
||||
priceColumnWidthFraction: _spatialDouble(
|
||||
json,
|
||||
'price_column_width_fraction',
|
||||
fallback: 0.25,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static double _spatialDouble(
|
||||
Map<String, dynamic> json,
|
||||
String key, {
|
||||
required double fallback,
|
||||
}) {
|
||||
final spatial = json['spatial_parsing'];
|
||||
if (spatial is! Map) return fallback;
|
||||
final value = spatial[key];
|
||||
if (value is num && value > 0) return value.toDouble();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static const assetPath = 'receipt-parsing-keywords.json';
|
||||
|
||||
/// True if [line] matches a config keyword.
|
||||
|
||||
Reference in New Issue
Block a user