Skip to content

Commit

Permalink
Added rouge1 and rouge2
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukaushik committed Oct 25, 2023
1 parent 70b9448 commit 584000e
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/lenses/RougeScoreLens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,34 @@ import 'twin.macro';
import rouge from 'rouge';
import { formatNumber } from '../dataformat';

const calculateRougeScore = (values: unknown[]) => {
return rouge.n(values[0], values[1]);
};

const RougeScoreLens: Lens = ({ values }) => {
const result = calculateRougeScore(values);
const rouge1 = rouge.n(values[0], values[1], 1);
const rouge2 = rouge.n(values[0], values[1], 2);
return (
<div tw="text-sm truncate px-1 py-0.5 flex items-center h-full">
Rouge score: {formatNumber(result)}
<div>
<div tw="text-sm truncate px-1 py-0.5 flex items-center h-full">
Rouge 1: {formatNumber(rouge1)}
</div>
<div tw="text-sm truncate px-1 py-0.5 flex items-center h-full">
Rouge 2: {formatNumber(rouge2)}
</div>
</div>
);
};

RougeScoreLens.key = 'RougeScoreView';
RougeScoreLens.dataTypes = ['str'];
RougeScoreLens.defaultHeight = 22;
RougeScoreLens.minHeight = 22;
RougeScoreLens.maxHeight = 64;
RougeScoreLens.defaultHeight = 50;
RougeScoreLens.minHeight = 50;
RougeScoreLens.maxHeight = 100;
RougeScoreLens.multi = true;
RougeScoreLens.displayName = 'ROUGE Score';
RougeScoreLens.filterAllowedColumns = (allColumns, selectedColumns) => {
if (selectedColumns.length === 2) return [];
else
return allColumns.filter(({ type, key }) => {
const isNotSelected = (key: string) => {
return selectedColumns.filter((selectedCol) => {
selectedCol.key !== key;
});
};
return type.kind === 'str' && isNotSelected(key);
});
const selectedKeys = selectedColumns.map((selectedCol) => selectedCol.key);
return allColumns.filter(({ type, key }) => {
return type.kind === 'str' && !selectedKeys.includes(key);
});
};
RougeScoreLens.isSatisfied = (columns) => {
if (columns.length === 2) return true;
Expand Down

0 comments on commit 584000e

Please sign in to comment.