license import { Scalar , Tensor , Tensor1D } from '@tensorflow/tfjs-core' ; import * as tfOps from '@tensorflow/tfjs-core/dist/ops/ops_for_converter' ; import { NamedTensorsMap } from '../../data/types' ; import { ExecutionContext } from '../../executor/execution_context' ; import { InternalOpExecutor , Node } from '../types' ; import { getParamValue } from './utils' ; export const executeOp = ( node , tensorMap , context ) : Tensor [ ] => { switch ( node . op ) { case 'StringNGrams' : { const { nGrams , nGramsSplits } = tfOps . string . stringNGrams ( getParamValue ( 'data' , node , tensorMap , context ) as Tensor1D , getParamValue ( 'dataSplits' , node , tensorMap , context ) as Tensor , getParamValue ( 'separator' , node , tensorMap , context ) as string , getParamValue ( 'nGramWidths' , node , tensorMap , context ) as number [ ] , getParamValue ( 'leftPad' , node , tensorMap , context ) as string , getParamValue ( 'rightPad' , node , tensorMap , context ) as string , getParamValue ( 'padWidth' , node , tensorMap , context ) as number , getParamValue ( 'preserveShortSequences' , node , tensorMap , context ) as boolean ) ; return [ nGrams , nGramsSplits ] ; } case 'StringSplit' : { const { indices , values , shape } = tfOps . string . stringSplit ( getParamValue ( 'input' , node , tensorMap , context ) as Tensor1D , getParamValue ( 'delimiter' , node , tensorMap , context ) as Scalar , getParamValue ( 'skipEmpty' , node , tensorMap , context ) as boolean ) ; return [ indices , values , shape ] ; } case 'StringToHashBucketFast' : { const output = tfOps . string . stringToHashBucketFast ( getParamValue ( 'input' , node , tensorMap , context ) as Tensor , getParamValue ( 'numBuckets' , node , tensorMap , context ) as number ) ; return [ output ] ; } default : throw TypeError ( `Node type ${ node . op } is not implemented` ) ; } } ; export const CATEGORY = 'string' ;