File size: 2,077 Bytes
ed6bec6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from typing import Dict, Any
from .glyph_decoder.py import decode_glyphs
from .glyph_encoder import encode_meaning
from .glyph_validator import validate_sequence, validate_roles
from .glyph_syntax import get_syntax_tree


def interpret(glyph_string: str) -> Dict[str, Any]:
    """
    High-level API: glyph string → structured meaning.
    """
    glyphs = list(glyph_string)
    return decode_glyphs(glyphs)


def encode(structured: Dict[str, Any]) -> str:
    """
    High-level API: structured meaning → glyph string.
    """
    return encode_meaning(structured)


def validate(glyph_string: str) -> None:
    """
    High-level API: validate glyph string.
    """
    glyphs = list(glyph_string)
    validate_sequence(glyphs)
    validate_roles(glyphs)


def explain(glyph_string: str) -> str:
    """
    Human-readable explanation of a glyph sequence.
    Prototype: uses primary meanings.
    """
    glyphs = list(glyph_string)
    tree = get_syntax_tree(glyphs)

    parts = []

    def names(entries):
        return [e.get("primary", e.get("id", "?")) for e in entries]

    if tree["actors"]:
        parts.append(f"Actors: {', '.join(names(tree['actors']))}")
    if tree["actions"]:
        parts.append(f"Actions: {', '.join(names(tree['actions']))}")
    if tree["objects"]:
        parts.append(f"Objects: {', '.join(names(tree['objects']))}")
    if tree["modifiers"]:
        parts.append(f"Modifiers: {', '.join(names(tree['modifiers']))}")

    ctx = tree["context"]
    if ctx["place"]:
        parts.append(f"Place context: {', '.join(names(ctx['place']))}")
    if ctx["time"]:
        parts.append(f"Time context: {', '.join(names(ctx['time']))}")
    if ctx["emotion"]:
        parts.append(f"Emotional context: {', '.join(names(ctx['emotion']))}")
    if ctx["sensory"]:
        parts.append(f"Sensory context: {', '.join(names(ctx['sensory']))}")
    if ctx["social"]:
        parts.append(f"Social context: {', '.join(names(ctx['social']))}")

    if not parts:
        return "No semantic structure detected."

    return " | ".join(parts)