File size: 772 Bytes
fda8fb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import annotations

import numpy as np

from app.analysis.summaries import (
    compute_incoming_importance,
    compute_outgoing_importance,
    compute_top_edges,
)


def test_summary_metrics_follow_upper_triangle() -> None:
    matrix = np.array(
        [
            [0.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [2.0, 3.0, 0.0],
        ],
        dtype=np.float32,
    )

    outgoing = compute_outgoing_importance(matrix)
    incoming = compute_incoming_importance(matrix)
    top_edges = compute_top_edges(matrix, top_k=2)

    assert outgoing == [1.5, 3.0, 0.0]
    assert incoming == [0.0, 1.0, 2.5]
    assert [(edge.source_sentence_idx, edge.target_sentence_idx) for edge in top_edges] == [
        (1, 2),
        (0, 2),
    ]