diff --git a/package.json b/package.json index 88e8f3a9..4e1ef815 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "react-virtualized-auto-sizer": "^1.0.7", "react-window": "^1.8.8", "recharts": "^2.4.3", + "rouge": "^1.0.3", "seedrandom": "^3.0.5", "shallowequal": "^1.1.0", "short-uuid": "^4.2.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9847ebd2..c0407c55 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + dependencies: '@floating-ui/react': specifier: ^0.19.2 @@ -148,6 +152,9 @@ dependencies: recharts: specifier: ^2.4.3 version: 2.4.3(prop-types@15.8.1)(react-dom@18.2.0)(react@18.2.0) + rouge: + specifier: ^1.0.3 + version: 1.0.3 seedrandom: specifier: ^3.0.5 version: 3.0.5 @@ -5376,6 +5383,11 @@ packages: p-locate: 5.0.0 dev: true + /lodash-node@2.4.1: + resolution: {integrity: sha512-egEt8eNQp2kZWRmngahiqMoDCDCENv3uM188S7Ed5t4k3v6RrLELXC+FqLNMUnhCo7gvQX3G1V8opK/Lcslahg==} + deprecated: This package is discontinued. Use lodash@^4.0.0. + dev: false + /lodash.castarray@4.4.0: resolution: {integrity: sha512-aVx8ztPv7/2ULbArGJ2Y42bG1mEQ5mGjpdvrbJcJFU3TbYybe+QlLS4pst9zV52ymy2in1KpFPiZnAOATxD4+Q==} dev: false @@ -6565,6 +6577,12 @@ packages: fsevents: 2.3.3 dev: true + /rouge@1.0.3: + resolution: {integrity: sha512-YCt74Dxsi99E8/uh943FTa80EmGboaOu1ij4q8WD4EAGyvyWYaH7MRHorrDbGgLY7iFUwDwyW/g9KJZx7D5fUQ==} + dependencies: + lodash-node: 2.4.1 + dev: false + /run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: @@ -7653,7 +7671,3 @@ packages: react: 18.2.0 use-sync-external-store: 1.2.0(react@18.2.0) dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false diff --git a/src/lenses/RougeScoreLens.tsx b/src/lenses/RougeScoreLens.tsx new file mode 100644 index 00000000..9ee86dbf --- /dev/null +++ b/src/lenses/RougeScoreLens.tsx @@ -0,0 +1,39 @@ +import { Lens } from '../types'; +import 'twin.macro'; +import rouge from 'rouge'; +import { formatNumber } from '../dataformat'; + +const RougeScoreLens: Lens = ({ values }) => { + const rouge1 = rouge.n(values[0], values[1], 1); + const rouge2 = rouge.n(values[0], values[1], 2); + return ( +
+
+ Rouge 1: {formatNumber(rouge1)} +
+
+ Rouge 2: {formatNumber(rouge2)} +
+
+ ); +}; + +RougeScoreLens.key = 'RougeScoreView'; +RougeScoreLens.dataTypes = ['str']; +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 []; + 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; + return false; +}; +export default RougeScoreLens; diff --git a/src/lenses/index.ts b/src/lenses/index.ts index 0a170cb5..35051f2d 100644 --- a/src/lenses/index.ts +++ b/src/lenses/index.ts @@ -10,6 +10,7 @@ import SequenceLens from './SequenceLens'; import SpectrogramLens from './SpectrogramLens'; import TextLens from './TextLens'; import VideoLens from './VideoLens'; +import RougeScoreLens from './RougeScoreLens'; export const ALL_LENSES = [ ArrayLens, @@ -24,4 +25,5 @@ export const ALL_LENSES = [ HtmlLens, MarkdownLens, ScalarLens, + RougeScoreLens, ]; diff --git a/src/rougeScore.d.ts b/src/rougeScore.d.ts new file mode 100644 index 00000000..a294f4d3 --- /dev/null +++ b/src/rougeScore.d.ts @@ -0,0 +1 @@ +declare module 'rouge';