Principle:AGI Edgerunners LLM Agents Papers Category Based Grouping
| Knowledge Sources | |
|---|---|
| Domains | Data_Organization, Data_Processing |
| Last Updated | 2026-10-10 14:30 GMT |
Overview
A data organization pattern that groups flat records into a nested hierarchical structure based on assigned category labels, enabling category-oriented views and ordered output.
Description
Category Based Grouping is the practice of transforming a flat collection of records (each tagged with one or more [category, sub_category] pairs) into a nested dict where records are organized under their category, and optionally sub-category. This pattern is the bridge between the labeling phase (where categories are assigned to individual papers) and the presentation phase (where papers are displayed grouped by category).
The pattern handles three cases:
- With sub-category: Record goes to {category: {sub_category: [records]}}
- Without sub-category (None): Record goes to {category: [records]}
- No category at all: Record goes to {Others: [records]}
Usage
Use this principle when:
- Transforming flat labeled records into a hierarchical view for document generation
- Building category-based navigation or indexes over a dataset
- Preparing data for section-based rendering where each category becomes a section
- Handling records with optional sub-categories and a fallback for uncategorized items
Theoretical Basis
The core mechanism is a multi-level grouping function:
# Abstract pattern (NOT real implementation)
def group_by_category(records):
grouped = {}
for record in records:
categories = record.get("category", [["Others", None]])
for [category, sub_category] in categories:
if sub_category is None:
grouped.setdefault(category, []).append(record)
else:
grouped.setdefault(category, {}).setdefault(sub_category, []).append(record)
return grouped
Key properties:
- Multi-label support: A record can appear in multiple categories
- Heterogeneous values: A category key maps to either a list (no sub-category) or a dict (with sub-categories)
3. Fallback bucket: Uncategorized records go to a default Others category 4. Order-independent: Records can be processed in any order; grouping is associative
The tradeoff is flexibility vs. uniformity: the heterogeneous return type (list vs dict at each category) requires the consumer to check types, but allows categories with and without sub-categories to coexist naturally.
Practical Guide
To apply this pattern:
- Read all records from their storage (e.g., all JSON files in a folder)
- For each record, read its category field (a list of [category, sub_category] pairs)
- Use setdefault to create nested structures as needed
- Handle the three cases: with sub-category, without sub-category, and no category
- The result is a nested dict ready for ordered iteration