Spaces:
Running
Running
Tobias Brugger
commited on
Commit
·
4c94a05
1
Parent(s):
a45d152
add direct translation hint
Browse files- src/lib/DatasetViewer.svelte +71 -4
src/lib/DatasetViewer.svelte
CHANGED
|
@@ -10,8 +10,38 @@
|
|
| 10 |
];
|
| 11 |
|
| 12 |
// Hardcoded configuration
|
| 13 |
-
const dataset = '
|
| 14 |
-
const scoresDataset = '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
// Form inputs
|
| 17 |
let jurisdiction1 = $state('en-us');
|
|
@@ -111,6 +141,23 @@
|
|
| 111 |
return term.replace(/_/g, ' ').replace(/\s+/g, ' ').trim().toLowerCase();
|
| 112 |
}
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
function getSimilarityScore(): EquivalencyScore | null {
|
| 115 |
if (!selectedTerm1 || !selectedTerm2 || equivalencyScores.length === 0) {
|
| 116 |
return null;
|
|
@@ -181,9 +228,12 @@
|
|
| 181 |
<label for="term1">Select Term:</label>
|
| 182 |
<select id="term1" bind:value={selectedTerm1}>
|
| 183 |
{#each data1 as item}
|
| 184 |
-
<option value={item.term}>
|
|
|
|
|
|
|
| 185 |
{/each}
|
| 186 |
</select>
|
|
|
|
| 187 |
</div>
|
| 188 |
{#if selectedTerm1}
|
| 189 |
<div class="definition-box">
|
|
@@ -205,9 +255,12 @@
|
|
| 205 |
<label for="term2">Select Term:</label>
|
| 206 |
<select id="term2" bind:value={selectedTerm2}>
|
| 207 |
{#each data2 as item}
|
| 208 |
-
<option value={item.term}>
|
|
|
|
|
|
|
| 209 |
{/each}
|
| 210 |
</select>
|
|
|
|
| 211 |
</div>
|
| 212 |
{#if selectedTerm2}
|
| 213 |
<div class="definition-box">
|
|
@@ -515,4 +568,18 @@
|
|
| 515 |
grid-template-columns: 1fr;
|
| 516 |
}
|
| 517 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
</style>
|
|
|
|
| 10 |
];
|
| 11 |
|
| 12 |
// Hardcoded configuration
|
| 13 |
+
const dataset = import.meta.env.VITE_PUBLIC_HUGGINGFACE_ORG + '/structured-answers';
|
| 14 |
+
const scoresDataset = import.meta.env.VITE_PUBLIC_HUGGINGFACE_ORG + '/equivalency-scores';
|
| 15 |
+
|
| 16 |
+
// Direct translations dictionary (English -> Swedish)
|
| 17 |
+
const directTranslations: Record<string, string> = {
|
| 18 |
+
"proximate cause": "adekvat kausalitet",
|
| 19 |
+
"articles of association": "bolagsordning",
|
| 20 |
+
"bylaws": "bolagsordning",
|
| 21 |
+
"condominium": "bostadrätt",
|
| 22 |
+
"cooperative apartment": "bostadrätt",
|
| 23 |
+
"company name": "firma",
|
| 24 |
+
"company": "firma",
|
| 25 |
+
"dispose of": "förfoga över",
|
| 26 |
+
"rights of first refusal": "hembud",
|
| 27 |
+
"implied consent": "konkludent handlande",
|
| 28 |
+
"aiding and abetting": "medverkande",
|
| 29 |
+
"trading prohibition": "näringsförbud",
|
| 30 |
+
"affiliated company": "närstående bolag",
|
| 31 |
+
"molestation": "ofredande",
|
| 32 |
+
"dismiss on the merits": "ogilla",
|
| 33 |
+
"the rule of contra proferentem": "oklarhetsregeln",
|
| 34 |
+
"joinder of parties": "processgemenskap",
|
| 35 |
+
"ultimate facts": "rättsfakta",
|
| 36 |
+
"apparent authority": "ställningsfullmakt",
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
// Create bidirectional lookup map (both English->Swedish and Swedish->English)
|
| 40 |
+
const translationMap = new Map<string, string>();
|
| 41 |
+
Object.entries(directTranslations).forEach(([en, sv]) => {
|
| 42 |
+
translationMap.set(en.toLowerCase(), sv.toLowerCase());
|
| 43 |
+
translationMap.set(sv.toLowerCase(), en.toLowerCase());
|
| 44 |
+
});
|
| 45 |
|
| 46 |
// Form inputs
|
| 47 |
let jurisdiction1 = $state('en-us');
|
|
|
|
| 141 |
return term.replace(/_/g, ' ').replace(/\s+/g, ' ').trim().toLowerCase();
|
| 142 |
}
|
| 143 |
|
| 144 |
+
// Get direct translation equivalent for a term
|
| 145 |
+
function getDirectTranslation(term: string): string | null {
|
| 146 |
+
const normalized = normalizeTermForComparison(term);
|
| 147 |
+
return translationMap.get(normalized) || null;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
// Check if a term should be highlighted based on the selected term in the other jurisdiction
|
| 151 |
+
function shouldHighlightTerm(term: string, selectedInOtherJurisdiction: string | null): boolean {
|
| 152 |
+
if (!selectedInOtherJurisdiction) return false;
|
| 153 |
+
|
| 154 |
+
const equivalentOfSelected = getDirectTranslation(selectedInOtherJurisdiction);
|
| 155 |
+
if (!equivalentOfSelected) return false;
|
| 156 |
+
|
| 157 |
+
const normalizedTerm = normalizeTermForComparison(term);
|
| 158 |
+
return normalizedTerm === equivalentOfSelected;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
function getSimilarityScore(): EquivalencyScore | null {
|
| 162 |
if (!selectedTerm1 || !selectedTerm2 || equivalencyScores.length === 0) {
|
| 163 |
return null;
|
|
|
|
| 228 |
<label for="term1">Select Term:</label>
|
| 229 |
<select id="term1" bind:value={selectedTerm1}>
|
| 230 |
{#each data1 as item}
|
| 231 |
+
<option value={item.term}>
|
| 232 |
+
{shouldHighlightTerm(item.term, selectedTerm2) ? '★ ' : ''}{item.term}
|
| 233 |
+
</option>
|
| 234 |
{/each}
|
| 235 |
</select>
|
| 236 |
+
<small class="translation-hint">★ = Direct translation equivalent</small>
|
| 237 |
</div>
|
| 238 |
{#if selectedTerm1}
|
| 239 |
<div class="definition-box">
|
|
|
|
| 255 |
<label for="term2">Select Term:</label>
|
| 256 |
<select id="term2" bind:value={selectedTerm2}>
|
| 257 |
{#each data2 as item}
|
| 258 |
+
<option value={item.term}>
|
| 259 |
+
{shouldHighlightTerm(item.term, selectedTerm1) ? '★ ' : ''}{item.term}
|
| 260 |
+
</option>
|
| 261 |
{/each}
|
| 262 |
</select>
|
| 263 |
+
<small class="translation-hint">★ = Direct translation equivalent</small>
|
| 264 |
</div>
|
| 265 |
{#if selectedTerm2}
|
| 266 |
<div class="definition-box">
|
|
|
|
| 568 |
grid-template-columns: 1fr;
|
| 569 |
}
|
| 570 |
}
|
| 571 |
+
|
| 572 |
+
/* Highlighting for direct translation equivalents */
|
| 573 |
+
option.highlighted {
|
| 574 |
+
background-color: #ffd700;
|
| 575 |
+
font-weight: 600;
|
| 576 |
+
color: #000;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
.translation-hint {
|
| 580 |
+
display: block;
|
| 581 |
+
margin-top: 0.25rem;
|
| 582 |
+
color: #666;
|
| 583 |
+
font-style: italic;
|
| 584 |
+
}
|
| 585 |
</style>
|