The following API allows you to analyze text for language, entities (places, people), key phrases, sentiment (positive, neutral, negative), and syntax (pronouns, verbs, adjectives). For analyzing language on iOS we use both AWS backend services as well as Apple's on-device [Natural Language Framework](https://developer.apple.com/documentation/naturallanguage) to provide you with the most accurate results. If your device is offline, we will return results only Natural Language. On the other hand, if you are able to connect to AWS Services, we will return a unioned result from both the service and Natural Language. Switching between backend services and Natural Language is done automatically without any additional configuration required. ## Set up your backend This will allow you to determine key phrases, sentiment, language, syntax, and entities from text. If you haven't already done so, run `amplify init` inside your project and then `amplify add auth` (we recommend selecting the *default configuration*). Run `amplify add predictions`, then use the following answers: ```console ? Please select from one of the categories below Identify Convert ❯ Interpret Infer Learn More ? What would you like to interpret? (Use arrow keys) ❯ Interpret Text ? Provide a friendly name for your resource ? What kind of interpretation would you like? Language Entity Keyphrase Sentiment Syntax ❯ All ? Who should have access? Auth users only ❯ Auth and Guest users ``` Run `amplify push` to create the resources in the cloud ## Working with the API Here is an example of sending text for interpretation such as sentiment analysis or natural language characteristics. ```swift func interpret(text: String) { Amplify.Predictions.interpret(text: text) { event in switch event { case let .success(result): print(result) case let .failure(error): print(error) } } } ``` ```swift func interpret(text: String) -> AnyCancellable { Amplify.Predictions.interpret(text: text) .resultPublisher .sink { if case let .failure(error) = $0 { print(error) } } receiveValue: { result in print(result) } } ```