1- // Libraries & stores
2-
3- import * as API from "@/api/evaluation"
41import { distributionPath } from "@/api/evaluation"
52import { useAxios } from "@/api/useAxios"
63import stores from "@/stores"
7- import * as Utils from "@/stores/evaluation/utils"
8- // API & types
9- // API & types
10- import type { UUID } from "@/types/corpora"
11- import type { DistributionWrapper } from "@/types/evaluation"
4+ import type { TypeToken , Distribution } from "@/types/evaluation/distribution"
125import type { SelectOption } from "@/types/ui/select"
136
14- // Allows for Object.keys(distribution.table), which dislikes null.
15- const defaultDistribution = ( ) => ( { distribution : { } } ) as DistributionWrapper
16-
17- /**
18- * Stores and fetches the term frequency distribution.
19- */
7+ /** Stores and fetches the term frequency distribution. */
208const useDistribution = defineStore ( "distribution" , ( ) => {
219 // Fields
2210 const { hypothesisId } = storeToRefs ( stores . useJobSelection ( ) )
@@ -26,30 +14,14 @@ const useDistribution = defineStore("distribution", () => {
2614 return distributionPath ( corpusId . value )
2715 } )
2816
29- const { loading, data : distributions } = useAxios < Record < string , DistributionWrapper > > (
30- url ,
31- { } ,
32- { hypothesis : hypothesisId . value } ,
33- )
17+ const { loading, data : distributions } = useAxios < Record < string , Distribution > > ( url , undefined , {
18+ hypothesis : hypothesisId . value ,
19+ } )
3420
35- const distribution = computed ( ( ) => distributions . value ?. [ selectedDistribution . value ] ?? defaultDistribution ( ) )
21+ const distribution = computed < TypeToken [ ] > ( ( ) => distributions . value ?. [ selectedDistribution . value ] )
3622 const selectedDistribution = ref < string > ( )
37- const distributionOptions = computed < SelectOption [ ] > (
38- ( ) => {
39- if ( ! distributions . value ) {
40- return [ ]
41- }
42- return Object . keys ( distributions . value ) . map ( ( x ) => ( { value : x , text : x } ) )
43- } ,
44- { immediate : true } ,
45- )
46- const posses = computed ( ( ) => {
47- // A bit hacky using Object.entries, but .map throws on undefined.
48- return Object . entries ( distribution . value ?. distribution )
49- ?. map ( ( x ) => x [ 1 ] . pos )
50- . filter ( ( val , ind , arr ) => arr . indexOf ( val ) === ind ) // unique values
51- . sort ( )
52- } )
23+ const distributionOptions = computed < SelectOption [ ] > ( ( ) => Object . keys ( distributions . value || { } ) . map ( ( x ) => ( { value : x , text : x } ) ) )
24+ const posses = computed < string [ ] > ( ( ) => [ ...new Set ( Object . values ( distribution . value || { } ) . map ( ( t : TypeToken ) => t . group ) ) ] . sort ( ) )
5325 // Exports
5426 return {
5527 // Fields
0 commit comments