EntityExtraction.h header
#include <ew/app/EntityExtraction.h>
Namespace ew::app
ExtractedEntity struct
struct ew::app::ExtractedEntity
One worldbuilding entity an AI proposed from a manuscript: a suggested name, a suggested codex category ("Characters", "Locations", "Items", "Organizations", "Events", or "Other"), and a one-sentence summary grounded in the prose. The desktop review UI turns the ones the writer accepts into codex entities. Backs DESIGN §4.8 "generate a codex from a manuscript".
Members
QString ew::app::ai::knowledge::ExtractedEntity::name
The proposed entity name.
QString ew::app::ai::knowledge::ExtractedEntity::category
The suggested category label (one of the fixed set; "Other" when the model is unsure).
QString ew::app::ai::knowledge::ExtractedEntity::summary
A one-sentence description drawn from the manuscript.
bool operator==(const ExtractedEntity &, const ExtractedEntity &)=default
Extracted entities compare equal when every field matches.
Functions
app::ai::AiRequest ew::app::ai::knowledge::buildEntityExtractionRequest(const QString &manuscriptText, const QStringList &existingNames)
Builds an AI request that asks the model to extract the worldbuilding entities mentioned in manuscriptText – characters, locations, items, organizations, events – as a strict JSON array for parseEntityExtractionResponse, excluding any whose name is already in existingNames (so it proposes only what the codex is missing). Pure (assembles the prompt only); the caller fills the model from settings and sends it via an AiProvider, then parses the reply. The model name is left empty for the caller to set.
QStringList ew::app::ai::knowledge::existingEntityNamesForAi(const ew::core::project::Project &project)
The entity names the model may be told already exist (so it does not propose them again), excluding entities the writer opted out of AI: naming one is telling the model it exists.
QString ew::app::ai::knowledge::manuscriptTextForAi(const ew::core::project::Project &project)
The manuscript prose the AI may read: every document's body in project order, separated by blank lines, EXCLUDING any document the writer opted out of AI.
The opt-out is a per-object promise the app makes on its right-click menu, and for a document it covers the whole body – a private chapter or a GM-secrets note is exactly the kind of thing a writer excludes, and "Generate Codex from Manuscript" used to send all of it (F-0112).
std::vector< ExtractedEntity > ew::app::ai::knowledge::parseEntityExtractionResponse(const QString &content)
Parses a model reply content (the assistant text from an entity-extraction request) into the proposed entities. Tolerant of a JSON array wrapped in code fences or surrounding prose: it reads the first '[' through the last ']' and parses that. Entries with an empty name are dropped, a missing category defaults to "Other", and duplicate names (case-insensitive) are collapsed to the first. Returns an empty vector when no JSON array is present or it is malformed. Pure and unit-testable (no network).