Setting threashold for fuzzy search results over MultiTerm Termbases

Hi,

I am trying to give my language provider plugin access to the termbases. 

The only way I found to access the entries of termabes is via search in a Sdl.MultiTerm.TMO.Interop.Termbase.

After loading the termbase I am initializing a search with

TermbaseSearch search = termbase.Search;
search.MaximumHits = 10;
search.FuzzySearch = true;
search.SourceIndex = someSourceLanguage;

And then I search via

HitTerms oHits = search.Execute();

But I did not find a way to set the threashold for the fuzzy search.
My goal is to find terms that are similar e.g. plural form of a term. But i do not want to get terms that are really different from my search term. At the moment this is the case. I have an entry in a termbase for the german word "Leiden" but it also finds this term when I search for "denn" or "denen". 
Is there an easy way to set the threshold? 

If not, could you recommend something to achieve my goal? I am not set on using the termbase search i can use something else.

Best,

Lukas

Parents
  • Hi  , you can also use the TerminologyManager singleton (https://developers.rws.com/studio-api-docs/api/terminology/Sdl.Terminology.TerminologyProvider.Core.TerminologyProviderManager.html?q=TerminologyProviderManager)

    Example:

    using Sdl.Terminology.TerminologyProvider.Core;
    
    // Example URI for your termbase
    string termbaseUriString = "file:///C:/Termbases/MyTermbase.sdltb";
    Uri termbaseUri = new Uri(termbaseUriString);
    
    // Get the terminology provider singleton instance
    var terminologyProvider = TerminologyProviderManager.Instance.GetTerminologyProvider(termbaseUri);
    
    // Ensure the provider is initialized before searching
    if (!terminologyProvider.IsInitialized)
    {
        try
        {
            terminologyProvider.Initialize();
        }
        catch (Exception ex)
        {
            // Handle initialization errors appropriately (log or surface meaningful error)
            throw new InvalidOperationException("Failed to initialize terminology provider.", ex);
        }
    }
    
    // Set up search parameters
    var sourceLanguage = new CultureInfo("en-US");
    var targetLanguage = new CultureInfo("it-IT");
    string segmentText = "Insert your source segment text here";
    int maxResultsCount = 10;
    bool targetRequired = true;
    
    // Perform a fuzzy terminology search
    var searchResults = terminologyProvider.Search(
        segmentText,
        sourceLanguage,
        targetLanguage,
        maxResultsCount,
        SearchMode.Fuzzy,
        targetRequired
    );
    
    // Process or display results as needed...

    Patrick Andrew Hartnett | Developer Experience | Team Lead | RWS Group

  • Hi  , thank you for this option! I will try this to check if it applies the application settings for the fuzzy threshold.

    One note on your code: terminologyProvider.Search() requires ILanguage instead of CultureInfo. I will try to construct a DefintionLanguage out of my CulureInfo to use it for the search. Please tell me if there is a more established approach

  • I tried to edit my answer but i am probably too late.  

    I added the Sdl.Terminology.TerminologyProver.Core dll to my project dependencies and I can get the TerminilogyProviderManager.Instance as you described.
    Wwhen I try to get the TerminologyProvider for a termbase it throws a MissingTerminologyProviderException.

    I get the paths from 

     List<Sdl.ProjectAutomation.Core.Termbase> termbases = SdlTradosStudio.Application.GetController<ProjectsController>().CurrentProject.GetTermbaseConfiguration().Termbases;
     
     foreach (Sdl.ProjectAutomation.Core.Termbase termbase in termbases) {
        if (termBase is LocalTermbase localTermbase && File.Exists(localTermbase.FilePath))
        {
            string filepath = localTermbase.FilePath;
        }
        
     }
     

    Then i create a new Uri with each paths and try to get the TerminologyProvider. But then the excpetion is thrown.

    I am developing a TranslationProviderPlugin if that matters? 

Reply
  • I tried to edit my answer but i am probably too late.  

    I added the Sdl.Terminology.TerminologyProver.Core dll to my project dependencies and I can get the TerminilogyProviderManager.Instance as you described.
    Wwhen I try to get the TerminologyProvider for a termbase it throws a MissingTerminologyProviderException.

    I get the paths from 

     List<Sdl.ProjectAutomation.Core.Termbase> termbases = SdlTradosStudio.Application.GetController<ProjectsController>().CurrentProject.GetTermbaseConfiguration().Termbases;
     
     foreach (Sdl.ProjectAutomation.Core.Termbase termbase in termbases) {
        if (termBase is LocalTermbase localTermbase && File.Exists(localTermbase.FilePath))
        {
            string filepath = localTermbase.FilePath;
        }
        
     }
     

    Then i create a new Uri with each paths and try to get the TerminologyProvider. But then the excpetion is thrown.

    I am developing a TranslationProviderPlugin if that matters? 

Children
  • If anyboby reads this, I found a solution.

    For whatever reason the TerminologyProvider URIs in the TerminologyProviderManager Instance do not start with "file". They start with "sdltb.file".
    I have to admit I wasted a lot of time searching for this.

    I am still on Studio 2024 (NOT SR1) so I dn't know if this is true for SR1 and later.


    For a 'Sdl.MultiTerm.TMO.Interop.Termbase termbase' you can do 

    Uri termbaseUri = new Uri(termbase.Information.Path, UriKind.Absolute);
    Uri termbaseUriSdltb = (new UriBuilder(termbaseUri) { Scheme = "sdltb.file", Port = -1 }).Uri;
     var terminologyProvider = TerminologyProviderManager.Instance.GetTerminologyProvider(termbaseUriSdltb);