EntityLinker.h header

#include <ew/app/EntityLinker.h>

Namespace ew::app

EntityLinker class

class ew::app::EntityLinker

Finds mentions of a project's entities in text so they can be turned into links. Names are matched whole-word and case-insensitively. Construct over a project, then call rebuild() whenever the project's entities change to refresh the name index. When two entities share a name the last one indexed wins; richer disambiguation is a later concern.

The two-argument constructor additionally indexes the names of every entity in the project's mounted libraries, so a shared-library entity auto-links in prose exactly like a local one; the resolved id then resolves across the span at click/hover time.

Members

ew::app::EntityLinker::EntityLinker(const ew::core::Project &project)

Constructs a linker that indexes the entity names of project. project must outlive this linker.

ew::app::EntityLinker::EntityLinker(const ew::core::Project &project, const MountedLibraries &libraries)

Like the single-argument constructor, but also indexes the entities of every library mounted into project via libraries, so their names auto-link too. libraries must outlive this linker.

void ew::app::EntityLinker::rebuild()

Rebuilds the name index and match pattern from the current project state.

std::vector< EntityMention > ew::app::EntityLinker::findMentions(QStringView text) const

Returns every entity-name mention in text, in order of appearance.

EntityMention struct

struct ew::app::EntityMention

One occurrence in text of an entity's display name, resolved to that entity.

Members

qsizetype ew::app::EntityMention::offset = 0

Code-unit offset of the mention within the analyzed text.

qsizetype ew::app::EntityMention::length = 0

Length of the mention in code units.

ew::core::ContentId ew::app::EntityMention::target

The entity the mention refers to.

bool operator==(const EntityMention &, const EntityMention &)=default

Mentions compare equal when every field matches.