diff --git a/src/adonisjs/public/editor/annotate/js/annotator.js b/src/adonisjs/public/editor/annotate/js/annotator.js index 9c121757..bd084f2e 100644 --- a/src/adonisjs/public/editor/annotate/js/annotator.js +++ b/src/adonisjs/public/editor/annotate/js/annotator.js @@ -211,7 +211,11 @@ class Annotator { for (const r of a.fragments) ranges.push({fragment: r, annot: [a]}) } - ranges.sort((a, b) => a.fragment.start - b.fragment.start) + ranges.sort((a, b) => + (a.fragment.start == b.fragment.start) + ? b.fragment.size - a.fragment.size // bigger first + : a.fragment.start - b.fragment.start + ) for (let r = 0; r < ranges.length - 1; r++) { if ((ranges[r].fragment.start == ranges[r + 1].fragment.start) && (ranges[r].fragment.size == ranges[r + 1].fragment.size)) { @@ -540,7 +544,8 @@ class Annotator { } const ctcategories = Object.keys(catIndex).length - const clustering = Math.round(AnnotationMetrics.i._clusteringFreeRecall(catOrder)*100) / 100 + const cfr = AnnotationMetrics.i._clusteringFreeRecall(catOrder) + const clustering = (isNaN) ? cfr : Math.round(cfr * 100) / 100 if (isAnnotations) { document.querySelector('#memory-scores').innerHTML = diff --git a/src/adonisjs/public/editor/annotate/js/metrics.js b/src/adonisjs/public/editor/annotate/js/metrics.js index a8b430bd..6dc412f0 100644 --- a/src/adonisjs/public/editor/annotate/js/metrics.js +++ b/src/adonisjs/public/editor/annotate/js/metrics.js @@ -87,7 +87,9 @@ class AnnotationMetrics { else nc[cat]++ let nextPos = i + 1 - while (nextPos < sortedL.length && sortedL[nextPos][1] === sortedL[i][1]) + // find next position of the same category or neighbor start + while (nextPos < sortedL.length && + sortedL[nextPos][0] != cat && sortedL[nextPos][1] === sortedL[i][1]) nextPos++ if (nextPos < sortedL.length) { let sp = nextPos @@ -115,7 +117,24 @@ class AnnotationMetrics { const ds = r - er // deviation score - const arc = (r - er) / (max - er) // adjusted ratio of clustering + const arc = + (max - er == 0) ? '0/0' : (r - er) / (max - er) // adjusted ratio of clustering + + console.log('\n\n=== Clustering Free Recall ===') + console.log(JSON.stringify(categoriesOrder)) + console.log('--- n = ' + n) + console.log('--- sorted by position') + console.log(JSON.stringify(sortedL)) + console.log('--- c = ' + c) + console.log('--- ni') + console.log(JSON.stringify(nc)) + console.log('--- r = ' + r) + console.log('--- max = ' + max) + console.log('--- E(r) = ' + Math.round(er * 100) / 100) + console.log('--- RR = ' + Math.round(rr * 100) / 100) + console.log('--- MRR = ' + Math.round(mrr * 100) / 100) + console.log('--- DS = ' + Math.round(ds * 100) / 100) + console.log('--- ARC = ' + ((isNaN(arc)) ? arc : Math.round(arc * 100) / 100)) if (present != null) { present('\n\n=== Clustering Free Recall ===') @@ -125,14 +144,14 @@ class AnnotationMetrics { present(JSON.stringify(sortedL)) present('--- c = ' + c) present('--- ni') - present(nc) + present(JSON.stringify(nc)) present('--- r = ' + r) present('--- max = ' + max) present('--- E(r) = ' + Math.round(er * 100) / 100) present('--- RR = ' + Math.round(rr * 100) / 100) present('--- MRR = ' + Math.round(mrr * 100) / 100) present('--- DS = ' + Math.round(ds * 100) / 100) - present('--- ARC = ' + Math.round(arc * 100) / 100) + present('--- ARC = ' + ((isNaN(arc)) ? arc : Math.round(arc * 100) / 100)) } return arc diff --git a/src/adonisjs/public/editor/annotate/metrics/test-metrics.js b/src/adonisjs/public/editor/annotate/metrics/test-metrics.js index 4d745ff4..b198ff3b 100644 --- a/src/adonisjs/public/editor/annotate/metrics/test-metrics.js +++ b/src/adonisjs/public/editor/annotate/metrics/test-metrics.js @@ -31,4 +31,19 @@ present(AnnotationMetrics.i._clusteringFreeRecall( present(AnnotationMetrics.i._clusteringFreeRecall( [[2, 71], [2, 96], [3, 98], [2, 98], [5, 98], [5, 130], [5, 135], [3, 140], [5, 180]], present)) present(AnnotationMetrics.i._clusteringFreeRecall( - [[2, 71], [2, 96], [3, 98], [2, 98], [5, 98], [7,98], [5, 130], [5, 135], [3, 140], [5, 180]], present)) \ No newline at end of file + [[2, 71], [2, 96], [3, 98], [2, 98], [5, 98], [7,98], [5, 130], [5, 135], [3, 140], [5, 180]], present)) +present(AnnotationMetrics.i._clusteringFreeRecall( + [[2, 1], [5, 2], [2, 3], [3, 4], [1, 5], [5, 6]], present +)) +present(AnnotationMetrics.i._clusteringFreeRecall( + [[1, 1], [1, 2], [1, 3], [2, 4]], present +)) +present(AnnotationMetrics.i._clusteringFreeRecall( + [[7,1],[3,2],[7,3],[3,4],[2,5],[2,6]], present +)) +present(AnnotationMetrics.i._clusteringFreeRecall( + [[1,1],[1,2],[5,3],[2,4],[8,5],[1,6],[1,7]], present +)) +present(AnnotationMetrics.i._clusteringFreeRecall( + [[5,1], [5,2], [5,3]], present +)) \ No newline at end of file