multiterm api count number of language terms

I am trying to access the Termbase statistics with the MultiTerm Api.

I am able to retrieve the Total number of entries:

Termbase.Entries.Count.ToString();

But how do I retrieve the breakdown for each language, like this:

Termbase.Statistics.Language.Breakdown

Thanks in advance

Top Replies

  • Hi ,

    I did an investigation on the Multiterm public API and you can get the number of entries for each language using one of the the following methods:

    Method 1. Get the language indexes from the current project and retrieve the NumberOfEntriesInIndex using the languageIndex:

       var projectsController = SdlTradosStudio.Application.GetController<ProjectsController>();
          var activeProject = projectsController?.CurrentProject;

          var termbaseConfiguration = activeProject?.GetTermbaseConfiguration();

          var languageIndexes = termbaseConfiguration.LanguageIndexes;

    After you get the list of Language Indexes, you should retreive the corresponding Language Index for the curent language, like in the below print screen:

    In the final step, you can use the languageIndex to get the number of entries from the termbase, using the below code:

    var numberOfLanguageEntries  = termbase.Information.NumberOfEntriesInIndex["languageIndex"];

    Note: On the Community Wiki area, we have a documentation which explains how to add a new entry, what is language index and how to get it using Multiterm SDK, the wiki page can be accessed using this link. (I've updated the Wiki page with this new information which shows how to get the number of entries for each language using the public API)

    Method 2. Parsing the Termbase Definition XML and get the needed information (this method is a bit complex, because requiers to create your own implementation to get the nodes information). The Definition can be accessed using the following code:

    var entries = termbase.Entries;
    var definition = termbase.Definition;
    var def = definition._Definition;

    The _Definition property keeps the entire termbase definition, including the languages and entries, so you can use it to extract the needed information.

    You can use the https://codebeautify.org/xmlviewer tool to check how  the xml result looks like.

    With kind regards,

    Florentina Caputa

  • Hi

    Thanks for the reply, however neither of the methods will give me the required data.

    Your first method uses the SdlTradosStudio/Project Api and in my case I am accessing standalone termbases (not attached to projects).

    The second method uses the Termbase Definition XML data which I already have access to. However a termbase definition can have more languages defined than actually in use. For example, I can define "de", "en" and "fr", which would all appear in the definition file; but only the "de" and "en" languages could have entries and terms. This is the data I am looking for.

    How does the desktop application access the term count for each language without looping through each entry?

    Kind regards

    Samuel  

  • Hi ,

    I will look on how you can get the number of entries on a standalone application and I will come back to you with an answer.

    Kind regards,

    Florentina

  • HI ,

    In order to get the number of entries for a standalone application, please see the following code (which can be also found within the SDL GitHub public repository, under the Code samples folder):

    The "GetNumberOfEntriesForEachLanguage(Termbase localtermbase)" method will return the terms entry for each language. I've implemented the method to return a Dictionary<string,int> which contains the language index and the corresponding number of terms.

    • Get the termabase
    • Get the termbase information: var termbaseInformation = termbase.Information;
    • Get the Indexes from termbase.Definition.Indexes (each index corresponds to one language)
    • Use the Language value from each index to retrieve the number of terms entry : termbaseInformation.NumberOfEntriesInIndex(languageIndex.Language)

    On  the appstore.sdl.com site, you can also find the Multiterm Desktop SDK, and I've also update the Multiterm Wiki page with the above details.

    With kind regards,

    Florentina Caputa

  • Lovely stuff, just what I needed. Thanks again for your help.

  • I am really happy that my answer helped you, any time.

    Wish you a beautiful day.

    Florentina

  • Hi Florentina,

    Sorry to bring this one up again.

    I've just noticed that your code counts the number of Entries per Language. 

    What I am really after is the number of Terms per Language.

    Is that at all possible?

    Thanks,

    Samuel