Krotos Modules 3
Loading...
Searching...
No Matches
krotos::TextToPreset Class Reference

text to preset class for text to preset embeddings calculation and dictionary creation More...

#include <TextToPreset.h>

Inheritance diagram for krotos::TextToPreset:

Classes

struct  Data
 

Public Member Functions

 TextToPreset ()
 
 ~TextToPreset ()
 
float computeSimilarity (const std::vector< float > &queryEmbedding, const std::vector< float > &resultEmbedding) const
 compute cosine similarity based of result to query
 
StringArray combineSearch (const String &searchTerm, const StringArray &classicResults, const StringArray &ttpResults, std::map< String, std::vector< float > > &embeddingsCache, const size_t &maxResults=25)
 combine multiple StringArrays, megre and rerank the items based on cosine similarity
 
StringArray findClosestPresets (String searchTerm, int maxNumPresetsToFind) const
 returns a String array that contains K closest presets,
 
std::string getPresetPath (std::string presetNameToLoad) const
 return the preset path
 
String logString () const
 returns the log string
 
bool processFileList (Array< File > &filesToProcess)
 processes a file list to create text embeddings
 
bool calculateEmbeddingsForPresetFile (File presetFile)
 create text embeddings file for the given preset file
 
bool appendDataToEmbeddingsFile ()
 appends data to the main embeddings file
 
File createFilePath (String filename)
 creates the path for the embeddings file
 
void loadEmbeddings ()
 will load embeddings data from file to all modules that need it
 
StringArray performSearch (String query)
 performs search based on text embeddings and KNN
 
void getSampleMetadata (const std::string &input, unsigned char *byteArray)
 

Private Member Functions

void clear ()
 clears internal data
 
void run () override
 
void getPresetAssetNames (ValueTree &root)
 will get preset asset paths and names to the m_samplePaths and m_sampleFilenames arrays
 
bool assetNamesToTags (bool eliminateDuplicates)
 Splits the asset names, in respect to the excluded terms, and pushes the remaining terms into a new string array.
 
void searchForTagAndProperty (ValueTree &root, Identifier tag, Identifier property)
 this will recursivelly search in a preset ValueTree structure for a given idendtifier and property name
 
std::vector< float > destringify (String stringWithNumbers)
 destrignifies embeddings
 
bool saveToFile (File file)
 saves embeddings to file
 
bool readFromFile (File file)
 load embeddings from file
 
template<class T >
String stringify (std::vector< T > numbers)
 

Private Attributes

String m_logString
 
StringArray m_samplePaths
 
StringArray m_sampleFilenames
 
File m_presetFile
 
String m_presetName
 
StringArray m_presetTags
 
std::map< String, Datam_presetData
 
std::map< std::string, std::string > m_presetNameAndPresetPathMap
 
StringArray excludeTerms
 
String assetPathsDelimiter {"\n"}
 
StringArray m_treatedAssetPaths
 
String delimiters {",|._- "}
 
SentenceTransformer m_sentenceTransformer
 
SharedResourcePointer< UniversalCategorySystemm_UCS
 
KDTreeND m_kNN
 
std::vector< String > m_presetNames
 
CriticalSection m_cs
 
unsigned char m_data [BUFFER_SIZE]
 
bool m_modelFileAvailable {false}
 

Detailed Description

text to preset class for text to preset embeddings calculation and dictionary creation

Constructor & Destructor Documentation

◆ TextToPreset()

krotos::TextToPreset::TextToPreset ( )

◆ ~TextToPreset()

krotos::TextToPreset::~TextToPreset ( )

Member Function Documentation

◆ appendDataToEmbeddingsFile()

bool krotos::TextToPreset::appendDataToEmbeddingsFile ( )

appends data to the main embeddings file

Returns
Returns true if the operation was successful, false if it failed

◆ assetNamesToTags()

bool krotos::TextToPreset::assetNamesToTags ( bool eliminateDuplicates)
private

Splits the asset names, in respect to the excluded terms, and pushes the remaining terms into a new string array.

Parameters
eliminateDuplicatesIf true, duplicates in the resulting tag list will be excluded
Returns
Returns true if the operation was successful, false if it failed

◆ calculateEmbeddingsForPresetFile()

bool krotos::TextToPreset::calculateEmbeddingsForPresetFile ( File presetFile)

create text embeddings file for the given preset file

Returns
Returns true if the operation was successful, false if it failed

◆ clear()

void krotos::TextToPreset::clear ( )
private

clears internal data

◆ combineSearch()

StringArray krotos::TextToPreset::combineSearch ( const String & searchTerm,
const StringArray & classicResults,
const StringArray & ttpResults,
std::map< String, std::vector< float > > & embeddingsCache,
const size_t & maxResults = 25 )

combine multiple StringArrays, megre and rerank the items based on cosine similarity

Parameters
querystring,
classicsearch results
existingtext to preset results
cachedembeddings
Returns
stringarray with adjusted preset recommendations

◆ computeSimilarity()

float krotos::TextToPreset::computeSimilarity ( const std::vector< float > & queryEmbedding,
const std::vector< float > & resultEmbedding ) const

compute cosine similarity based of result to query

Parameters
queryembedding
resultembedding
Returns
similarity value

◆ createFilePath()

File krotos::TextToPreset::createFilePath ( String filename)

creates the path for the embeddings file

◆ destringify()

std::vector< float > krotos::TextToPreset::destringify ( String stringWithNumbers)
private

destrignifies embeddings

◆ findClosestPresets()

StringArray krotos::TextToPreset::findClosestPresets ( String searchTerm,
int maxNumPresetsToFind ) const

returns a String array that contains K closest presets,

Parameters
querystring,
maxpresets to return
Returns
array with preset reccomendations

◆ getPresetAssetNames()

void krotos::TextToPreset::getPresetAssetNames ( ValueTree & root)
private

will get preset asset paths and names to the m_samplePaths and m_sampleFilenames arrays

◆ getPresetPath()

std::string krotos::TextToPreset::getPresetPath ( std::string presetNameToLoad) const
inline

return the preset path

Parameters
thepreset name
Returns
string with preset path

◆ getSampleMetadata()

void krotos::TextToPreset::getSampleMetadata ( const std::string & input,
unsigned char * byteArray )
inline

◆ loadEmbeddings()

void krotos::TextToPreset::loadEmbeddings ( )

will load embeddings data from file to all modules that need it

◆ logString()

String krotos::TextToPreset::logString ( ) const
inline

returns the log string

◆ performSearch()

StringArray krotos::TextToPreset::performSearch ( String query)

performs search based on text embeddings and KNN

◆ processFileList()

bool krotos::TextToPreset::processFileList ( Array< File > & filesToProcess)

processes a file list to create text embeddings

Parameters
filelist to process
Returns
Returns true if the operation was successful, false if it failed

◆ readFromFile()

bool krotos::TextToPreset::readFromFile ( File file)
private

load embeddings from file

◆ run()

void krotos::TextToPreset::run ( )
overrideprivate

◆ saveToFile()

bool krotos::TextToPreset::saveToFile ( File file)
private

saves embeddings to file

◆ searchForTagAndProperty()

void krotos::TextToPreset::searchForTagAndProperty ( ValueTree & root,
Identifier tag,
Identifier property )
private

this will recursivelly search in a preset ValueTree structure for a given idendtifier and property name

◆ stringify()

template<class T >
String krotos::TextToPreset::stringify ( std::vector< T > numbers)
private

std::vector to juce::String

Member Data Documentation

◆ assetPathsDelimiter

String krotos::TextToPreset::assetPathsDelimiter {"\n"}
private

◆ delimiters

String krotos::TextToPreset::delimiters {",|._- "}
private

◆ excludeTerms

StringArray krotos::TextToPreset::excludeTerms
private
Initial value:
{"Woje", "woje", "SNDBTS_CAS1", "SNDBTS_CAS4", ".wav", "wav", "kaf", ".kaf",
"sndbts", "krotos", "krt", "krts", "mf", "ks", "mono", "stereo",
"ambisonic", "and", "in", "on", "up", "or", "i", "ii",
"type1", "type2", "type3", "type4", "type5"}

◆ m_cs

CriticalSection krotos::TextToPreset::m_cs
private

◆ m_data

unsigned char krotos::TextToPreset::m_data[BUFFER_SIZE]
private

◆ m_kNN

KDTreeND krotos::TextToPreset::m_kNN
private

◆ m_logString

String krotos::TextToPreset::m_logString
private

◆ m_modelFileAvailable

bool krotos::TextToPreset::m_modelFileAvailable {false}
private

◆ m_presetData

std::map<String, Data> krotos::TextToPreset::m_presetData
private

◆ m_presetFile

File krotos::TextToPreset::m_presetFile
private

◆ m_presetName

String krotos::TextToPreset::m_presetName
private

◆ m_presetNameAndPresetPathMap

std::map<std::string, std::string> krotos::TextToPreset::m_presetNameAndPresetPathMap
private

◆ m_presetNames

std::vector<String> krotos::TextToPreset::m_presetNames
private

◆ m_presetTags

StringArray krotos::TextToPreset::m_presetTags
private

◆ m_sampleFilenames

StringArray krotos::TextToPreset::m_sampleFilenames
private

◆ m_samplePaths

StringArray krotos::TextToPreset::m_samplePaths
private

◆ m_sentenceTransformer

SentenceTransformer krotos::TextToPreset::m_sentenceTransformer
private

◆ m_treatedAssetPaths

StringArray krotos::TextToPreset::m_treatedAssetPaths
private

◆ m_UCS

SharedResourcePointer<UniversalCategorySystem> krotos::TextToPreset::m_UCS
private

The documentation for this class was generated from the following files: