# `LeXtract.Resolver`
[🔗](https://github.com/YgorCastor/lextract.git/blob/main/lib/lextract/resolver.ex#L1)

Parses LLM output into Extraction structs.

Handles conversion from JSON/YAML format to structured Extraction records,
including attribute extraction and index parsing.

## Supported Formats

### List of extractions directly:
```json
[
  {
    "entity": "aspirin",
    "entity_index": 0,
    "entity_attributes": {"dosage": "81mg"}
  }
]
```

### Extractions key:
```yaml
extractions:
  - medication: "aspirin"
    medication_index: 0
    medication_attributes:
      dosage: "81mg"
      frequency: "daily"
```

### Multiple extraction classes per item:
```json
[
  {
    "person": "John Doe",
    "organization": "Acme Corp",
    "person_index": 0,
    "organization_index": 1
  }
]
```

## Examples

    iex> json = ~s([{"person": "John Doe", "person_index": 0}])
    iex> {:ok, [extraction]} = LeXtract.Resolver.resolve(json, :json)
    iex> extraction.extraction_class
    "Person"
    iex> extraction.extraction_text
    "John Doe"
    iex> extraction.extraction_index
    0

# `resolve_result`

```elixir
@type resolve_result() :: {:ok, [LeXtract.Extraction.t()]} | {:error, Exception.t()}
```

# `resolve`

```elixir
@spec resolve(String.t(), LeXtract.FormatHandler.format()) :: resolve_result()
```

Resolves LLM text output into a list of Extraction structs.

Automatically parses the text in the specified format and converts
the structured data into Extraction records.

## Examples

    iex> json = ~s([{"person": "John Doe", "person_index": 0}])
    iex> {:ok, extractions} = LeXtract.Resolver.resolve(json, :json)
    iex> length(extractions)
    1

    iex> yaml = "- medication: aspirin\n  medication_index: 0"
    iex> {:ok, extractions} = LeXtract.Resolver.resolve(yaml, :yaml)
    iex> hd(extractions).extraction_class
    "Medication"

# `resolve_parsed`

```elixir
@spec resolve_parsed(term()) :: resolve_result()
```

Resolves from already-parsed data (map or list).

Useful when data has been parsed elsewhere.

## Examples

    iex> data = [%{"person" => "Jane", "person_index" => 1}]
    iex> {:ok, [extraction]} = LeXtract.Resolver.resolve_parsed(data)
    iex> extraction.extraction_text
    "Jane"

    iex> data = %{"extractions" => [%{"entity" => "test"}]}
    iex> {:ok, [extraction]} = LeXtract.Resolver.resolve_parsed(data)
    iex> extraction.extraction_class
    "Entity"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
