{# FE2-4: knowledge-graph fragment — lazy-loaded into #corpus-graph. Context: doi — the seed paper's DOI. snapshot — get_paper_snapshot() shape, or None when the graph isn't built: {metadata, entities_by_type, relationships_in, relationships_out}. entities_by_type : {type: [{canonical_id, type, surface, ...}]} relationships_out : [{predicate, target_kind, target_id, evidence, ...}] relationships_in : [{predicate, source_doi, evidence, ...}] error — True when the snapshot raised (generic notice, no detail leaked). All content is rendered through Jinja autoescape ONLY — never |safe, never striptags (scientific text legitimately contains < and >). #}

Knowledge graph

{% if error %}

Could not load the knowledge graph — check the server logs.

{% elif snapshot is none %}

No knowledge graph is built yet. Run lit-monitor graph backfill --all to build the graph for this paper.

{% else %} {# --- Entities grouped by type ------------------------------------------- #}

Entities

{% set _entities = snapshot.entities_by_type or {} %} {% if _entities %} {% for type_, items in _entities.items() %}

{{ type_ }} {% for e in items %} {# Show the surface form (human-readable) plus the canonical_id so the normalized identity is visible too; fall back to either if one is blank. #} {{ e.surface or e.canonical_id }} {% if e.surface and e.canonical_id and e.surface != e.canonical_id %} ({{ e.canonical_id }}) {% endif %} {% endfor %}

{% endfor %} {% else %}

No entities linked to this paper in the graph.

{% endif %} {# --- Relationships (outgoing + incoming) -------------------------------- #}

Relationships

{% set _out = snapshot.relationships_out or [] %} {% set _in = snapshot.relationships_in or [] %} {% if _out or _in %} {% for r in _out %} {% endfor %} {% for r in _in %} {% endfor %}
DirectionPredicateOther paper / entityEvidence
out {{ r.predicate }} {% if r.target_kind == "Paper" and r.target_id %} {{ r.target_id }} {% else %} {{ r.target_id }} {% endif %} {{ r.evidence or "" }}
in {{ r.predicate }} {% if r.source_doi %} {{ r.source_doi }} {% else %} {% endif %} {{ r.evidence or "" }}
{% else %}

No relationships recorded for this paper in the graph.

{% endif %} {% endif %}