Introduction
Welcome to the documentation for the BNGAPI library! This documentation will guide you through using the library to interact with the BNG (Bilingual Neural Graph) service.
Getting Started
In order to use the BNGAPI library, you’ll need to sign up for an API key on the BNG website. Once you have your API key, you’re ready to get started with integrating BNG into your own applications.
Installation
To install the BNGAPI library, you have a couple of options:
- Using CocoaPods: Add the following line to your Podfile:
pod 'BNGAPI'
Then run:pod install
- Manual installation: Download the BNGAPI framework from the GitHub repository and add it to your project.
Once the BNGAPI library is installed, you can import it into your code and start using the BNG service.
Usage
To use the BNGAPI library, you need to create an instance of the `BNGAPI` class:
import BNGAPI
let bngAPI = BNGAPI(apiKey: "YOUR_API_KEY")
Replace “YOUR_API_KEY” with your actual API key obtained from the BNG website.
Once you have an instance of `BNGAPI`, you can make various API calls to interact with the BNG service. Here are some examples:
Translation
To make a translation request, use the `translate` method:
let textToTranslate = "Hello, world!"
let targetLanguage = "es"
bngAPI.translate(textToTranslate, to: targetLanguage) { (translatedText, error) in
if let translatedText = translatedText {
print("Translated text:", translatedText)
} else if let error = error {
print("Translation error:", error)
}
}
This example translates the text “Hello, world!” to Spanish (target language). The translated text or any error message will be returned in the completion handler.
Language Detection
To detect the language of a given text, use the `detectLanguage` method:
let textToDetect = "Hola, mundo!"
bngAPI.detectLanguage(textToDetect) { (detectedLanguage, error) in
if let detectedLanguage = detectedLanguage {
print("Detected language:", detectedLanguage)
} else if let error = error {
print("Language detection error:", error)
}
}
This example detects the language of the given text “Hola, mundo!”. The detected language or any error message will be returned in the completion handler.
Glossary
To retrieve a glossary, use the `getGlossary` method:
let glossaryID = "YOUR_GLOSSARY_ID"
bngAPI.getGlossary(glossaryID) { (glossary, error) in
if let glossary = glossary {
print("Glossary:", glossary)
} else if let error = error {
print("Glossary retrieval error:", error)
}
}
This example retrieves a glossary with the given glossary ID. The glossary or any error message will be returned in the completion handler.
Note: Make sure to replace “YOUR_GLOSSARY_ID” with the actual ID of the glossary you want to retrieve.
Conclusion
That covers the basics of using the BNGAPI library to interact with the BNG service. For more details, please refer to the library’s documentation and the BNG website.