Creating a File-based Termbase
This article shows how to create a file-based termbase (.ttb) programmatically.
Create the Class
Create a class named FileBasedTermbaseCreator.
Add a public asynchronous method named CreateFileBasedTermbaseAsync().
This method accepts the following string parameters:
folderPath- folder where the termbase file will be createdfileName- name of the termbase file
Call the method as follows:
var creator = new FileBasedTermbaseCreator();
await creator.CreateFileBasedTermbaseAsync(@"C:\MyTermbases", "MyTermbase.ttb");
Create the File-based Termbase
Create a CreateTermbaseRequest object and pass it to the CreateTermbaseAsync() method of the TerminologyProviderManager class.
CreateTermbaseRequest includes the following properties:
- Name - termbase name
- Description - termbase description
- Path - folder where the termbase file will be created
- Languages - list of languages to include in the termbase
Each language uses a DefinitionLanguage object with these properties:
- Locale - locale code of the language, for example
enorde - Name - display name of the language
- IsBidirectional - indicates whether the language is bidirectional
- TargetOnly - indicates whether the language is target-only
CreateTermbaseAsync() returns an OperationResult object. Check IsSuccess to confirm that the operation succeeded. If the operation fails, inspect Error for details.
The following example creates a file-based termbase with English and German:
public async Task CreateFileBasedTermbaseAsync(string folderPath, string fileName)
{
var request = new CreateTermbaseRequest
{
Name = fileName,
Description = "My termbase description",
Path = folderPath,
Languages = new List<DefinitionLanguage>
{
new DefinitionLanguage
{
Locale = "en",
Name = "English",
IsBidirectional = true,
TargetOnly = false
},
new DefinitionLanguage
{
Locale = "de",
Name = "German",
IsBidirectional = true,
TargetOnly = false
}
}
};
OperationResult result = await TerminologyProviderManager.Instance.CreateTermbaseAsync(request);
if (!result.IsSuccess)
{
// Handle result.Error.
}
}