Gm82 commited on
Commit
ee654bc
·
verified ·
1 Parent(s): d40c7b5

Fix renderResults entity type extraction bug

Browse files
Files changed (1) hide show
  1. index.html +6 -10
index.html CHANGED
@@ -568,6 +568,7 @@ async function runNER() {
568
  const errBox = document.getElementById('error-box');
569
 
570
  if (!text) { showError('Please enter some text first.'); return; }
 
571
 
572
  errBox.style.display = 'none';
573
  setLoading(true);
@@ -628,10 +629,12 @@ function renderResults(text, entities) {
628
  const out = document.getElementById('output-section');
629
  const el = document.getElementById('rendered-text');
630
 
 
 
631
  /* Count by type */
632
  const counts = { ACTOR: 0, ACTION: 0, ASSETS: 0 };
633
  entities.forEach(e => {
634
- const t = (e.entity_group || e.entity || '').replace('B-','').replace('I-','');
635
  if (counts[t] !== undefined) counts[t]++;
636
  });
637
  document.getElementById('cnt-actor').textContent = counts.ACTOR;
@@ -645,16 +648,13 @@ function renderResults(text, entities) {
645
 
646
  /* Sort by start position */
647
  const sorted = [...entities]
648
- .filter(e => {
649
- const t = (e.entity_group || e.entity || '').replace('B-','').replace('I-','');
650
- return ['ACTOR','ACTION','ASSETS'].includes(t);
651
- })
652
  .sort((a, b) => (a.start || 0) - (b.start || 0));
653
 
654
  sorted.forEach(ent => {
655
  const start = ent.start || 0;
656
  const end = ent.end || 0;
657
- const type = (ent.entity_group || e_entityType(ent) || '').replace('B-','').replace('I-','');
658
  const score = ((ent.score || 0) * 100).toFixed(1) + '%';
659
  const word = ent.word || text.slice(start, end);
660
 
@@ -678,10 +678,6 @@ function renderResults(text, entities) {
678
  out.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
679
  }
680
 
681
- function e_entityType(e) {
682
- return e.entity_group || e.entity || '';
683
- }
684
-
685
  function escHtml(s) {
686
  return s
687
  .replace(/&/g,'&')
 
568
  const errBox = document.getElementById('error-box');
569
 
570
  if (!text) { showError('Please enter some text first.'); return; }
571
+ if (!token) { showError('An HF token is required. Create one at huggingface.co/settings/tokens and paste it in the Authentication box.'); return; }
572
 
573
  errBox.style.display = 'none';
574
  setLoading(true);
 
629
  const out = document.getElementById('output-section');
630
  const el = document.getElementById('rendered-text');
631
 
632
+ const typeOf = e => (e.entity_group || e.entity || '').replace('B-','').replace('I-','');
633
+
634
  /* Count by type */
635
  const counts = { ACTOR: 0, ACTION: 0, ASSETS: 0 };
636
  entities.forEach(e => {
637
+ const t = typeOf(e);
638
  if (counts[t] !== undefined) counts[t]++;
639
  });
640
  document.getElementById('cnt-actor').textContent = counts.ACTOR;
 
648
 
649
  /* Sort by start position */
650
  const sorted = [...entities]
651
+ .filter(e => ['ACTOR','ACTION','ASSETS'].includes(typeOf(e)))
 
 
 
652
  .sort((a, b) => (a.start || 0) - (b.start || 0));
653
 
654
  sorted.forEach(ent => {
655
  const start = ent.start || 0;
656
  const end = ent.end || 0;
657
+ const type = typeOf(ent);
658
  const score = ((ent.score || 0) * 100).toFixed(1) + '%';
659
  const word = ent.word || text.slice(start, end);
660
 
 
678
  out.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
679
  }
680
 
 
 
 
 
681
  function escHtml(s) {
682
  return s
683
  .replace(/&/g,'&')