File size: 1,012 Bytes
a8b3f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'

export const useKnowledge = () => {
  const { t } = useTranslation()

  const formatIndexingTechnique = useCallback((indexingTechnique: string) => {
    return t(`dataset.indexingTechnique.${indexingTechnique}`)
  }, [t])

  const formatIndexingMethod = useCallback((indexingMethod: string, isEco?: boolean) => {
    if (isEco)
      return t('dataset.indexingMethod.invertedIndex')

    return t(`dataset.indexingMethod.${indexingMethod}`)
  }, [t])

  const formatIndexingTechniqueAndMethod = useCallback((indexingTechnique: string, indexingMethod: string) => {
    let result = formatIndexingTechnique(indexingTechnique)

    if (indexingMethod)
      result += ` · ${formatIndexingMethod(indexingMethod, indexingTechnique === 'economy')}`

    return result
  }, [formatIndexingTechnique, formatIndexingMethod])

  return {
    formatIndexingTechnique,
    formatIndexingMethod,
    formatIndexingTechniqueAndMethod,
  }
}