🚫 This project is no longer maintained. Please check out https://github.com/watson-developer-cloud/swift-sdk.
The Watson Developer Cloud Swift SDK is a collection of services to allow developers to quickly add Watson Cognitive Computing services and Analytics Weather Company Data to their Swift 3 applications.
The Watson Developer Cloud Swift SDK is currently in beta.
- Installation
- IBM Watson Services
- IBM Data and Analytics Services
- Weather Company Data (partial)
- 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.
AlchemyLanguage is a collection of text analysis functions that derive semantic information from your content. You can input text, HTML, or a public URL and leverage sophisticated natural language processing techniques to get a quick high-level understanding of your content and obtain detailed insights such as directional sentiment from entity to object.
AlchemyLanguage has a number of features, including:
- Entity Extraction
- Sentiment Analysis
- Keyword Extraction
- Concept Tagging
- Relation Extraction
- Taxonomy Classification
- Author Extraction
- Language Detection
- Text Extraction
- Microformats Parsing
- Feed Detection
- An Alchemy API Key
Instantiate an AlchemyLanguage object and set its api key
let alchemyLanguageInstance = AlchemyLanguage(apiKey: String)
API calls are instance methods, and model class instances are returned as part of our callback.
let failure = { (error: RestError) in print(error) }
alchemyLanguage.getRankedKeywords(forURL: imputEncoded!,
knowledgeGraph: QueryParam.Included,
sentiment: QueryParam.Included,
failure: failure) { keywords in
// code here
}
})
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
})
With the IBM Watson Conversation service you can create cognitive agents--virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements.
The following example shows how to start a conversation with the Conversation service:
import Conversation
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 conversation = Conversation(username: username, password: password, version: version)
let workspaceID = "your-workspace-id-here"
let failure = { (error: RestError) in print(error) }
var context: Context? // save context to continue conversation
conversation.message(workspaceID, failure: failure) { response in
print(response.output.text)
context = response.context
}
The following example shows how to continue an existing conversation with the Conversation service:
```swift
let text = "Turn on the radio."
let failure = { (error: RestError) in print(error) }
conversation.message(workspaceID, text: text, context: context, failure: failure) { response in
print(response.output.text)
context = response.context
}
The following links provide more information about the IBM Conversation service:
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 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 PersonalityInsights
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
}
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 ToneAnalyzer
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
}
Getting started with IBM Data and Analytics Services and Bluemix
Use Weather Company Data for IBM® Bluemix® 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.
Use Weather Company Data for IBM® Bluemix® to incorporate weather data from The Weather Company (TWC) into your IBM® Bluemix® applications.
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 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 48 hours that starts from the current time for a specified geolocation.
- A daily forecast for each of the next 3, 5, 7, or 10 days starting from the current day 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.
- A daily forecast for each of the next 3, 5, 7, or 10 days starting from the current day, which breaks each daily forecast into morning, afternoon, evening, and overnight segments.
- 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 up to and including the previous 24 hours. This data is sourced from physical observation stations.
- Government-issued weather alerts, including weather watches, warnings, statements, and advisories issued by the National Weather Service (US), Environment Canada, and MeteoAlarm (Europe).
- Almanac services that provide historical daily or monthly weather data that is sourced from National Weather Service observations stations from a time period spanning 10 to 30 years or more.
- Location mapping services that provide the ability to look up a location name or geocode (latitude and longitude) to retrieve a set of locations that match your request.
Instantiate an Insights for Weather service:
let weatherCompanyData = WeatherCompanyData(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) }
weatherCompanyData.getCurrentForecast(
units: units,
latitude: latitude,
longitude: longitude,
language: language,
failure: failure) { response in
// code here
})
IBM Watson Services and Weather Company Data 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.swift 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.swift 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.