The Watson Developer Cloud Swift SDK is a collection of services to allow developers to quickly add Watson Cognitive Computing services and Analytics Insights for Weather to their Swift 3 applications.
The Watson Developer Cloud Swift SDK is currently in beta.
- Installation
- IBM Watson Services
- Alchemy Vision (partial)
- Natural Language Classifier (partial)
- Tone Analyzer
- Personality Insights
- IBM Data and Analytics Services
- Authentication
- Building and Testing
- Open Source @ IBM
- License
- Contributing
The Watson Developer Cloud Swift SDK requires dependencies to run correctly. These dependencies can be found in the package manager file. You can downloading the needed dependencies by invoking package manager with "swift build" from terminal which creates the Packages directory. The project file can be created with "swift build -X" command invoked through terminal.
Getting started with Watson Developer Cloud and Bluemix
The IBM Watson™ Developer Cloud (WDC) offers a variety of services for developing cognitive applications. Each Watson service provides a Representational State Transfer (REST) Application Programming Interface (API) for interacting with the service. Some services, such as the Speech to Text service, provide additional interfaces.
IBM Bluemix™ is the cloud platform in which you deploy applications that you develop with Watson Developer Cloud services. The Watson Developer Cloud documentation provides information for developing applications with Watson services in Bluemix. You can learn more about Bluemix from the following links:
The IBM Bluemix documentation, specifically the pages What is Bluemix? and the Bluemix overview. IBM developerWorks, specifically the IBM Bluemix section of IBM developerWorks and the article that provides An introduction to the application lifecycle on IBM Bluemix.
AlchemyVision is an API that can analyze an image and return the objects, people, and text found within the image. AlchemyVision can enhance the way businesses make decisions by integrating image cognition.
- An Alchemy API Key
Instantiate an AlchemyVision object and set its api key
let alchemyVisionInstance = AlchemyVision(apiKey: String)
API calls are instance methods, and model class instances are returned as part of our callback.
e.g.
let failure = { (error: RestError) in print(error) }
alchemyVisionInstance.getRankedImageKeywords(url: urlString,
forceShowAll: true,
knowledgeGraph: true,
failure: failure) { (response) in
// code here
})
The IBM Watson™ Natural Language Classifier service uses machine learning algorithms to return the top matching predefined classes for short text input. You create and train a classifier to connect predefined classes to example texts so that the service can apply those classes to new inputs.
Instantiate a NaturalLanguageClassifier object and set its username and password
let naturalLanguageClassifier = NaturalLanguageClassifier(username: username, password: password)
API calls are instance methods, and model class instances are returned as part of our callback.
e.g.
let failure = { (error: RestError) in print(error) }
naturalLanguageClassifier.getClassifiers(failure: failure) { response in
// code here
})
The IBM Watson Tone Analyzer service can be used to discover, understand, and revise the language tones in text. The service uses linguistic analysis to detect three types of tones from written text: emotions, social tendencies, and writing style.
Emotions identified include things like anger, fear, joy, sadness, and disgust. Identified social tendencies include things from the Big Five personality traits used by some psychologists. These include openness, conscientiousness, extraversion, agreeableness, and emotional range. Identified writing styles include confident, analytical, and tentative.
The following links provide more information about the IBM Watson Tone Analyzer service:
The following example demonstrates how to use the Tone Analyzer service:
import ToneAnalyzerV3
let username = "your-username-here"
let password = "your-password-here"
let version = "YYYY-MM-DD" // use today's date for the most recent version
let toneAnalyzer = ToneAnalyzer(username: username, password: password, version: version)
let text = "your-input-text"
let failure = { (error: RestError) in print(error) }
toneAnalyzer.getTone(text, failure: failure) { tones in
// code here
}
The IBM Watson Personality Insights service enables applications to derive insights from social media, enterprise data, or other digital communications. The service uses linguistic analytics to infer personality and social characteristics, including Big Five, Needs, and Values, from text.
The following links provide more information about the Personality Insights service:
- IBM Watson Personality Insights - Service Page
- IBM Watson Personality Insights - Documentation
- IBM Watson Personality Insights - Demo
The following example demonstrates how to use the Personality Insights service:
import PersonalityInsightsV2
let username = "your-username-here"
let password = "your-password-here"
let personalityInsights = PersonalityInsights(username: username, password: password)
let text = "your-input-text"
let failure = { (error: RestError) in print(error) }
personalityInsights.getProfile(text: text, failure: failure) { profile in
// code here
}
Getting started with IBM Data and Analytics Services and Bluemix
Use IBM® Insights for Weather to incorporate weather data from The Weather Company (TWC) into your IBM® Bluemix® applications.
IBM Bluemix™ is the cloud platform in which you deploy applications that you develop with Watson Developer Cloud services. The Watson Developer Cloud documentation provides information for developing applications with Watson services in Bluemix. You can learn more about Bluemix from the following links:
The IBM Bluemix documentation, specifically the pages What is Bluemix? and the Bluemix overview. IBM developerWorks, specifically the IBM Bluemix section of IBM developerWorks and the article that provides An introduction to the application lifecycle on IBM Bluemix.
This service lets you integrate historical and real-time weather data from The Weather Company into your IBM Bluemix application. You can retrieve weather data for an area specified by a geolocation. The data allows you to forecast, detect, and visualize disruptive weather events that might affect decision making in your application.
You can add weather observations and forecasts to your Bluemix application and display the weather data for an area that is specified by a geolocation by using the Insights for Weather REST APIs. The Weather Company is the most comprehensive provider of historical and forecast weather data. Data for all forms of weather, including precipitation, barometric pressure, wind, and thunderstorms, is captured.
You can use the REST APIs to retrieve the following information:
An hourly weather forecast for the next 24 hours that starts from the current time for a specified geolocation. A daily weather forecast for the next 10 days that includes forecasts for the daytime and nighttime segments for a specified geolocation. This forecast includes the forecast narrative text string of up to 256 characters with appropriate units of measure for the location and in the language requested. The current observed weather data for a specified geolocation. This weather data includes temperature, precipitation, wind direction and speed, humidity, barometric pressure, dew point, visibility, and ultraviolet (UV) radiation. The observed weather data for a specified geolocation and a specified time range. This data is sourced from physical observation stations. This API returns weather observations for current conditions and past observations up to and including the previous 24 hours.
Instantiate an Insights for Weather service:
let insightsForWeatherInstance = InsightsForWeather(username: username, password: password)
API calls are instance methods, and model class instances are returned as part of our callback.
e.g.
let failure = { (error: RestError) in print(error) }
insightsForWeather.getCurrentForecast(
units: units,
geocode: geocode,
language: language,
failure: failure) { response in
// code here
})
IBM Watson Services and Insights for Weather are hosted in the Bluemix platform. Before you can use each service in the SDK, the service must first be created in Bluemix, bound to an Application, and you must have the credentials that Bluemix generates for that service. Alchemy services use a single API key, and all the other Watson services use a username and password credential.
XCode is used to build the project for testing and deployment. Select Product->Build For->Testing to build the project in XCode's menu.
In order to build the project and run the unit tests, a credentials.plist file needs to be populated with proper credentials in order to communicate with the running Watson services. A copy of this file is located in the project's folder under Tests. The credentials.plist file contains a key and value for each service's user name and password.
There are some tests already in place that can be displayed when selecting the Test Navigator in XCode. Right click on the test you want to run and select Test in the context menu to run that specific test. You can also select a full node and right-click to run all of the tests in that node or service.
Find more open source projects on the IBM Github Page
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
This SDK is intended solely for use with an Apple iOS product and intended to be used in conjunction with officially licensed Apple development tools.
See CONTRIBUTING on how to help out.