<!-- Source: https://docs.squirro.com/en/latest/api/squirro.lib.nlp.steps.filters.EntityAggregatorFilter.html -->
# EntityAggregatorFilter

**`class EntityAggregatorFilter(config)`**

Bases: [`Filter`](squirro.lib.nlp.steps.filters.Filter.md#squirro.lib.nlp.steps.filters.Filter)

The entity aggregator [`Filter`](squirro.lib.nlp.steps.filters.Filter.md#squirro.lib.nlp.steps.filters.Filter) creates a structured prediction field based on detected entities.

This filter examines entities that have been detected in previous pipeline steps (typically
from NER or entity extraction steps) and aggregates them into a structured prediction field with entity
types as keys and unique entity names as values.

**Input** - List[InputEntity]: Entities conforming to the InputEntity Pydantic model

**Output** - PredictionOutput: Structured prediction field conforming to PredictionOutput model

**Data Models:**
- InputEntity: Defines the expected structure for input entities with type, name, and extracts
- PredictionOutput: Defines the output structure as {entity_type: [unique_entity_names]}

Parameters

- `entities_field` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``'entities'`) – Field containing detected entities
- `output_field` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``'prediction'`) – Field to write resulting prediction structure
- `entity_types` ([`list`](https://docs.python.org/3.11/library/stdtypes.html#list)`, ``None`) – Optional list to filter which entity types to include.
  If None, all entity types will be used.

**Example**

```json
{
    "step": "filter",
    "type": "entity_aggregator",
    "entities_field": "entities",
    "output_field": "prediction",
    "entity_types": ["PERSON", "ORG", "GPE"]
}
```

Methods SummaryMethods Documentation

**`process_doc(doc)`**

Process a document and generate prediction structure from entities

Parameters

`doc` – Document with entities field conforming to List[InputEntity] structure

Returns

Document with prediction field conforming to PredictionOutput structure
