File size: 3,879 Bytes
03bc986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Prosody Corpus Visualizer (2012-2026)</title>
    <style>
        body { font-family: "Microsoft YaHei", sans-serif; background: #f5f7f9; padding: 20px; }
        .container { max-width: 1000px; margin: auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
        h1 { color: #2c3e50; border-bottom: 2px solid #3498db; padding-bottom: 10px; }
        .row { border-bottom: 1px solid #eee; padding: 15px 0; display: flex; align-items: flex-start; }
        .id { font-weight: bold; color: #7f8c8d; min-width: 80px; font-family: monospace; }
        .text { line-height: 2; font-size: 18px; color: #2c3e50; }
        
        /* Pause Tags (Boxes) */
        .pause { display: inline-block; padding: 0 4px; margin: 0 2px; border-radius: 3px; font-size: 12px; font-weight: bold; vertical-align: middle; line-height: 1.4; color: white; }
        .p-str { background-color: #95a5a6; } /* Grey for Structural */
        .p-cog { background-color: #3498db; } /* Blue for Cognitive */
        .p-prg { background-color: #9b59b6; } /* Purple for Pragmatic */

        /* Stress Tags (Underlines/Bold) */
        .stress-box { position: relative; display: inline-block; border-bottom: 3px solid; padding-bottom: 1px; font-weight: bold; }
        .s-norm { border-color: #27ae60; color: #27ae60; }    /* Green */
        .s-emp-int { border-color: #e74c3c; color: #c0392b; } /* Red */
        .s-emp-emo { border-color: #f1c40f; color: #d35400; } /* Orange */
        .s-con-e { border-color: #e67e22; text-decoration: wavy underline; }
        
        .tag-label { font-size: 10px; position: absolute; top: -15px; left: 0; text-transform: uppercase; white-space: nowrap; }
    </style>
</head>
<body>
<div class="container">
    <h1>Prosody Annotation Visualizer</h1>
    <input type="file" id="csvFile" accept=".csv" style="margin-bottom: 20px;">
    <div id="output"></div>
</div>

<script>
document.getElementById('csvFile').onchange = function(e) {
    const file = e.target.files[0];
    const reader = new FileReader();
    reader.onload = function(event) {
        const text = event.target.result;
        processData(text);
    };
    reader.readAsText(file);
};

function processData(csv) {
    const lines = csv.split('\n').slice(1);
    const output = document.getElementById('output');
    output.innerHTML = '';

    lines.forEach(line => {
        if (!line.trim()) return;
        // Simple CSV split (handling quoted text)
        const parts = line.match(/(".*?"|[^,]+)/g);
        if (!parts || parts.length < 2) return;
        
        const id = parts[0].replace(/"/g, '');
        let content = parts.slice(1).join(',').replace(/"/g, '');

        // 1. Process Pauses [P_...]
        content = content.replace(/\[P_STR\]/g, '<span class="pause p-str">STR</span>');
        content = content.replace(/\[P_COG\]/g, '<span class="pause p-cog">COG</span>');
        content = content.replace(/\[P_PRG\]/g, '<span class="pause p-prg">PRG</span>');

        // 2. Process Stress [S_...] + following word
        // Regex looks for [S_TAG] followed by Chinese characters or English words
        const stressRegex = /\[(S_[A-Z_]+)\]([\u4e00-\u9fa5]+|[a-zA-Z0-9]+)/g;
        content = content.replace(stressRegex, function(match, tag, word) {
            const className = tag.toLowerCase().replace(/_/g, '-');
            const label = tag.replace('S_', '').replace('_', ' ');
            return `<span class="stress-box ${className}"><span class="tag-label">${label}</span>${word}</span>`;
        });

        const row = document.createElement('div');
        row.className = 'row';
        row.innerHTML = `<div class="id">${id}</div><div class="text">${content}</div>`;
        output.appendChild(row);
    });
}
</script>
</body>
</html>