ping98k commited on
Commit
f92828b
·
1 Parent(s): 8ecd0da

Add search cluster sorting mode; implement dropdown for selecting sorting criteria in heatmap functionality.

Browse files
Files changed (2) hide show
  1. index.html +9 -0
  2. main.js +56 -1
index.html CHANGED
@@ -69,6 +69,15 @@
69
  <button id="naming-btn">Generate Name</button>
70
  <button id="clusterplot-btn">Cluster Plot</button>
71
 
 
 
 
 
 
 
 
 
 
72
  <button id="heatmap-btn">Similarity</button>
73
  <div id="progress-bar">
74
  <div id="progress-bar-inner"></div>
 
69
  <button id="naming-btn">Generate Name</button>
70
  <button id="clusterplot-btn">Cluster Plot</button>
71
 
72
+ <!-- Add this dropdown for search cluster sorting mode -->
73
+ <div style="margin-bottom: 10px;">
74
+ <label for="search-sort-mode">Search Cluster Sort Mode:</label>
75
+ <select id="search-sort-mode">
76
+ <option value="group">By Group Similarity</option>
77
+ <option value="line">By Max Search Line</option>
78
+ </select>
79
+ </div>
80
+
81
  <button id="heatmap-btn">Similarity</button>
82
  <div id="progress-bar">
83
  <div id="progress-bar-inner"></div>
main.js CHANGED
@@ -17,6 +17,10 @@ document.getElementById("heatmap-btn").onclick = async () => {
17
  progressBarInner.style.width = "0%";
18
 
19
  const text = document.getElementById("input").value;
 
 
 
 
20
 
21
  // Find the index of the search cluster (case-insensitive)
22
  const clusterNames = text.split(/\n/)
@@ -66,7 +70,58 @@ document.getElementById("heatmap-btn").onclick = async () => {
66
  // Reorder text if search cluster is found
67
  // First group is search then follow by hight sim group
68
  // in each group order by high sim line
69
- if (searchIdx !== -1) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  const refEmbed = groupEmbeddings[searchIdx];
71
 
72
  const cleanGroups = groups.map(g =>
 
17
  progressBarInner.style.width = "0%";
18
 
19
  const text = document.getElementById("input").value;
20
+ // Get search sort mode from dropdown
21
+ const searchSortMode = document.getElementById("search-sort-mode")?.value || "group";
22
+ const search_by_max_search_line = searchSortMode === "line";
23
+ const search_by_max_search_group = searchSortMode === "group";
24
 
25
  // Find the index of the search cluster (case-insensitive)
26
  const clusterNames = text.split(/\n/)
 
70
  // Reorder text if search cluster is found
71
  // First group is search then follow by hight sim group
72
  // in each group order by high sim line
73
+ if (searchIdx !== -1 && search_by_max_search_line) {
74
+ const searchLines = groups[searchIdx]
75
+ .split("\n")
76
+ .filter(l => l && !l.startsWith("##"));
77
+ const searchEmbeds = await getLineEmbeddings(searchLines, task);
78
+
79
+ const cleanGroups = groups.map(g =>
80
+ g.split("\n").filter(l => l && !l.startsWith("##"))
81
+ );
82
+ const allLines = cleanGroups.flat();
83
+ const allEmbeds = await getLineEmbeddings(allLines, task);
84
+
85
+ const cosine = (a, b) => {
86
+ let dot = 0, na = 0, nb = 0;
87
+ for (let i = 0; i < a.length; i++) {
88
+ dot += a[i] * b[i];
89
+ na += a[i] * a[i];
90
+ nb += b[i] * b[i];
91
+ }
92
+ return na && nb ? dot / Math.sqrt(na * nb) : 0;
93
+ };
94
+
95
+ const score = e =>
96
+ Math.max(...searchEmbeds.map(se => cosine(se, e)));
97
+
98
+ const idxByGroup = [];
99
+ let p = 0;
100
+ for (const g of cleanGroups) {
101
+ idxByGroup.push(Array.from({ length: g.length }, (_, i) => p + i));
102
+ p += g.length;
103
+ }
104
+
105
+ const sorted = order.map(g =>
106
+ idxByGroup[g]
107
+ .map(i => ({ t: allLines[i], s: score(allEmbeds[i]) }))
108
+ .sort((a, b) => b.s - a.s)
109
+ .map(o => o.t)
110
+ );
111
+
112
+ const finalText = order
113
+ .map((gIdx, i) => {
114
+ const header =
115
+ clusterNames?.length === n ? clusterNames[gIdx] : `Group ${i + 1}`;
116
+ return `## ${header}\n${sorted[i].join("\n")}`;
117
+ })
118
+ .join("\n\n\n");
119
+
120
+ document.getElementById("input").value = finalText;
121
+ }
122
+
123
+
124
+ if (searchIdx !== -1 && search_by_max_search_group) {
125
  const refEmbed = groupEmbeddings[searchIdx];
126
 
127
  const cleanGroups = groups.map(g =>