Delete index.html
Browse files- index.html +0 -1376
index.html
DELETED
|
@@ -1,1376 +0,0 @@
|
|
| 1 |
-
<!DOCTYPE html>
|
| 2 |
-
<html lang="ru">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Поиск схожих фраз</title>
|
| 7 |
-
<style>
|
| 8 |
-
:root{
|
| 9 |
-
--bg:#f5f6f8;
|
| 10 |
-
--text:#202124;
|
| 11 |
-
--panel-bg:white;
|
| 12 |
-
--panel-border:#d9dce1;
|
| 13 |
-
--panel-shadow:#0000000a;
|
| 14 |
-
--input-border:#cfd3d8;
|
| 15 |
-
--input-bg:white;
|
| 16 |
-
--btn-bg:#e8eaed;
|
| 17 |
-
--btn-text:#202124;
|
| 18 |
-
--btn-primary-bg:#111827;
|
| 19 |
-
--btn-primary-text:white;
|
| 20 |
-
--status:#6b7280;
|
| 21 |
-
--split-border:#e2e5e9;
|
| 22 |
-
--split-divider:#d9dce1;
|
| 23 |
-
--match-bg:#FFFA00;
|
| 24 |
-
--uncovered-border:#e05252;
|
| 25 |
-
--uncovered-bg:#fff5f5;
|
| 26 |
-
--uncovered-tag-bg:#ffe1e1;
|
| 27 |
-
--uncovered-tag-text:#b00000;
|
| 28 |
-
--note-text:#222;
|
| 29 |
-
--note-match-text:#222;
|
| 30 |
-
--empty:#6b7280;
|
| 31 |
-
--banner-bg:#eefbea;
|
| 32 |
-
--banner-border:#bfe8b8;
|
| 33 |
-
--banner-text:#1f7a32;
|
| 34 |
-
--summary-bg:#eefbea;
|
| 35 |
-
--summary-border:#bfe8b8;
|
| 36 |
-
--summary-pct:#1f7a32;
|
| 37 |
-
--summary-label:#3a5c3f;
|
| 38 |
-
--unused-bg:#fff8e6;
|
| 39 |
-
--unused-border:#f0dca0;
|
| 40 |
-
--unused-text:#6b4e00;
|
| 41 |
-
--chunk-title:#202124;
|
| 42 |
-
--auto-info-bg:#eef5ff;
|
| 43 |
-
--auto-info-border:#b8d4f0;
|
| 44 |
-
--auto-info-text:#1a4a7a;
|
| 45 |
-
--auto-info-b:#0d3a66;
|
| 46 |
-
--auto-label:#6b7280;
|
| 47 |
-
--legend-text:#444;
|
| 48 |
-
--legend-border:#d9dce1;
|
| 49 |
-
--by-chunk-bg:#f0f0f0;
|
| 50 |
-
--by-chunk-text:#202124;
|
| 51 |
-
--clean-border:#d9dce1;
|
| 52 |
-
--tab-bg:#e8eaed;
|
| 53 |
-
--tab-text:#202124;
|
| 54 |
-
--tab-active-bg:#1a4a7a;
|
| 55 |
-
--tab-active-text:#fff;
|
| 56 |
-
--clear-bg:#fee2e2;
|
| 57 |
-
--clear-text:#b00000;
|
| 58 |
-
--clear-border:#fca5a5;
|
| 59 |
-
--clear-hover:#fecaca;
|
| 60 |
-
--hint:#1a4a7a;
|
| 61 |
-
--hint-empty:#9ca3af;
|
| 62 |
-
--progress-bg:rgba(255,255,255,0.92);
|
| 63 |
-
--progress-bar:#e2e5e9;
|
| 64 |
-
--progress-fill:#111827;
|
| 65 |
-
--progress-text:#6b7280;
|
| 66 |
-
--progress-percent:#111827;
|
| 67 |
-
--book-bg:#f5f0ff;
|
| 68 |
-
--book-border:#d9c9f7;
|
| 69 |
-
--book-title:#4a2d80;
|
| 70 |
-
--book-label-bg:#e4d4fb;
|
| 71 |
-
--book-label-text:#4a2d80;
|
| 72 |
-
--book-path-text:#5b3a91;
|
| 73 |
-
--book-quote-text:#3a2560;
|
| 74 |
-
--book-pct-bg:#b794f6;
|
| 75 |
-
--book-pct-text:#2d1b4e;
|
| 76 |
-
--book-empty:#8a7aa8;
|
| 77 |
-
--book-error-bg:#fdecec;
|
| 78 |
-
--book-error-text:#b00000;
|
| 79 |
-
--book-error-border:#f3b8b8;
|
| 80 |
-
}
|
| 81 |
-
.dark{
|
| 82 |
-
--bg:#1a1b1e;
|
| 83 |
-
--text:#e4e4e7;
|
| 84 |
-
--panel-bg:#252629;
|
| 85 |
-
--panel-border:#3a3b3e;
|
| 86 |
-
--panel-shadow:#00000040;
|
| 87 |
-
--input-border:#3a3b3e;
|
| 88 |
-
--input-bg:#1a1b1e;
|
| 89 |
-
--btn-bg:#3a3b3e;
|
| 90 |
-
--btn-text:#e4e4e7;
|
| 91 |
-
--btn-primary-bg:#3b82f6;
|
| 92 |
-
--btn-primary-text:white;
|
| 93 |
-
--status:#9ca3af;
|
| 94 |
-
--split-border:#3a3b3e;
|
| 95 |
-
--split-divider:#3a3b3e;
|
| 96 |
-
--match-bg:#FFFA00;
|
| 97 |
-
--uncovered-border:#7f1d1d;
|
| 98 |
-
--uncovered-bg:#2a1010;
|
| 99 |
-
--uncovered-tag-bg:#5a1010;
|
| 100 |
-
--uncovered-tag-text:#fca5a5;
|
| 101 |
-
--note-text:#d4d4d8;
|
| 102 |
-
--note-match-text:#d4d4d8;
|
| 103 |
-
--empty:#9ca3af;
|
| 104 |
-
--banner-bg:#14241a;
|
| 105 |
-
--banner-border:#1f7a32;
|
| 106 |
-
--banner-text:#86efac;
|
| 107 |
-
--summary-bg:#14241a;
|
| 108 |
-
--summary-border:#1f7a32;
|
| 109 |
-
--summary-pct:#2cf776;
|
| 110 |
-
--summary-label:#86efac;
|
| 111 |
-
--unused-bg:#2a2010;
|
| 112 |
-
--unused-border:#7a5c1a;
|
| 113 |
-
--unused-text:#fde68a;
|
| 114 |
-
--chunk-title:#e4e4e7;
|
| 115 |
-
--auto-info-bg:#0c1a2a;
|
| 116 |
-
--auto-info-border:#1a5c7a;
|
| 117 |
-
--auto-info-text:#93c5fd;
|
| 118 |
-
--auto-info-b:#bfdbfe;
|
| 119 |
-
--auto-label:#9ca3af;
|
| 120 |
-
--legend-text:#d4d4d8;
|
| 121 |
-
--legend-border:#3a3b3e;
|
| 122 |
-
--by-chunk-bg:#2a2b2e;
|
| 123 |
-
--by-chunk-text:#e4e4e7;
|
| 124 |
-
--clean-border:#3a3b3e;
|
| 125 |
-
--tab-bg:#3a3b3e;
|
| 126 |
-
--tab-text:#e4e4e7;
|
| 127 |
-
--tab-active-bg:#1a5c7a;
|
| 128 |
-
--tab-active-text:#fff;
|
| 129 |
-
--clear-bg:#2a1010;
|
| 130 |
-
--clear-text:#fca5a5;
|
| 131 |
-
--clear-border:#7f1d1d;
|
| 132 |
-
--clear-hover:#3a1515;
|
| 133 |
-
--hint:#93c5fd;
|
| 134 |
-
--hint-empty:#6b7280;
|
| 135 |
-
--progress-bg:rgba(26,27,30,0.92);
|
| 136 |
-
--progress-bar:#3a3b3e;
|
| 137 |
-
--progress-fill:#3b82f6;
|
| 138 |
-
--progress-text:#9ca3af;
|
| 139 |
-
--progress-percent:#e4e4e7;
|
| 140 |
-
--book-bg:#241a33;
|
| 141 |
-
--book-border:#4a3466;
|
| 142 |
-
--book-title:#d8b8ff;
|
| 143 |
-
--book-label-bg:#3a2a55;
|
| 144 |
-
--book-label-text:#e0c8ff;
|
| 145 |
-
--book-path-text:#c9a8f0;
|
| 146 |
-
--book-quote-text:#e4d4fb;
|
| 147 |
-
--book-pct-bg:#7c4fc9;
|
| 148 |
-
--book-pct-text:#f0e4ff;
|
| 149 |
-
--book-empty:#9a8ab8;
|
| 150 |
-
--book-error-bg:#2a1010;
|
| 151 |
-
--book-error-text:#fca5a5;
|
| 152 |
-
--book-error-border:#7f1d1d;
|
| 153 |
-
}
|
| 154 |
-
*{box-sizing:border-box}
|
| 155 |
-
body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;background:var(--bg);color:var(--text);transition:background 0.2s,color 0.2s}
|
| 156 |
-
.container{max-width:1500px;margin:0 auto;padding:28px}
|
| 157 |
-
h1{margin:0 0 8px;font-size:28px}
|
| 158 |
-
.subtitle{color:var(--status);margin-bottom:20px}
|
| 159 |
-
.theme-toggle{background:var(--btn-bg);color:var(--btn-text);border:1px solid var(--panel-border);border-radius:8px;padding:8px 12px;font-size:14px;cursor:pointer;font-weight:600;white-space:nowrap}
|
| 160 |
-
.theme-toggle:hover{opacity:0.85}
|
| 161 |
-
.inputs{display:grid;grid-template-columns:1fr 1fr;gap:20px}
|
| 162 |
-
.panel{background:var(--panel-bg);border:1px solid var(--panel-border);border-radius:12px;padding:16px;box-shadow:0 2px 8px var(--panel-shadow);transition:background 0.2s,border 0.2s}
|
| 163 |
-
.panel h2{font-size:18px;margin:0 0 12px}
|
| 164 |
-
input[type=file]{width:100%;margin-bottom:10px}
|
| 165 |
-
textarea{width:100%;height:380px;resize:vertical;border:1px solid var(--input-border);border-radius:8px;padding:12px;font:14px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;background:var(--input-bg);color:var(--text);transition:background 0.2s,border 0.2s,color 0.2s}
|
| 166 |
-
.file-name{font-size:13px;color:var(--status);margin:5px 0 10px}
|
| 167 |
-
.controls{display:flex;flex-wrap:wrap;gap:14px;align-items:end;background:var(--panel-bg);border:1px solid var(--panel-border);border-radius:12px;padding:16px;margin-top:20px;transition:background 0.2s,border 0.2s}
|
| 168 |
-
.control{display:flex;flex-direction:column;gap:5px}
|
| 169 |
-
.control label{font-size:12px;color:var(--status)}
|
| 170 |
-
.control input{width:100px;padding:8px;border:1px solid var(--input-border);border-radius:7px;background:var(--input-bg);color:var(--text)}
|
| 171 |
-
button{border:0;border-radius:8px;padding:10px 18px;font-size:14px;cursor:pointer}
|
| 172 |
-
.primary{background:var(--btn-primary-bg);color:var(--btn-primary-text)}
|
| 173 |
-
button:disabled{opacity:.5;cursor:not-allowed}
|
| 174 |
-
.status{margin-left:auto;color:var(--status);font-size:14px}
|
| 175 |
-
.result{margin-top:20px;background:var(--panel-bg);border:1px solid var(--panel-border);border-radius:12px;padding:22px;transition:background 0.2s,border 0.2s}
|
| 176 |
-
.result h2{margin-top:0}
|
| 177 |
-
.split-row{display:flex;gap:0;align-items:stretch;border-top:1px solid var(--split-border);padding:14px 0}
|
| 178 |
-
.split-left{width:50%;padding-right:16px;position:relative}
|
| 179 |
-
.split-divider{width:1px;background:var(--split-divider);flex-shrink:0;align-self:stretch}
|
| 180 |
-
.split-right{width:50%;padding-left:16px}
|
| 181 |
-
.split-left p{line-height:1.65;margin:4px 0;font-size:13px}
|
| 182 |
-
.split-right p{line-height:1.65;margin:4px 0;font-size:13px}
|
| 183 |
-
.match{padding:1px 2px;border-radius:2px}
|
| 184 |
-
.covered{padding:1px 2px;border-radius:2px}
|
| 185 |
-
.cov-para{line-height:1.65;margin:4px 0;font-size:13px}
|
| 186 |
-
.cov-para.uncovered{border-left:3px solid var(--uncovered-border);padding-left:10px;background:var(--uncovered-bg);border-radius:0 6px 6px 0}
|
| 187 |
-
.uncovered-tag{display:inline-block;font-size:11px;font-weight:700;color:var(--uncovered-tag-text);background:var(--uncovered-tag-bg);border-radius:4px;padding:2px 6px;margin-right:6px;vertical-align:middle}
|
| 188 |
-
.note{font-size:13px;color:var(--note-text);margin:8px 0 3px;line-height:1.5;text-decoration:underline}
|
| 189 |
-
.note-match{font-size:13px;color:var(--note-match-text);margin:0 0 10px;line-height:1.5}
|
| 190 |
-
.note-match:last-child{margin-bottom:0}
|
| 191 |
-
.empty{color:var(--empty)}
|
| 192 |
-
.unique-banner{background:var(--banner-bg);border:1px solid var(--banner-border);color:var(--banner-text);border-radius:10px;padding:16px 18px;font-size:15px;font-weight:600}
|
| 193 |
-
.coverage-summary{display:flex;align-items:baseline;gap:14px;margin-bottom:18px;padding:14px 18px;background:var(--summary-bg);border:1px solid var(--summary-border);border-radius:10px;flex-wrap:wrap}
|
| 194 |
-
.coverage-pct{font-size:34px;font-weight:800;color:var(--summary-pct)}
|
| 195 |
-
.coverage-label{color:var(--summary-label);font-size:14px}
|
| 196 |
-
.unused-box{margin-top:20px;padding:14px 18px;background:var(--unused-bg);border:1px solid var(--unused-border);border-radius:10px;font-size:14px;color:var(--unused-text)}
|
| 197 |
-
.unused-box ul{margin:8px 0 0;padding-left:20px}
|
| 198 |
-
.chunk-title{font-size:17px;font-weight:700;margin-bottom:12px;color:var(--chunk-title)}
|
| 199 |
-
.auto-info{background:var(--auto-info-bg);border:1px solid var(--auto-info-border);border-radius:8px;padding:10px 14px;margin-bottom:14px;font-size:13px;color:var(--auto-info-text)}
|
| 200 |
-
.auto-info b{color:var(--auto-info-b)}
|
| 201 |
-
.auto-label{display:flex;align-items:center;gap:6px;font-size:13px;color:var(--auto-label);cursor:pointer;user-select:none}
|
| 202 |
-
.auto-label input{width:auto}
|
| 203 |
-
.chunk-legend{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:14px}
|
| 204 |
-
.chunk-legend-item{display:flex;align-items:center;gap:5px;font-size:12px;color:var(--legend-text)}
|
| 205 |
-
.chunk-legend-dot{width:14px;height:14px;border-radius:3px;flex-shrink:0;border:1px solid var(--legend-border)}
|
| 206 |
-
.by-chunk-header{font-size:16px;font-weight:700;padding:10px 14px;border-radius:8px;margin-bottom:8px}
|
| 207 |
-
.clean-view{margin-top:0}
|
| 208 |
-
.clean-chunk{display:flex;gap:0;align-items:stretch;border-top:1px solid var(--split-border);padding:14px 0}
|
| 209 |
-
.clean-chunk-left{width:50%;padding-right:16px;display:flex;align-items:flex-start;justify-content:flex-start}
|
| 210 |
-
.clean-chunk-header{font-size:15px;font-weight:700;padding:10px 14px;border-radius:8px;text-align:left;max-width:100%;word-break:break-word}
|
| 211 |
-
.clean-chunk-right{width:50%;padding-left:16px;border-left:1px solid var(--clean-border)}
|
| 212 |
-
.clean-chunk-body{font-size:14px;line-height:1.7}
|
| 213 |
-
.clean-chunk-body p{margin:6px 0}
|
| 214 |
-
.progress-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:var(--progress-bg);z-index:9999;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px}
|
| 215 |
-
.progress-bar-container{width:400px;max-width:80%;height:8px;background:var(--progress-bar);border-radius:4px;overflow:hidden}
|
| 216 |
-
.progress-bar-fill{height:100%;background:var(--progress-fill);width:0%;transition:width 0.3s ease;border-radius:4px}
|
| 217 |
-
.progress-text{font-size:15px;color:var(--progress-text);font-weight:500}
|
| 218 |
-
.progress-percent{font-size:28px;font-weight:800;color:var(--progress-percent)}
|
| 219 |
-
.result-tabs{display:flex;gap:8px;margin-bottom:16px}
|
| 220 |
-
.result-tab{background:var(--tab-bg);color:var(--tab-text);border:0;border-radius:8px;padding:10px 18px;font-size:14px;cursor:pointer;font-weight:600}
|
| 221 |
-
.result-tab.active{background:var(--tab-active-bg);color:var(--tab-active-text)}
|
| 222 |
-
.result-panel{display:none}
|
| 223 |
-
.result-panel.active{display:block}
|
| 224 |
-
.clear-btn{background:var(--clear-bg);color:var(--clear-text);border:1px solid var(--clear-border);border-radius:6px;padding:4px 10px;font-size:12px;cursor:pointer;margin-bottom:6px}
|
| 225 |
-
.clear-btn:hover{background:var(--clear-hover)}
|
| 226 |
-
.input-hint{font-size:12px;color:var(--hint);margin-top:6px;min-height:16px}
|
| 227 |
-
.input-hint.empty-hint{color:var(--hint-empty)}
|
| 228 |
-
.article-color-picker{display:flex;align-items:center;gap:6px;margin-top:4px}
|
| 229 |
-
.article-color-picker input[type=color]{width:28px;height:28px;border:1px solid var(--input-border);border-radius:4px;cursor:pointer;padding:0;background:transparent}
|
| 230 |
-
.article-color-picker label{font-size:12px;color:var(--status)}
|
| 231 |
-
.pct-badge{display:inline-block;font-weight:800;font-size:13px;padding:2px 8px;border-radius:6px;margin-right:6px;border:1px solid}
|
| 232 |
-
.book-matches-box{margin-top:14px;padding:14px 16px;background:var(--book-bg);border:1px solid var(--book-border);border-radius:10px}
|
| 233 |
-
.book-matches-title{font-size:13px;font-weight:700;color:var(--book-title);margin-bottom:10px}
|
| 234 |
-
.book-match-item{margin-bottom:12px;padding-bottom:12px;border-bottom:1px dashed var(--book-border)}
|
| 235 |
-
.book-match-item:last-child{margin-bottom:0;padding-bottom:0;border-bottom:0}
|
| 236 |
-
.book-match-label{display:inline-block;font-size:12px;font-weight:700;color:var(--book-label-text);background:var(--book-label-bg);border-radius:5px;padding:3px 9px;margin-bottom:6px}
|
| 237 |
-
.book-match-path{font-size:12.5px;line-height:1.6;color:var(--book-path-text);margin:4px 0}
|
| 238 |
-
.book-match-text{color:var(--book-quote-text)}
|
| 239 |
-
.book-pct{background:var(--book-pct-bg)!important;color:var(--book-pct-text)!important;border-color:var(--book-pct-text)!important}
|
| 240 |
-
.book-match-empty{font-size:13px;color:var(--book-empty)}
|
| 241 |
-
.book-match-error{font-size:13px;color:var(--book-error-text);background:var(--book-error-bg);border:1px solid var(--book-error-border);border-radius:8px;padding:8px 12px}
|
| 242 |
-
.book-match-loading{font-size:13px;color:var(--book-empty)}
|
| 243 |
-
@media(max-width:900px){
|
| 244 |
-
.inputs{grid-template-columns:1fr}
|
| 245 |
-
.status{width:100%;margin-left:0}
|
| 246 |
-
.split-row{flex-direction:column}
|
| 247 |
-
.split-left{width:100%;padding-right:0;padding-bottom:10px}
|
| 248 |
-
.split-divider{width:100%;height:1px}
|
| 249 |
-
.split-right{width:100%;padding-left:0;padding-top:10px}
|
| 250 |
-
.clean-chunk{flex-direction:column}
|
| 251 |
-
.clean-chunk-left{width:100%;padding-right:0;padding-bottom:10px;justify-content:flex-start}
|
| 252 |
-
.clean-chunk-header{text-align:left}
|
| 253 |
-
.clean-chunk-right{width:100%;padding-left:0;border-left:0;border-top:1px solid var(--clean-border);padding-top:10px}
|
| 254 |
-
}
|
| 255 |
-
</style>
|
| 256 |
-
</head>
|
| 257 |
-
<body>
|
| 258 |
-
<div class="container">
|
| 259 |
-
<div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:10px">
|
| 260 |
-
<h1 style="margin:0">Поиск схожих фраз в подборке и статьях</h1>
|
| 261 |
-
<button class="theme-toggle" id="themeToggle" onclick="toggleTheme()">🌙 Тёмная</button>
|
| 262 |
-
</div>
|
| 263 |
-
<div class="subtitle">Загрузите два TXT-файла или вставьте текст вручную.</div>
|
| 264 |
-
<div class="inputs">
|
| 265 |
-
<section class="panel">
|
| 266 |
-
<h2>Статьи</h2>
|
| 267 |
-
<input id="articlesFile" type="file" accept=".txt,text/plain">
|
| 268 |
-
<div id="articlesName" class="file-name">Файл не выбран</div>
|
| 269 |
-
<textarea id="articlesText" placeholder="Здесь будет текст статей..."></textarea>
|
| 270 |
-
<button class="clear-btn" onclick="clearField('articlesText','articlesName','articlesHint')">🗑 Очистить</button>
|
| 271 |
-
<div id="articlesHint" class="input-hint empty-hint">Вставьте текст статей</div>
|
| 272 |
-
<div id="articleColorPickers"></div>
|
| 273 |
-
<div id="bookMatches" class="book-matches-box" style="display:none"></div>
|
| 274 |
-
</section>
|
| 275 |
-
<section class="panel">
|
| 276 |
-
<h2>Куски</h2>
|
| 277 |
-
<input id="chunksFile" type="file" accept=".txt,text/plain">
|
| 278 |
-
<div id="chunksName" class="file-name">Файл не выбран</div>
|
| 279 |
-
<textarea id="chunksText" placeholder="Здесь будет текст кусков..."></textarea>
|
| 280 |
-
<button class="clear-btn" onclick="clearField('chunksText','chunksName','chunksHint')">🗑 Очистить</button>
|
| 281 |
-
<div id="chunksHint" class="input-hint empty-hint">Вставьте текст кусков</div>
|
| 282 |
-
</section>
|
| 283 |
-
</div>
|
| 284 |
-
<div class="controls">
|
| 285 |
-
<div class="control"><label>Порог схожести, %</label><input id="threshold" type="number" value="60" min="0" max="100"></div>
|
| 286 |
-
<label class="auto-label"><input type="checkbox" id="autoMode"> Авто-подбор</label>
|
| 287 |
-
<label class="auto-label"><input type="checkbox" id="searchBooks"> 📚 Искать в книгах</label>
|
| 288 |
-
<button id="run" class="primary">🔎 Найти совпадения</button>
|
| 289 |
-
<div id="status" class="status">Готово</div>
|
| 290 |
-
</div>
|
| 291 |
-
<div class="result-tabs">
|
| 292 |
-
<button class="result-tab active" id="tabAnchors" onclick="switchResultTab('anchors')">⚓ Обзор найденных якорей</button>
|
| 293 |
-
<button class="result-tab" id="tabCoverage" onclick="switchResultTab('coverage')">🗺️ Покрытие статьи</button>
|
| 294 |
-
<button class="result-tab" id="tabClean" onclick="switchResultTab('clean')">🚢 Просмотр текста с якорями</button>
|
| 295 |
-
</div>
|
| 296 |
-
<section class="result">
|
| 297 |
-
<div id="outputAnchors" class="result-panel active empty">Загрузите файлы и нажмите «Найти совпадения».</div>
|
| 298 |
-
<div id="outputCoverage" class="result-panel empty">Загрузите файлы и нажмите «Найти совпадения».</div>
|
| 299 |
-
<div id="outputClean" class="result-panel empty">Загрузите файлы и нажмите «Найти совпадения».</div>
|
| 300 |
-
</section>
|
| 301 |
-
</div>
|
| 302 |
-
<div id="progressOverlay" class="progress-overlay" style="display:none">
|
| 303 |
-
<div class="progress-percent" id="progressPercent">0%</div>
|
| 304 |
-
<div class="progress-bar-container">
|
| 305 |
-
<div class="progress-bar-fill" id="progressBarFill"></div>
|
| 306 |
-
</div>
|
| 307 |
-
<div class="progress-text" id="progressText">Обработка...</div>
|
| 308 |
-
</div>
|
| 309 |
-
|
| 310 |
-
<script>
|
| 311 |
-
const $ = id => document.getElementById(id);
|
| 312 |
-
|
| 313 |
-
/* === Переключение темы === */
|
| 314 |
-
function toggleTheme(){
|
| 315 |
-
document.body.classList.toggle("dark");
|
| 316 |
-
const isDark=document.body.classList.contains("dark");
|
| 317 |
-
$("themeToggle").textContent=isDark?"☀️ Светлая":"🌙 Тёмная";
|
| 318 |
-
try{localStorage.setItem("theme",isDark?"dark":"light");}catch(e){}
|
| 319 |
-
}
|
| 320 |
-
window.toggleTheme=toggleTheme;
|
| 321 |
-
try{if(localStorage.getItem("theme")==="dark"){document.body.classList.add("dark");$("themeToggle")&&($("themeToggle").textContent="☀️ Светлая");}}catch(e){}
|
| 322 |
-
|
| 323 |
-
$("articlesFile").addEventListener("change", e => loadFile(e.target, $("articlesText"), $("articlesName")));
|
| 324 |
-
$("chunksFile").addEventListener("change", e => loadFile(e.target, $("chunksText"), $("chunksName")));
|
| 325 |
-
|
| 326 |
-
/* === Очистка поля === */
|
| 327 |
-
function clearField(textId,nameId,hintId){
|
| 328 |
-
$(textId).value="";
|
| 329 |
-
$(nameId).textContent="Файл не выбран";
|
| 330 |
-
$(hintId).textContent="Вставьте текст";
|
| 331 |
-
$(hintId).className="input-hint empty-hint";
|
| 332 |
-
$("outputAnchors").className="result-panel active empty";
|
| 333 |
-
$("outputAnchors").innerHTML="Загрузите файлы и нажмите «Найти совпадения».";
|
| 334 |
-
$("outputCoverage").className="result-panel empty";
|
| 335 |
-
$("outputCoverage").innerHTML="Загрузите файлы и нажмите «Найти совпадения».";
|
| 336 |
-
$("outputClean").className="result-panel empty";
|
| 337 |
-
$("outputClean").innerHTML="Загрузите файлы и нажмите «Найти совпадения».";
|
| 338 |
-
$("status").textContent="Готово";
|
| 339 |
-
if(textId==="articlesText"){
|
| 340 |
-
$("articleColorPickers").innerHTML="";
|
| 341 |
-
}
|
| 342 |
-
lastAnchorsData=null;
|
| 343 |
-
$("bookMatches").style.display="none";
|
| 344 |
-
$("bookMatches").innerHTML="";
|
| 345 |
-
}
|
| 346 |
-
window.clearField=clearField;
|
| 347 |
-
|
| 348 |
-
/* === Обновление подсказок и цветовых пиккеров === */
|
| 349 |
-
function updateHints(){
|
| 350 |
-
const articlesRaw=$("articlesText").value.trim();
|
| 351 |
-
const articlesHint=$("articlesHint");
|
| 352 |
-
const articleColorPickers=$("articleColorPickers");
|
| 353 |
-
articleColorPickers.innerHTML="";
|
| 354 |
-
if(articlesRaw){
|
| 355 |
-
const blocks=articlesRaw.split(/\n\s*\n+/).filter(x=>x.trim());
|
| 356 |
-
if(blocks.length>0){
|
| 357 |
-
const firstTitle=blocks[0].trim().split("\n")[0].trim();
|
| 358 |
-
if(blocks.length===1){
|
| 359 |
-
articlesHint.textContent=`Статья «${firstTitle}»`;
|
| 360 |
-
}else{
|
| 361 |
-
articlesHint.textContent=`Статей: ${blocks.length}. Первая: «${firstTitle}»`;
|
| 362 |
-
}
|
| 363 |
-
articlesHint.className="input-hint";
|
| 364 |
-
blocks.forEach((block,idx)=>{
|
| 365 |
-
const title=block.trim().split("\n")[0].trim();
|
| 366 |
-
const picker=document.createElement("div");
|
| 367 |
-
picker.className="article-color-picker";
|
| 368 |
-
const defaultColor=ARTICLE_COLORS[idx%ARTICLE_COLORS.length];
|
| 369 |
-
picker.innerHTML=`<input type="color" value="${defaultColor.bg}" data-idx="${idx}" id="artColor${idx}"><label for="artColor${idx}">Статья ${idx+1}: «${escapeHtml(title.substring(0,40))}${title.length>40?"…":""}»</label>`;
|
| 370 |
-
articleColorPickers.appendChild(picker);
|
| 371 |
-
});
|
| 372 |
-
}else{
|
| 373 |
-
articlesHint.textContent="Вставьте текст статей";
|
| 374 |
-
articlesHint.className="input-hint empty-hint";
|
| 375 |
-
}
|
| 376 |
-
}else{
|
| 377 |
-
articlesHint.textContent="Вставьте текст статей";
|
| 378 |
-
articlesHint.className="input-hint empty-hint";
|
| 379 |
-
}
|
| 380 |
-
const chunksRaw=$("chunksText").value.trim();
|
| 381 |
-
const chunksHint=$("chunksHint");
|
| 382 |
-
if(chunksRaw){
|
| 383 |
-
const blocks=chunksRaw.split(/\n\s*\n+/).filter(x=>x.trim());
|
| 384 |
-
if(blocks.length>0){
|
| 385 |
-
const firstBlock=blocks[0].trim().split("\n")[0].trim();
|
| 386 |
-
const m=firstBlock.match(/^(\d+)\.\s*(.*)$/);
|
| 387 |
-
if(m){
|
| 388 |
-
chunksHint.textContent=`Кусков: ${blocks.length}. Первый: «${m[2].trim()}»`;
|
| 389 |
-
}else{
|
| 390 |
-
chunksHint.textContent=`Кусков: ${blocks.length}`;
|
| 391 |
-
}
|
| 392 |
-
chunksHint.className="input-hint";
|
| 393 |
-
}else{
|
| 394 |
-
chunksHint.textContent="Вставьте текст кусков";
|
| 395 |
-
chunksHint.className="input-hint empty-hint";
|
| 396 |
-
}
|
| 397 |
-
}else{
|
| 398 |
-
chunksHint.textContent="Вставьте текст кусков";
|
| 399 |
-
chunksHint.className="input-hint empty-hint";
|
| 400 |
-
}
|
| 401 |
-
}
|
| 402 |
-
|
| 403 |
-
/* === Очистка текста от лишних пустых строк === */
|
| 404 |
-
function cleanText(raw){
|
| 405 |
-
return raw.replace(/\r\n/g,"\n").replace(/\n{3,}/g,"\n\n").replace(/^\n+/,"").replace(/\n+$/,"");
|
| 406 |
-
}
|
| 407 |
-
|
| 408 |
-
/* === Добавление пробела после точки, если его нет === */
|
| 409 |
-
function fixSpacing(text){
|
| 410 |
-
return text.replace(/\.\s*(?=[А-ЯЁA-Z])/g,". ");
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
/* === Очистка текста статей: сохраняет абзацы, убирает лишние пустые строки === */
|
| 414 |
-
function cleanArticlesText(raw){
|
| 415 |
-
let text=raw.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
|
| 416 |
-
// Нормализуем пробелы/табы в пустых строках
|
| 417 |
-
text=text.replace(/^[ \t]+$/gm,"");
|
| 418 |
-
// Схлопываем 3 и более переносов (2+ пустых строк) в 2 переноса (1 пустая строка)
|
| 419 |
-
text=text.replace(/\n{3,}/g,"\n\n");
|
| 420 |
-
// Убираем пустые строки в начале и конце всего текста
|
| 421 |
-
text=text.replace(/^\n+/,"").replace(/\n+$/,"");
|
| 422 |
-
return text;
|
| 423 |
-
}
|
| 424 |
-
|
| 425 |
-
/* === Очистка текста кусков: сохраняет абзацы, убирает лишние пустые строки === */
|
| 426 |
-
function cleanChunksText(raw){
|
| 427 |
-
let text=raw.replace(/\r\n/g,"\n");
|
| 428 |
-
// Добавляем пробел после многоточий (3 и 4 точки), если его нет
|
| 429 |
-
text=text.replace(/\.{3,4}(?=[^\s])/g,"... ");
|
| 430 |
-
// Нормализуем пробелы/табы в пустых строках
|
| 431 |
-
text=text.replace(/^[ \t]+$/gm,"");
|
| 432 |
-
// Схлопываем 3 и более переносов (2+ пустых строк) в 2 переноса (1 пустая строка)
|
| 433 |
-
text=text.replace(/\n{3,}/g,"\n\n");
|
| 434 |
-
// Убираем пустые строки в начале и конце всего текста
|
| 435 |
-
text=text.replace(/^\n+/,"").replace(/\n+$/,"");
|
| 436 |
-
|
| 437 |
-
// Теперь убираем пустые строки внутри куска, НО сохраняем между кусками
|
| 438 |
-
const lines=text.split("\n");
|
| 439 |
-
const result=[];
|
| 440 |
-
let prevEmpty=false;
|
| 441 |
-
|
| 442 |
-
for(let k=0;k<lines.length;k++){
|
| 443 |
-
const line=lines[k];
|
| 444 |
-
const isEmpty=line.trim()==="";
|
| 445 |
-
const isChunkStart=/^\d+\.\s/.test(line.trim());
|
| 446 |
-
|
| 447 |
-
if(isEmpty){
|
| 448 |
-
// Не добавляем две пустые строки подряд
|
| 449 |
-
if(prevEmpty)continue;
|
| 450 |
-
prevEmpty=true;
|
| 451 |
-
result.push("");
|
| 452 |
-
continue;
|
| 453 |
-
}
|
| 454 |
-
|
| 455 |
-
// Если это начало нового куска, а предыдущая строка не пустая — добавляем пустую
|
| 456 |
-
if(isChunkStart && !prevEmpty && result.length>0){
|
| 457 |
-
result.push("");
|
| 458 |
-
}
|
| 459 |
-
|
| 460 |
-
prevEmpty=false;
|
| 461 |
-
result.push(line);
|
| 462 |
-
}
|
| 463 |
-
|
| 464 |
-
return result.join("\n");
|
| 465 |
-
}
|
| 466 |
-
|
| 467 |
-
function loadFile(input, textarea, nameBox){
|
| 468 |
-
const file=input.files[0];
|
| 469 |
-
if(!file)return;
|
| 470 |
-
nameBox.textContent=file.name;
|
| 471 |
-
const reader=new FileReader();
|
| 472 |
-
reader.onload=()=>{
|
| 473 |
-
let text=reader.result;
|
| 474 |
-
if(textarea.id==="chunksText"){
|
| 475 |
-
text=cleanChunksText(text);
|
| 476 |
-
}else{
|
| 477 |
-
text=cleanArticlesText(text);
|
| 478 |
-
}
|
| 479 |
-
textarea.value=text;
|
| 480 |
-
updateHints();
|
| 481 |
-
};
|
| 482 |
-
reader.readAsText(file,"UTF-8");
|
| 483 |
-
}
|
| 484 |
-
|
| 485 |
-
$("chunksText").addEventListener("paste",e=>{
|
| 486 |
-
setTimeout(()=>{
|
| 487 |
-
const ta=$("chunksText");
|
| 488 |
-
ta.value=cleanChunksText(ta.value);
|
| 489 |
-
updateHints();
|
| 490 |
-
},0);
|
| 491 |
-
});
|
| 492 |
-
$("articlesText").addEventListener("paste",e=>{
|
| 493 |
-
setTimeout(()=>{
|
| 494 |
-
const ta=$("articlesText");
|
| 495 |
-
let text=ta.value;
|
| 496 |
-
// Временно убираем fixSpacing для проверки
|
| 497 |
-
text=text.replace(/\r\n/g,"\n").replace(/\r/g,"\n");
|
| 498 |
-
text=text.replace(/^[ \t]+$/gm,"");
|
| 499 |
-
text=text.replace(/\n{3,}/g,"\n\n");
|
| 500 |
-
text=text.replace(/^\n+/,"").replace(/\n+$/,"");
|
| 501 |
-
ta.value=text;
|
| 502 |
-
updateHints();
|
| 503 |
-
},0);
|
| 504 |
-
});
|
| 505 |
-
$("articlesText").addEventListener("input",updateHints);
|
| 506 |
-
$("chunksText").addEventListener("input",updateHints);
|
| 507 |
-
|
| 508 |
-
/* === Скрытые параметры === */
|
| 509 |
-
const HIDDEN_OPT={
|
| 510 |
-
minLength:20,
|
| 511 |
-
minWords:3,
|
| 512 |
-
minSentences:1,
|
| 513 |
-
maxCombine:10
|
| 514 |
-
};
|
| 515 |
-
|
| 516 |
-
/* === Палитра цветов для кусков === */
|
| 517 |
-
const CHUNK_COLORS=[
|
| 518 |
-
{bg:"#78E700",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 519 |
-
{bg:"#c5e8f7",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 520 |
-
{bg:"#f7e8c5",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 521 |
-
{bg:"#f7c5e8",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 522 |
-
{bg:"#e8c5f7",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 523 |
-
{bg:"#f7d5c5",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 524 |
-
{bg:"#d5f7c5",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 525 |
-
{bg:"#c5d5f7",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 526 |
-
{bg:"#f7c5d5",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 527 |
-
{bg:"#d5c5f7",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 528 |
-
{bg:"#c5f7d5",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 529 |
-
{bg:"#f7e8d5",fg:"#1a1a1a",note:"#1a1a1a"}
|
| 530 |
-
];
|
| 531 |
-
|
| 532 |
-
/* === Палитра цветов для статей (для пиккеров) === */
|
| 533 |
-
const ARTICLE_COLORS=[
|
| 534 |
-
{bg:"#78E700",fg:"#1a1a1a",note:"#1a1a1a"},
|
| 535 |
-
{bg:"#c5e8f7",fg:"#1a5c7a",note:"#1a5c7a"},
|
| 536 |
-
{bg:"#f7e8c5",fg:"#7a5c1a",note:"#7a5c1a"},
|
| 537 |
-
{bg:"#f7c5e8",fg:"#7a1a5c",note:"#7a1a5c"},
|
| 538 |
-
{bg:"#e8c5f7",fg:"#5c1a7a",note:"#5c1a7a"},
|
| 539 |
-
{bg:"#f7d5c5",fg:"#7a3a1a",note:"#7a3a1a"},
|
| 540 |
-
{bg:"#d5f7c5",fg:"#3a7a1a",note:"#3a7a1a"},
|
| 541 |
-
{bg:"#c5d5f7",fg:"#1a3a7a",note:"#1a3a7a"},
|
| 542 |
-
{bg:"#f7c5d5",fg:"#7a1a3a",note:"#7a1a3a"},
|
| 543 |
-
{bg:"#d5c5f7",fg:"#3a1a7a",note:"#3a1a7a"},
|
| 544 |
-
{bg:"#c5f7d5",fg:"#1a7a3a",note:"#1a7a3a"},
|
| 545 |
-
{bg:"#f7e8d5",fg:"#7a5c3a",note:"#7a5c3a"}
|
| 546 |
-
];
|
| 547 |
-
|
| 548 |
-
function buildChunkColorMap(chunks){
|
| 549 |
-
const map=new Map();
|
| 550 |
-
chunks.forEach((chunk,idx)=>{
|
| 551 |
-
const color=CHUNK_COLORS[idx%CHUNK_COLORS.length];
|
| 552 |
-
map.set(`Кусок ${chunk.number}. ${chunk.title}`,color);
|
| 553 |
-
});
|
| 554 |
-
return map;
|
| 555 |
-
}
|
| 556 |
-
|
| 557 |
-
const SENT_SPLIT_RE=/(?<=[.!?…])\s+/u;
|
| 558 |
-
const PUNCT_RE=/[^\p{L}\p{N}_\s]/gu;
|
| 559 |
-
|
| 560 |
-
function preprocess(text){return text.replace(/\.\.\./g,"…").replace(PUNCT_RE,"").toLowerCase().trim();}
|
| 561 |
-
function stripPunct(text){return text.replace(PUNCT_RE,"").toLowerCase().replace(/\s/g,"");}
|
| 562 |
-
function normLev(a,b){return sequenceMatcher(stripPunct(a),stripPunct(b))*100;}
|
| 563 |
-
function sequenceMatcher(a,b){
|
| 564 |
-
if(a===b)return 1;
|
| 565 |
-
if(!a.length||!b.length)return 0;
|
| 566 |
-
let prev=new Array(b.length+1).fill(0);
|
| 567 |
-
for(let i=0;i<=a.length;i++){
|
| 568 |
-
let cur=new Array(b.length+1).fill(0);
|
| 569 |
-
cur[0]=i;
|
| 570 |
-
for(let j=1;j<=b.length;j++){
|
| 571 |
-
cur[j]=Math.min(cur[j-1]+1,prev[j]+1,prev[j-1]+(a[i-1]===b[j-1]?0:1));
|
| 572 |
-
}
|
| 573 |
-
prev=cur;
|
| 574 |
-
}
|
| 575 |
-
const dist=prev[b.length];
|
| 576 |
-
return 1-dist/Math.max(a.length,b.length);
|
| 577 |
-
}
|
| 578 |
-
|
| 579 |
-
function parseArticles(raw){
|
| 580 |
-
const blocks=raw.trim().split(/\n\s*\n+/).filter(x=>x.trim());
|
| 581 |
-
return blocks.map(block=>{
|
| 582 |
-
const lines=block.trim().split("\n");
|
| 583 |
-
return {title:lines[0].trim(),body:lines.slice(1).join("\n").trim()};
|
| 584 |
-
});
|
| 585 |
-
}
|
| 586 |
-
|
| 587 |
-
function parseChunks(raw){
|
| 588 |
-
const blocks=raw.trim().split(/\n\s*\n+/).filter(x=>x.trim());
|
| 589 |
-
return blocks.map((block,i)=>{
|
| 590 |
-
const lines=block.trim().split("\n");
|
| 591 |
-
const first=lines[0].trim();
|
| 592 |
-
const m=first.match(/^(\d+)\.\s*(.*)$/);
|
| 593 |
-
if(m)return {number:m[1],title:m[2].trim(),body:lines.slice(1).join("\n").trim()};
|
| 594 |
-
return {number:String(i+1),title:first,body:lines.slice(1).join("\n").trim()};
|
| 595 |
-
});
|
| 596 |
-
}
|
| 597 |
-
|
| 598 |
-
function ngrams(text,n=3,maxN=5){
|
| 599 |
-
const padded=" "+text+" ";
|
| 600 |
-
const out=[];
|
| 601 |
-
for(let k=n;k<=maxN;k++){
|
| 602 |
-
for(let i=0;i<=padded.length-k;i++)out.push(padded.slice(i,i+k));
|
| 603 |
-
}
|
| 604 |
-
return out;
|
| 605 |
-
}
|
| 606 |
-
|
| 607 |
-
function buildIndex(articles){
|
| 608 |
-
const sentences=[],titles=[];
|
| 609 |
-
for(const art of articles){
|
| 610 |
-
for(const s of art.body.split(SENT_SPLIT_RE)){
|
| 611 |
-
const sent=s.trim();
|
| 612 |
-
if(sent){sentences.push(sent);titles.push(art.title);}
|
| 613 |
-
}
|
| 614 |
-
}
|
| 615 |
-
const docs=sentences.map(preprocess);
|
| 616 |
-
const df=new Map();
|
| 617 |
-
const termDocs=[];
|
| 618 |
-
docs.forEach(doc=>{
|
| 619 |
-
const counts=new Map();
|
| 620 |
-
for(const g of ngrams(doc)){counts.set(g,(counts.get(g)||0)+1);}
|
| 621 |
-
termDocs.push(counts);
|
| 622 |
-
for(const g of counts.keys())df.set(g,(df.get(g)||0)+1);
|
| 623 |
-
});
|
| 624 |
-
const N=docs.length;
|
| 625 |
-
const vectors=termDocs.map(counts=>{
|
| 626 |
-
const v=new Map();
|
| 627 |
-
let norm=0;
|
| 628 |
-
for(const [g,c] of counts){
|
| 629 |
-
const idf=Math.log((N+1)/((df.get(g)||0)+1))+1;
|
| 630 |
-
const val=c*idf;
|
| 631 |
-
v.set(g,val);
|
| 632 |
-
norm+=val*val;
|
| 633 |
-
}
|
| 634 |
-
norm=Math.sqrt(norm)||1;
|
| 635 |
-
for(const [g,val] of v)v.set(g,val/norm);
|
| 636 |
-
return v;
|
| 637 |
-
});
|
| 638 |
-
return {sentences,titles,vectors,df,N};
|
| 639 |
-
}
|
| 640 |
-
|
| 641 |
-
function vectorFor(text,index){
|
| 642 |
-
const counts=new Map();
|
| 643 |
-
for(const g of ngrams(preprocess(text)))counts.set(g,(counts.get(g)||0)+1);
|
| 644 |
-
const v=new Map();
|
| 645 |
-
let norm=0;
|
| 646 |
-
for(const [g,c] of counts){
|
| 647 |
-
const idf=Math.log((index.N+1)/((index.df.get(g)||0)+1))+1;
|
| 648 |
-
const val=c*idf;
|
| 649 |
-
v.set(g,val);
|
| 650 |
-
norm+=val*val;
|
| 651 |
-
}
|
| 652 |
-
norm=Math.sqrt(norm)||1;
|
| 653 |
-
for(const [g,val] of v)v.set(g,val/norm);
|
| 654 |
-
return v;
|
| 655 |
-
}
|
| 656 |
-
|
| 657 |
-
function cosine(a,b){
|
| 658 |
-
let sum=0;
|
| 659 |
-
const small=a.size<b.size?a:b, large=small===a?b:a;
|
| 660 |
-
for(const [g,v] of small)sum+=v*(large.get(g)||0);
|
| 661 |
-
return sum;
|
| 662 |
-
}
|
| 663 |
-
|
| 664 |
-
function nearest(text,index){
|
| 665 |
-
const v=vectorFor(text,index);
|
| 666 |
-
const candidates=[];
|
| 667 |
-
index.vectors.forEach((iv,i)=>{
|
| 668 |
-
const s=cosine(v,iv);
|
| 669 |
-
candidates.push({index:i,sim:s*100});
|
| 670 |
-
});
|
| 671 |
-
candidates.sort((a,b)=>b.sim-a.sim);
|
| 672 |
-
return candidates.slice(0,5);
|
| 673 |
-
}
|
| 674 |
-
|
| 675 |
-
function validMatch(text,match,numSent,minLen,minWords,minSent){
|
| 676 |
-
if(numSent<minSent)return false;
|
| 677 |
-
const a=text.trim().replace(/\s+/g," "),b=match.trim().replace(/\s+/g," ");
|
| 678 |
-
if(a.replace(/ /g,"").length<minLen||b.replace(/ /g,"").length<minLen)return false;
|
| 679 |
-
if(a.split(" ").length<minWords||b.split(" ").length<minWords)return false;
|
| 680 |
-
return true;
|
| 681 |
-
}
|
| 682 |
-
|
| 683 |
-
function processRange(sentences,combs,opt,start,end){
|
| 684 |
-
if(start>end)return [];
|
| 685 |
-
let best=null;
|
| 686 |
-
for(let len=Math.min(opt.maxCombine,end-start+1);len>=1;len--){
|
| 687 |
-
for(let i=start;i+len-1<=end;i++){
|
| 688 |
-
const j=i+len-1;
|
| 689 |
-
const d=combs.find(x=>x.i===i&&x.j===j);
|
| 690 |
-
if(!d)continue;
|
| 691 |
-
if(d.sim>=opt.threshold&&validMatch(d.text,d.match,d.numSent,opt.minLength,opt.minWords,opt.minSentences)){
|
| 692 |
-
best=d;
|
| 693 |
-
break;
|
| 694 |
-
}
|
| 695 |
-
if(!best&&normLev(d.text,d.match)>95&&validMatch(d.text,d.match,d.numSent,opt.minLength,opt.minWords,opt.minSentences)){
|
| 696 |
-
best=d;
|
| 697 |
-
}
|
| 698 |
-
}
|
| 699 |
-
if(best)break;
|
| 700 |
-
}
|
| 701 |
-
if(best){
|
| 702 |
-
const before=processRange(sentences,combs,opt,start,best.i-1);
|
| 703 |
-
const match={text:best.text,is_match:true,article:best.article,fragment:best.match,score:best.sim};
|
| 704 |
-
const after=processRange(sentences,combs,opt,best.j+1,end);
|
| 705 |
-
return [...before,match,...after];
|
| 706 |
-
}else{
|
| 707 |
-
const segs=[];
|
| 708 |
-
for(let i=start;i<=end;i++){
|
| 709 |
-
segs.push({text:sentences[i],is_match:false});
|
| 710 |
-
}
|
| 711 |
-
return segs;
|
| 712 |
-
}
|
| 713 |
-
}
|
| 714 |
-
|
| 715 |
-
/* === Разбивка длинных абзацев на части по 2-4 предложения === */
|
| 716 |
-
function splitForSearch(subparas){
|
| 717 |
-
const result=[];
|
| 718 |
-
for(const sp of subparas){
|
| 719 |
-
const sentences=sp.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 720 |
-
if(sentences.length<=4){
|
| 721 |
-
result.push(sp);
|
| 722 |
-
continue;
|
| 723 |
-
}
|
| 724 |
-
for(let i=0;i<sentences.length;i+=3){
|
| 725 |
-
const chunk=sentences.slice(i,i+3).join(" ");
|
| 726 |
-
result.push(chunk);
|
| 727 |
-
}
|
| 728 |
-
}
|
| 729 |
-
return result;
|
| 730 |
-
}
|
| 731 |
-
|
| 732 |
-
/* === Поиск с разбивкой === */
|
| 733 |
-
function findMatchesInChunk(text,index,opt){
|
| 734 |
-
const subparas=text.split("\n").map(x=>x.trim()).filter(Boolean);
|
| 735 |
-
const result=[];
|
| 736 |
-
for(const sp of subparas){
|
| 737 |
-
const sentences=sp.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 738 |
-
const n=sentences.length;
|
| 739 |
-
if(!n)continue;
|
| 740 |
-
// Разбиваем на части по 2-4 предложения для поиска
|
| 741 |
-
const searchParts=splitForSearch([sp]);
|
| 742 |
-
for(const part of searchParts){
|
| 743 |
-
const partSentences=part.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 744 |
-
const partN=partSentences.length;
|
| 745 |
-
if(!partN)continue;
|
| 746 |
-
const combs=[];
|
| 747 |
-
for(let i=0;i<partN;i++){
|
| 748 |
-
for(let j=i;j<Math.min(i+opt.maxCombine,partN);j++){
|
| 749 |
-
const text2=partSentences.slice(i,j+1).join(" ");
|
| 750 |
-
const cands=nearest(text2,index);
|
| 751 |
-
for(const c of cands){
|
| 752 |
-
combs.push({i,j,text:text2,candidateIndex:c.index,match:index.sentences[c.index],article:index.titles[c.index],sim:c.sim,numSent:j-i+1});
|
| 753 |
-
}
|
| 754 |
-
}
|
| 755 |
-
}
|
| 756 |
-
const segments=processRange(partSentences,combs,opt,0,partN-1);
|
| 757 |
-
const merged=[];
|
| 758 |
-
for(let i=0;i<segments.length;i++){
|
| 759 |
-
const s=segments[i];
|
| 760 |
-
if(s.is_match&&merged.length&&merged[merged.length-1].is_match){
|
| 761 |
-
const m=merged[merged.length-1];
|
| 762 |
-
m.text+=" "+s.text;
|
| 763 |
-
m.fragment+=" "+s.fragment;
|
| 764 |
-
m.score=Math.max(m.score,s.score);
|
| 765 |
-
}else{
|
| 766 |
-
merged.push({...s});
|
| 767 |
-
}
|
| 768 |
-
}
|
| 769 |
-
result.push(merged);
|
| 770 |
-
}
|
| 771 |
-
}
|
| 772 |
-
return result;
|
| 773 |
-
}
|
| 774 |
-
|
| 775 |
-
function findMatchesAdaptive(text,index,baseOpt){
|
| 776 |
-
const subparas=text.split("\n").map(x=>x.trim()).filter(Boolean);
|
| 777 |
-
const thresholds=[50,55,60,65,70,75,80,85,90];
|
| 778 |
-
const result=[];
|
| 779 |
-
for(const sp of subparas){
|
| 780 |
-
const searchParts=splitForSearch([sp]);
|
| 781 |
-
for(const part of searchParts){
|
| 782 |
-
const partSentences=part.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 783 |
-
const partN=partSentences.length;
|
| 784 |
-
if(!partN)continue;
|
| 785 |
-
const combs=[];
|
| 786 |
-
for(let i=0;i<partN;i++){
|
| 787 |
-
for(let j=i;j<Math.min(i+baseOpt.maxCombine,partN);j++){
|
| 788 |
-
const text2=partSentences.slice(i,j+1).join(" ");
|
| 789 |
-
const cands=nearest(text2,index);
|
| 790 |
-
for(const c of cands){
|
| 791 |
-
combs.push({i,j,text:text2,candidateIndex:c.index,match:index.sentences[c.index],article:index.titles[c.index],sim:c.sim,numSent:j-i+1});
|
| 792 |
-
}
|
| 793 |
-
}
|
| 794 |
-
}
|
| 795 |
-
let bestResult=null;
|
| 796 |
-
let bestMetric=-1;
|
| 797 |
-
for(const t of thresholds){
|
| 798 |
-
const opt={...baseOpt,threshold:t};
|
| 799 |
-
const segments=processRange(partSentences,combs,opt,0,partN-1);
|
| 800 |
-
const matches=segments.filter(s=>s.is_match);
|
| 801 |
-
if(matches.length===0)continue;
|
| 802 |
-
const matchedLen=matches.reduce((s,m)=>s+m.text.replace(/\s/g,"").length,0);
|
| 803 |
-
const totalLen=partSentences.join(" ").replace(/\s/g,"").length;
|
| 804 |
-
const coverage=totalLen>0?(matchedLen/totalLen):0;
|
| 805 |
-
const avgScore=matches.reduce((s,m)=>s+m.score,0)/matches.length;
|
| 806 |
-
const metric=coverage*80 + (avgScore/100)*20;
|
| 807 |
-
if(metric>bestMetric){
|
| 808 |
-
bestMetric=metric;
|
| 809 |
-
bestResult=segments;
|
| 810 |
-
}
|
| 811 |
-
}
|
| 812 |
-
const merged=[];
|
| 813 |
-
if(bestResult){
|
| 814 |
-
for(let i=0;i<bestResult.length;i++){
|
| 815 |
-
const s=bestResult[i];
|
| 816 |
-
if(s.is_match&&merged.length&&merged[merged.length-1].is_match){
|
| 817 |
-
const m=merged[merged.length-1];
|
| 818 |
-
m.text+=" "+s.text;
|
| 819 |
-
m.fragment+=" "+s.fragment;
|
| 820 |
-
m.score=Math.max(m.score,s.score);
|
| 821 |
-
}else{
|
| 822 |
-
merged.push({...s});
|
| 823 |
-
}
|
| 824 |
-
}
|
| 825 |
-
}
|
| 826 |
-
result.push(merged.length?merged:[{text:part,is_match:false}]);
|
| 827 |
-
}
|
| 828 |
-
}
|
| 829 |
-
return result;
|
| 830 |
-
}
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
function escapeHtml(s){
|
| 834 |
-
return s.replace(/[&<>"']/g,c=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));
|
| 835 |
-
}
|
| 836 |
-
|
| 837 |
-
function renderHighlighted(segments,colorMap){
|
| 838 |
-
let html="";
|
| 839 |
-
for(const seg of segments){
|
| 840 |
-
if(seg.is_match){
|
| 841 |
-
const color=colorMap?colorMap.get(seg.article):null;
|
| 842 |
-
if(color){
|
| 843 |
-
html+=`<span class="match" style="background:${color.bg};color:#1a1a1a">${escapeHtml(seg.text)}</span> `;
|
| 844 |
-
}else{
|
| 845 |
-
html+=`<span class="match" style="background:var(--match-bg);color:#1a1a1a">${escapeHtml(seg.text)}</span> `;
|
| 846 |
-
}
|
| 847 |
-
}else{
|
| 848 |
-
html+=escapeHtml(seg.text)+" ";
|
| 849 |
-
}
|
| 850 |
-
}
|
| 851 |
-
return html.trim();
|
| 852 |
-
}
|
| 853 |
-
|
| 854 |
-
function renderCoverageHighlighted(segments,colorMap){
|
| 855 |
-
let html="";
|
| 856 |
-
for(const seg of segments){
|
| 857 |
-
if(seg.is_match){
|
| 858 |
-
const color=colorMap.get(seg.article)||CHUNK_COLORS[0];
|
| 859 |
-
html+=`<span class="covered" style="background:${color.bg};color:#1a1a1a">${escapeHtml(seg.text)}</span> `;
|
| 860 |
-
}else{
|
| 861 |
-
html+=escapeHtml(seg.text)+" ";
|
| 862 |
-
}
|
| 863 |
-
}
|
| 864 |
-
return html.trim();
|
| 865 |
-
}
|
| 866 |
-
|
| 867 |
-
function renderRightColumn(segments, isCoverage, colorMap){
|
| 868 |
-
let html="";
|
| 869 |
-
let hasAny=false;
|
| 870 |
-
const bySource=new Map();
|
| 871 |
-
for(const s of segments){
|
| 872 |
-
if(!s.is_match)continue;
|
| 873 |
-
hasAny=true;
|
| 874 |
-
if(!bySource.has(s.article))bySource.set(s.article,[]);
|
| 875 |
-
bySource.get(s.article).push(s);
|
| 876 |
-
}
|
| 877 |
-
if(hasAny){
|
| 878 |
-
for(const [source,matches] of bySource){
|
| 879 |
-
const color=colorMap?colorMap.get(source):null;
|
| 880 |
-
const noteColor="var(--note-text)";
|
| 881 |
-
const fragColor="var(--note-match-text)";
|
| 882 |
-
const noteClass=isCoverage?"note":"note";
|
| 883 |
-
const label=isCoverage?"Покрыто текстом":"Совпадает с текстом в статье";
|
| 884 |
-
html+=`<div class="${noteClass}" style="color:${noteColor}">${label} «${escapeHtml(source)}»:</div>`;
|
| 885 |
-
for(const s of matches){
|
| 886 |
-
const pctBg=color?color.bg:"var(--match-bg)";
|
| 887 |
-
const pctFg=color?color.fg:"#1a1a1a";
|
| 888 |
-
html+=`<div class="note-match" style="color:${fragColor}"><span class="pct-badge" style="background:${pctBg};color:${pctFg};border-color:${pctFg}">${Math.round(s.score)}%</span> — <span style="color:${fragColor}">«${escapeHtml(s.fragment)}»</span></div>`;
|
| 889 |
-
}
|
| 890 |
-
}
|
| 891 |
-
}else{
|
| 892 |
-
if(isCoverage){
|
| 893 |
-
html+=`<div class="note-match"><span class="uncovered-tag">не покрыто ⚠</span> Для этого абзаца не найдено подходящего куска.</div>`;
|
| 894 |
-
}else{
|
| 895 |
-
html+=`<div class="note-match" style="color:var(--empty)">Совпадений не найдено.</div>`;
|
| 896 |
-
}
|
| 897 |
-
}
|
| 898 |
-
return html;
|
| 899 |
-
}
|
| 900 |
-
|
| 901 |
-
function showProgress(){
|
| 902 |
-
$("progressOverlay").style.display="flex";
|
| 903 |
-
$("progressBarFill").style.width="0%";
|
| 904 |
-
$("progressPercent").textContent="0%";
|
| 905 |
-
$("progressText").textContent="Обработка...";
|
| 906 |
-
}
|
| 907 |
-
function updateProgress(current,total,label){
|
| 908 |
-
const pct=Math.round(current/total*100);
|
| 909 |
-
$("progressBarFill").style.width=pct+"%";
|
| 910 |
-
$("progressPercent").textContent=pct+"%";
|
| 911 |
-
$("progressText").textContent=label;
|
| 912 |
-
}
|
| 913 |
-
function hideProgress(){
|
| 914 |
-
$("progressOverlay").style.display="none";
|
| 915 |
-
}
|
| 916 |
-
|
| 917 |
-
function switchResultTab(tab){
|
| 918 |
-
$("tabAnchors").classList.toggle("active",tab==="anchors");
|
| 919 |
-
$("tabCoverage").classList.toggle("active",tab==="coverage");
|
| 920 |
-
$("tabClean").classList.toggle("active",tab==="clean");
|
| 921 |
-
$("outputAnchors").classList.toggle("active",tab==="anchors");
|
| 922 |
-
$("outputCoverage").classList.toggle("active",tab==="coverage");
|
| 923 |
-
$("outputClean").classList.toggle("active",tab==="clean");
|
| 924 |
-
}
|
| 925 |
-
window.switchResultTab=switchResultTab;
|
| 926 |
-
|
| 927 |
-
/* ==================== Поиск по книгам (books.json) ==================== */
|
| 928 |
-
/* Ожидаемая структура books.json (используется гибкий разбор с запасными
|
| 929 |
-
вариантами названий полей — если у вас другие ключи, пришлите файл, подстроим):
|
| 930 |
-
[
|
| 931 |
-
{ "book":"Книга 1", "sections":[
|
| 932 |
-
{ "section":"Раздел ...", "articles":[
|
| 933 |
-
{ "article":"Статья ...",
|
| 934 |
-
"subheadings":[ { "subheading":"Подзаголовок ...", "text":"..." } ],
|
| 935 |
-
"text":"..." // если подзаголовков нет
|
| 936 |
-
}
|
| 937 |
-
]}
|
| 938 |
-
]}
|
| 939 |
-
]
|
| 940 |
-
*/
|
| 941 |
-
let bookLeaves=null;
|
| 942 |
-
let bookIndex=null;
|
| 943 |
-
let booksLoadError=null;
|
| 944 |
-
let booksLoaded=false;
|
| 945 |
-
let lastAnchorsData=null;
|
| 946 |
-
|
| 947 |
-
function pick(obj,keys,fallback){
|
| 948 |
-
for(const k of keys){
|
| 949 |
-
if(obj && typeof obj[k]==="string" && obj[k].trim())return obj[k].trim();
|
| 950 |
-
}
|
| 951 |
-
return fallback;
|
| 952 |
-
}
|
| 953 |
-
function pickArray(obj,keys){
|
| 954 |
-
for(const k of keys){
|
| 955 |
-
if(obj && Array.isArray(obj[k]) && obj[k].length)return obj[k];
|
| 956 |
-
}
|
| 957 |
-
return null;
|
| 958 |
-
}
|
| 959 |
-
function pickText(obj,keys){
|
| 960 |
-
for(const k of keys){
|
| 961 |
-
const v=obj?obj[k]:undefined;
|
| 962 |
-
if(typeof v==="string" && v.trim())return v.trim();
|
| 963 |
-
if(Array.isArray(v) && v.length)return v.filter(x=>typeof x==="string").join("\n").trim();
|
| 964 |
-
}
|
| 965 |
-
return "";
|
| 966 |
-
}
|
| 967 |
-
|
| 968 |
-
function flattenBooks(data){
|
| 969 |
-
const leaves = [];
|
| 970 |
-
let bookList;
|
| 971 |
-
|
| 972 |
-
if(Array.isArray(data)) bookList = data;
|
| 973 |
-
else if(data && typeof data === "object") {
|
| 974 |
-
// Если data = { books: [...] }
|
| 975 |
-
if(data.books && Array.isArray(data.books)) bookList = data.books;
|
| 976 |
-
else bookList = [data];
|
| 977 |
-
} else {
|
| 978 |
-
bookList = [];
|
| 979 |
-
}
|
| 980 |
-
|
| 981 |
-
for(const bk of bookList){
|
| 982 |
-
const bookTitle = bk.title || bk.book || bk.название || "Книга";
|
| 983 |
-
|
| 984 |
-
// Ищем секции (поддерживаем русские и английские ключи)
|
| 985 |
-
let sectionsArr = bk.sections || bk.разделы || bk.chapters || bk.главы;
|
| 986 |
-
|
| 987 |
-
// Если нет секций, но есть статьи напрямую
|
| 988 |
-
if(!sectionsArr || !sectionsArr.length) {
|
| 989 |
-
const articlesArr = bk.articles || bk.статьи || bk.items;
|
| 990 |
-
if(articlesArr && articlesArr.length) {
|
| 991 |
-
sectionsArr = [{ title: "Основной текст", articles: articlesArr }];
|
| 992 |
-
} else {
|
| 993 |
-
// Если книга — это просто текст
|
| 994 |
-
const text = bk.body || bk.text || bk.текст || bk.content;
|
| 995 |
-
if(text) {
|
| 996 |
-
leaves.push({
|
| 997 |
-
book: bookTitle,
|
| 998 |
-
section: null,
|
| 999 |
-
article: "Статья",
|
| 1000 |
-
subheading: null,
|
| 1001 |
-
text: text
|
| 1002 |
-
});
|
| 1003 |
-
}
|
| 1004 |
-
continue;
|
| 1005 |
-
}
|
| 1006 |
-
}
|
| 1007 |
-
|
| 1008 |
-
for(const sec of (sectionsArr || [])){
|
| 1009 |
-
const sectionTitle = sec.title || sec.название || sec.section || sec.раздел || "Раздел";
|
| 1010 |
-
const articlesArr = sec.articles || sec.статьи || sec.items || sec.contents;
|
| 1011 |
-
|
| 1012 |
-
if(articlesArr && articlesArr.length) {
|
| 1013 |
-
for(const art of articlesArr){
|
| 1014 |
-
const articleTitle = art.title || art.название || art.article || art.статья || "Статья";
|
| 1015 |
-
const subheading = art.subheading || art.подзаголовок || null;
|
| 1016 |
-
const text = art.body || art.text || art.текст || art.content || "";
|
| 1017 |
-
|
| 1018 |
-
if(text && text.trim()) {
|
| 1019 |
-
leaves.push({
|
| 1020 |
-
book: bookTitle,
|
| 1021 |
-
section: sectionTitle,
|
| 1022 |
-
article: articleTitle,
|
| 1023 |
-
subheading: subheading,
|
| 1024 |
-
text: text
|
| 1025 |
-
});
|
| 1026 |
-
}
|
| 1027 |
-
}
|
| 1028 |
-
} else {
|
| 1029 |
-
// Если в секции нет статей, но есть текст
|
| 1030 |
-
const text = sec.body || sec.text || sec.текст || sec.content;
|
| 1031 |
-
if(text && text.trim()) {
|
| 1032 |
-
leaves.push({
|
| 1033 |
-
book: bookTitle,
|
| 1034 |
-
section: sectionTitle,
|
| 1035 |
-
article: "Статья",
|
| 1036 |
-
subheading: null,
|
| 1037 |
-
text: text
|
| 1038 |
-
});
|
| 1039 |
-
}
|
| 1040 |
-
}
|
| 1041 |
-
}
|
| 1042 |
-
}
|
| 1043 |
-
return leaves;
|
| 1044 |
-
}
|
| 1045 |
-
|
| 1046 |
-
async function loadBooksData(){
|
| 1047 |
-
if(booksLoaded)return;
|
| 1048 |
-
booksLoaded=true;
|
| 1049 |
-
try{
|
| 1050 |
-
const resp=await fetch("books.json");
|
| 1051 |
-
if(!resp.ok)throw new Error("HTTP "+resp.status);
|
| 1052 |
-
const data=await resp.json();
|
| 1053 |
-
bookLeaves=flattenBooks(data);
|
| 1054 |
-
if(!bookLeaves.length){
|
| 1055 |
-
booksLoadError="books.json загружен, но в нём не нашлось ни одного текстового фрагмента. Проверьте структуру файла (Книга → Раздел → Статья → Подзаголовок → текст).";
|
| 1056 |
-
}else{
|
| 1057 |
-
const pseudoArticles=bookLeaves.map((l,i)=>({title:String(i),body:l.text}));
|
| 1058 |
-
bookIndex=buildIndex(pseudoArticles);
|
| 1059 |
-
}
|
| 1060 |
-
}catch(e){
|
| 1061 |
-
booksLoadError="Не удалось загрузить books.json: "+e.message+". Файл должен лежать рядом с index.html в корне пространства.";
|
| 1062 |
-
}
|
| 1063 |
-
}
|
| 1064 |
-
|
| 1065 |
-
function findBookMatches(text,threshold,maxResults=3){
|
| 1066 |
-
if(!bookIndex)return [];
|
| 1067 |
-
const cands=nearest(text,bookIndex);
|
| 1068 |
-
const seen=new Set();
|
| 1069 |
-
const out=[];
|
| 1070 |
-
for(const c of cands){
|
| 1071 |
-
if(c.sim<threshold)continue;
|
| 1072 |
-
const leafIdx=Number(bookIndex.titles[c.index]);
|
| 1073 |
-
if(seen.has(leafIdx))continue;
|
| 1074 |
-
seen.add(leafIdx);
|
| 1075 |
-
out.push({leaf:bookLeaves[leafIdx],sim:c.sim,matchedSentence:bookIndex.sentences[c.index]});
|
| 1076 |
-
}
|
| 1077 |
-
out.sort((a,b)=>b.sim-a.sim);
|
| 1078 |
-
return out.slice(0,maxResults);
|
| 1079 |
-
}
|
| 1080 |
-
|
| 1081 |
-
function renderBookMatches(anchorsData,threshold){
|
| 1082 |
-
const box=$("bookMatches");
|
| 1083 |
-
if(!$("searchBooks").checked || !anchorsData){
|
| 1084 |
-
box.style.display="none";
|
| 1085 |
-
box.innerHTML="";
|
| 1086 |
-
return;
|
| 1087 |
-
}
|
| 1088 |
-
if(booksLoadError){
|
| 1089 |
-
box.style.display="block";
|
| 1090 |
-
box.innerHTML=`<div class="book-match-error">⚠️ ${escapeHtml(booksLoadError)}</div>`;
|
| 1091 |
-
return;
|
| 1092 |
-
}
|
| 1093 |
-
if(!bookIndex){
|
| 1094 |
-
box.style.display="block";
|
| 1095 |
-
box.innerHTML=`<div class="book-match-loading">📚 Загрузка books.json...</div>`;
|
| 1096 |
-
return;
|
| 1097 |
-
}
|
| 1098 |
-
let html=`<div class="book-matches-title">📚 Совпадения с книгами (порог ${threshold}%)</div>`;
|
| 1099 |
-
let any=false;
|
| 1100 |
-
for(const r of anchorsData.results){
|
| 1101 |
-
const matches=findBookMatches(r.chunk.body,threshold);
|
| 1102 |
-
if(!matches.length)continue;
|
| 1103 |
-
any=true;
|
| 1104 |
-
const matchedSegs=[];
|
| 1105 |
-
for(const arr of r.segs)for(const s of arr)if(s.is_match)matchedSegs.push(s);
|
| 1106 |
-
let label;
|
| 1107 |
-
if(matchedSegs.length){
|
| 1108 |
-
matchedSegs.sort((a,b)=>b.score-a.score);
|
| 1109 |
-
label=`Статья «${escapeHtml(matchedSegs[0].article)}»`;
|
| 1110 |
-
}else{
|
| 1111 |
-
label=`Кусок ${escapeHtml(r.chunk.number)}. «${escapeHtml(r.chunk.title)}»`;
|
| 1112 |
-
}
|
| 1113 |
-
html+=`<div class="book-match-item"><div class="book-match-label">${label}</div>`;
|
| 1114 |
-
for(const m of matches){
|
| 1115 |
-
const parts=[];
|
| 1116 |
-
if(m.leaf.book)parts.push(m.leaf.book);
|
| 1117 |
-
if(m.leaf.section)parts.push(m.leaf.section);
|
| 1118 |
-
if(m.leaf.article)parts.push(m.leaf.article);
|
| 1119 |
-
if(m.leaf.subheading)parts.push(m.leaf.subheading);
|
| 1120 |
-
const path=parts.map(p=>`«${escapeHtml(p)}»`).join(" → ");
|
| 1121 |
-
html+=`<div class="book-match-path"><span class="pct-badge book-pct">${Math.round(m.sim)}%</span> ${path}: <span class="book-match-text">«${escapeHtml(m.matchedSentence)}»</span></div>`;
|
| 1122 |
-
}
|
| 1123 |
-
html+=`</div>`;
|
| 1124 |
-
}
|
| 1125 |
-
if(!any){
|
| 1126 |
-
html+=`<div class="book-match-empty">При пороге ${threshold}% совпадений с книгами не найдено.</div>`;
|
| 1127 |
-
}
|
| 1128 |
-
box.style.display="block";
|
| 1129 |
-
box.innerHTML=html;
|
| 1130 |
-
}
|
| 1131 |
-
|
| 1132 |
-
$("searchBooks").addEventListener("change",async()=>{
|
| 1133 |
-
if(!$("searchBooks").checked){
|
| 1134 |
-
$("bookMatches").style.display="none";
|
| 1135 |
-
$("bookMatches").innerHTML="";
|
| 1136 |
-
return;
|
| 1137 |
-
}
|
| 1138 |
-
if(!lastAnchorsData)return;
|
| 1139 |
-
$("bookMatches").style.display="block";
|
| 1140 |
-
$("bookMatches").innerHTML=`<div class="book-match-loading">📚 Ищем совпадения в книгах...</div>`;
|
| 1141 |
-
await loadBooksData();
|
| 1142 |
-
renderBookMatches(lastAnchorsData,+$("threshold").value);
|
| 1143 |
-
});
|
| 1144 |
-
/* ==================== /Поиск по книгам ==================== */
|
| 1145 |
-
|
| 1146 |
-
async function runBothModes(articleRaw,chunkRaw,baseOpt,useAdaptive){
|
| 1147 |
-
const articles=parseArticles(articleRaw);
|
| 1148 |
-
const chunks=parseChunks(chunkRaw);
|
| 1149 |
-
const colorMap=buildChunkColorMap(chunks);
|
| 1150 |
-
|
| 1151 |
-
const articleIndex=buildIndex(articles);
|
| 1152 |
-
let matched=0,matchCount=0;
|
| 1153 |
-
const resultsAnchors=[];
|
| 1154 |
-
for(let ci=0;ci<chunks.length;ci++){
|
| 1155 |
-
const chunk=chunks[ci];
|
| 1156 |
-
updateProgress(ci+1,chunks.length,`Якоря: кусок ${ci+1} из ${chunks.length}...`);
|
| 1157 |
-
await new Promise(r=>setTimeout(r,0));
|
| 1158 |
-
const segs=useAdaptive
|
| 1159 |
-
?findMatchesAdaptive(chunk.body,articleIndex,baseOpt)
|
| 1160 |
-
:findMatchesInChunk(chunk.body,articleIndex,baseOpt);
|
| 1161 |
-
const has=segs.some(x=>x.some(s=>s.is_match));
|
| 1162 |
-
if(has)matched++;
|
| 1163 |
-
matchCount+=segs.reduce((sum,arr)=>sum+arr.filter(s=>s.is_match).length,0);
|
| 1164 |
-
resultsAnchors.push({chunk,segs,has});
|
| 1165 |
-
}
|
| 1166 |
-
const anchorsData={mode:"check",articles,chunks,results:resultsAnchors,matched,matchCount,colorMap};
|
| 1167 |
-
lastAnchorsData=anchorsData;
|
| 1168 |
-
renderAnchorsResults(anchorsData);
|
| 1169 |
-
|
| 1170 |
-
const chunkAsArticles=chunks.map(c=>({title:`Кусок ${c.number}. ${c.title}`,body:c.body}));
|
| 1171 |
-
const chunkIndex=buildIndex(chunkAsArticles);
|
| 1172 |
-
const resultsCoverage=[];
|
| 1173 |
-
let totalChars=0,matchedChars=0;
|
| 1174 |
-
const usedAnywhere=new Set();
|
| 1175 |
-
for(let ai=0;ai<articles.length;ai++){
|
| 1176 |
-
const art=articles[ai];
|
| 1177 |
-
updateProgress(ai+1,articles.length,`Покрытие: статья ${ai+1} из ${articles.length}...`);
|
| 1178 |
-
await new Promise(r=>setTimeout(r,0));
|
| 1179 |
-
const segs=useAdaptive
|
| 1180 |
-
?findMatchesAdaptive(art.body,chunkIndex,baseOpt)
|
| 1181 |
-
:findMatchesInChunk(art.body,chunkIndex,baseOpt);
|
| 1182 |
-
let artTotal=0,artMatched=0;
|
| 1183 |
-
const usedHere=new Set();
|
| 1184 |
-
for(const para of segs){
|
| 1185 |
-
for(const s of para){
|
| 1186 |
-
const len=s.text.replace(/\s/g,"").length;
|
| 1187 |
-
artTotal+=len;
|
| 1188 |
-
if(s.is_match){artMatched+=len;usedHere.add(s.article);usedAnywhere.add(s.article);}
|
| 1189 |
-
}
|
| 1190 |
-
}
|
| 1191 |
-
totalChars+=artTotal;
|
| 1192 |
-
matchedChars+=artMatched;
|
| 1193 |
-
const pct=artTotal?(artMatched/artTotal*100):0;
|
| 1194 |
-
resultsCoverage.push({article:art,segs,pct,usedChunkCount:usedHere.size});
|
| 1195 |
-
}
|
| 1196 |
-
const overallPct=totalChars?(matchedChars/totalChars*100):0;
|
| 1197 |
-
const allChunkTitles=chunkAsArticles.map(c=>c.title);
|
| 1198 |
-
const unusedChunks=allChunkTitles.filter(t=>!usedAnywhere.has(t));
|
| 1199 |
-
const coverageData={mode:"coverage",articles,chunks,results:resultsCoverage,overallPct,unusedChunks,colorMap};
|
| 1200 |
-
renderCoverageResults(coverageData);
|
| 1201 |
-
|
| 1202 |
-
renderCleanView(anchorsData);
|
| 1203 |
-
|
| 1204 |
-
$("status").textContent=`Готово: текстов в подборке — ${matched}/${chunks.length}, покрытие — ${overallPct.toFixed(1)}%`;
|
| 1205 |
-
}
|
| 1206 |
-
|
| 1207 |
-
function renderAnchorsResults(data){
|
| 1208 |
-
if(data.matched===0){
|
| 1209 |
-
$("outputAnchors").className="result-panel active";
|
| 1210 |
-
$("outputAnchors").innerHTML=`<div class="unique-banner">✅ Проверено текстов: ${data.chunks.length}. Совпадений со статьями не найдено — все тексты (куски) уникальны.</div>`;
|
| 1211 |
-
return;
|
| 1212 |
-
}
|
| 1213 |
-
const colorMap=data.colorMap;
|
| 1214 |
-
let html=`<p>Статей: <b>${data.articles.length}</b>. Кусков всего: <b>${data.chunks.length}</b>. Кусков с совпадениями: <b>${data.matched}</b>. Найдено совпадений: <b>${data.matchCount}</b>.</p>`;
|
| 1215 |
-
for(const r of data.results){
|
| 1216 |
-
if(!r.has)continue;
|
| 1217 |
-
const chunkTitle=`Кусок ${r.chunk.number}. ${r.chunk.title}`;
|
| 1218 |
-
const color=colorMap.get(chunkTitle)||CHUNK_COLORS[0];
|
| 1219 |
-
html+=`<div class="by-chunk-header" style="background:${color.bg};color:${color.fg};border:1px solid ${color.fg};margin-bottom:8px">Кусок ${escapeHtml(r.chunk.number)}. ${escapeHtml(r.chunk.title)}</div>`;
|
| 1220 |
-
for(const segs of r.segs){
|
| 1221 |
-
html+=`<div class="split-row">`;
|
| 1222 |
-
html+=`<div class="split-left"><p>${renderHighlighted(segs,colorMap)}</p></div>`;
|
| 1223 |
-
html+=`<div class="split-divider"></div>`;
|
| 1224 |
-
html+=`<div class="split-right">${renderRightColumn(segs,false,colorMap)}</div>`;
|
| 1225 |
-
html+=`</div>`;
|
| 1226 |
-
}
|
| 1227 |
-
}
|
| 1228 |
-
html+=`<p><b>Итого кусков: ${data.chunks.length}. Текстов с совпадениями: ${data.matched}. Найдено совпадений: ${data.matchCount}.</b></p>`;
|
| 1229 |
-
$("outputAnchors").className="result-panel active";
|
| 1230 |
-
$("outputAnchors").innerHTML=html;
|
| 1231 |
-
}
|
| 1232 |
-
|
| 1233 |
-
function renderCoverageResults(data){
|
| 1234 |
-
const colorMap=data.colorMap;
|
| 1235 |
-
let html=`<div class="coverage-summary"><div class="coverage-pct">${data.overallPct.toFixed(1)}%</div><div class="coverage-label">текста статей покрыто кусками<br>Статей: ${data.articles.length}. Кусков: ${data.chunks.length}.</div></div>`;
|
| 1236 |
-
html+=`<div class="chunk-legend">`;
|
| 1237 |
-
for(const chunk of data.chunks){
|
| 1238 |
-
const title=`Кусок ${chunk.number}. ${chunk.title}`;
|
| 1239 |
-
const color=colorMap.get(title)||CHUNK_COLORS[0];
|
| 1240 |
-
html+=`<div class="chunk-legend-item"><div class="chunk-legend-dot" style="background:${color.bg};border:1px solid ${color.fg}"></div>Кусок ${escapeHtml(chunk.number)}</div>`;
|
| 1241 |
-
}
|
| 1242 |
-
html+=`</div>`;
|
| 1243 |
-
for(const r of data.results){
|
| 1244 |
-
html+=`<div class="chunk-title">${escapeHtml(r.article.title)} — покрытие ${r.pct.toFixed(1)}%</div>`;
|
| 1245 |
-
for(const para of r.segs){
|
| 1246 |
-
const covered=para.some(s=>s.is_match);
|
| 1247 |
-
html+=`<div class="split-row">`;
|
| 1248 |
-
html+=`<div class="split-left"><p class="cov-para${covered?"":" uncovered"}">${renderCoverageHighlighted(para,colorMap)}</p></div>`;
|
| 1249 |
-
html+=`<div class="split-divider"></div>`;
|
| 1250 |
-
html+=`<div class="split-right">${renderRightColumn(para,true,colorMap)}</div>`;
|
| 1251 |
-
html+=`</div>`;
|
| 1252 |
-
}
|
| 1253 |
-
}
|
| 1254 |
-
if(data.unusedChunks.length){
|
| 1255 |
-
html+=`<div class="unused-box"><b>Эти куски не нашли соответствия в тексте статей — проверьте, не потерялись ли они при сборке:</b><ul>`;
|
| 1256 |
-
for(const t of data.unusedChunks)html+=`<li>${escapeHtml(t)}</li>`;
|
| 1257 |
-
html+=`</ul></div>`;
|
| 1258 |
-
}
|
| 1259 |
-
$("outputCoverage").className="result-panel";
|
| 1260 |
-
$("outputCoverage").innerHTML=html;
|
| 1261 |
-
}
|
| 1262 |
-
|
| 1263 |
-
function renderCleanView(data){
|
| 1264 |
-
if(data.matched===0){
|
| 1265 |
-
$("outputClean").className="result-panel";
|
| 1266 |
-
$("outputClean").innerHTML=`<div class="unique-banner">✅ Нет совпадений — нечего показывать.</div>`;
|
| 1267 |
-
return;
|
| 1268 |
-
}
|
| 1269 |
-
const colorMap=data.colorMap;
|
| 1270 |
-
let html="";
|
| 1271 |
-
for(const r of data.results){
|
| 1272 |
-
if(!r.has)continue;
|
| 1273 |
-
const chunkTitle=`Кусок ${r.chunk.number}. ${r.chunk.title}`;
|
| 1274 |
-
const color=colorMap.get(chunkTitle)||CHUNK_COLORS[0];
|
| 1275 |
-
html+=`<div class="clean-chunk">`;
|
| 1276 |
-
html+=`<div class="clean-chunk-left">`;
|
| 1277 |
-
html+=`<div class="clean-chunk-header" style="background:${color.bg};color:${color.fg};border:1px solid ${color.fg}">Кусок ${escapeHtml(r.chunk.number)}. ${escapeHtml(r.chunk.title)}</div>`;
|
| 1278 |
-
html+=`</div>`;
|
| 1279 |
-
html+=`<div class="clean-chunk-right">`;
|
| 1280 |
-
html+=`<div class="clean-chunk-body">`;
|
| 1281 |
-
|
| 1282 |
-
// Берём оригинальные абзацы из тела куска
|
| 1283 |
-
const origSubparas=r.chunk.body.split("\n").map(x=>x.trim()).filter(Boolean);
|
| 1284 |
-
|
| 1285 |
-
// Собираем все предложения из результатов поиска и создаём карту "предложение -> сегмент"
|
| 1286 |
-
const sentenceMap=new Map();
|
| 1287 |
-
for(const segArr of r.segs){
|
| 1288 |
-
for(const seg of segArr){
|
| 1289 |
-
const segSentences=seg.text.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 1290 |
-
for(const sent of segSentences){
|
| 1291 |
-
sentenceMap.set(sent, seg);
|
| 1292 |
-
}
|
| 1293 |
-
}
|
| 1294 |
-
}
|
| 1295 |
-
|
| 1296 |
-
// Проходим по каждому оригинальному абзацу
|
| 1297 |
-
for(const origSp of origSubparas){
|
| 1298 |
-
const origSentences=origSp.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 1299 |
-
const paraSegs=[];
|
| 1300 |
-
const usedSentences=new Set();
|
| 1301 |
-
|
| 1302 |
-
// Для каждого предложения в оригинальном абзаце находим соответствующий сегмент
|
| 1303 |
-
for(const sent of origSentences){
|
| 1304 |
-
if(sentenceMap.has(sent) && !usedSentences.has(sent)){
|
| 1305 |
-
const seg=sentenceMap.get(sent);
|
| 1306 |
-
paraSegs.push(seg);
|
| 1307 |
-
// Помечаем все пр��дложения этого сегмента как использованные
|
| 1308 |
-
const segSents=seg.text.split(SENT_SPLIT_RE).map(x=>x.trim()).filter(Boolean);
|
| 1309 |
-
for(const ss of segSents){
|
| 1310 |
-
usedSentences.add(ss);
|
| 1311 |
-
}
|
| 1312 |
-
}
|
| 1313 |
-
}
|
| 1314 |
-
|
| 1315 |
-
if(paraSegs.length>0){
|
| 1316 |
-
html+=`<p>${renderHighlighted(paraSegs,colorMap)}</p>`;
|
| 1317 |
-
} else {
|
| 1318 |
-
html+=`<p>${escapeHtml(origSp)}</p>`;
|
| 1319 |
-
}
|
| 1320 |
-
}
|
| 1321 |
-
|
| 1322 |
-
html+=`</div>`;
|
| 1323 |
-
html+=`</div>`;
|
| 1324 |
-
html+=`</div>`;
|
| 1325 |
-
}
|
| 1326 |
-
$("outputClean").className="result-panel";
|
| 1327 |
-
$("outputClean").innerHTML=html;
|
| 1328 |
-
}
|
| 1329 |
-
|
| 1330 |
-
$("run").addEventListener("click",async()=>{
|
| 1331 |
-
const searchBooks = $("searchBooks").checked;
|
| 1332 |
-
const articleRaw = $("articlesText").value;
|
| 1333 |
-
const chunkRaw = $("chunksText").value;
|
| 1334 |
-
|
| 1335 |
-
if (!chunkRaw.trim()) { alert("Нужно вставить текст кусков."); return; }
|
| 1336 |
-
if (!searchBooks && !articleRaw.trim()) { alert("В режиме 'без книг' нужно вставить текст статей."); return; }
|
| 1337 |
-
$("status").textContent="Обработка...";
|
| 1338 |
-
$("run").disabled=true;
|
| 1339 |
-
showProgress();
|
| 1340 |
-
await new Promise(r=>setTimeout(r,50));
|
| 1341 |
-
try{
|
| 1342 |
-
const baseOpt={
|
| 1343 |
-
threshold:+$("threshold").value,
|
| 1344 |
-
...HIDDEN_OPT
|
| 1345 |
-
};
|
| 1346 |
-
const useAdaptive=$("autoMode").checked;
|
| 1347 |
-
await runBothModes(articleRaw,chunkRaw,baseOpt,useAdaptive);
|
| 1348 |
-
if($("searchBooks").checked){
|
| 1349 |
-
$("bookMatches").style.display="block";
|
| 1350 |
-
$("bookMatches").innerHTML=`<div class="book-match-loading">📚 Ищем совпадения в книгах...</div>`;
|
| 1351 |
-
await loadBooksData();
|
| 1352 |
-
renderBookMatches(lastAnchorsData,baseOpt.threshold);
|
| 1353 |
-
}else{
|
| 1354 |
-
$("bookMatches").style.display="none";
|
| 1355 |
-
$("bookMatches").innerHTML="";
|
| 1356 |
-
}
|
| 1357 |
-
if(useAdaptive){
|
| 1358 |
-
const infoDiv=document.createElement("div");
|
| 1359 |
-
infoDiv.className="auto-info";
|
| 1360 |
-
infoDiv.innerHTML=`⚙️ <b>Адаптивный режим:</b> для каждого абзаца автоматически выбран оптимальный порог схожести (от 50% до 90%), максимизирующий точность совпадений.`;
|
| 1361 |
-
$("outputAnchors").insertBefore(infoDiv.cloneNode(true),$("outputAnchors").firstChild);
|
| 1362 |
-
$("outputCoverage").insertBefore(infoDiv.cloneNode(true),$("outputCoverage").firstChild);
|
| 1363 |
-
}
|
| 1364 |
-
}catch(e){
|
| 1365 |
-
console.error(e);
|
| 1366 |
-
$("status").textContent="Ошибка";
|
| 1367 |
-
$("outputAnchors").className="result-panel active empty";
|
| 1368 |
-
$("outputAnchors").innerHTML=`<div class="empty">Ошибка: ${escapeHtml(e.message)}</div>`;
|
| 1369 |
-
}finally{
|
| 1370 |
-
hideProgress();
|
| 1371 |
-
$("run").disabled=false;
|
| 1372 |
-
}
|
| 1373 |
-
});
|
| 1374 |
-
</script>
|
| 1375 |
-
</body>
|
| 1376 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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