https://github.com/simplisticated/swiftypredictor
Swift API for Yandex.Predictor service.
https://github.com/simplisticated/swiftypredictor
cloud-computing prediction suggestion-engine swift text
Last synced: about 1 month ago
JSON representation
Swift API for Yandex.Predictor service.
- Host: GitHub
- URL: https://github.com/simplisticated/swiftypredictor
- Owner: simplisticated
- License: mit
- Created: 2017-04-02T00:24:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-24T17:37:44.000Z (over 7 years ago)
- Last Synced: 2025-05-08T17:04:07.054Z (about 1 month ago)
- Topics: cloud-computing, prediction, suggestion-engine, swift, text
- Language: Swift
- Homepage:
- Size: 89.8 KB
- Stars: 21
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
# At a Glance
`SwiftyPredictor` simplifies work with [Yandex.Predictor](https://tech.yandex.ru/predictor) service in iOS.
## How To Get Started
- Copy content of `Source` folder to your project.
or
- Use `SwiftyPredictor` cocoapod.
## Requirements
* iOS 9.0 and later
* Xcode 8 and later## Usage
To initialize predictor, simply write something like this:
```swift
let predictor = Predictor(APIKey: "some_api_key")
```As you noticed, constructor requires API key. If you still don't have it, obtain new API key [here](https://tech.yandex.ru/keys/get/?service=pdct) (you'll need to authorize with Yandex account).
Now you can make requests for text suggestions:
```swift
predictor.requestSuggestions(forQuery: "how to ", inLanguage: .english, withLimit: 10) { (suggestions, error) in
for suggestion in suggestions {
print(suggestion.text)
}
if error != nil {
print("Error: \(error!)")
}
}
```The example above will print suggestions for phrase `how to `:
- `get`
- `make`
- `use`
- `buy`
- `do`You can change language by its identifier or predefined name:
- `.english`
- `.russian`
- `.custom(identifier: "es")` - Spanish language
- etc.If you want to receive full list of supported languages, use `availableLanguages` method:
```swift
predictor.availableLanguages { (languages, error) in
for language in languages {
print(language.identifier)
}
}
```All asynchronous requests made by `Predictor` instance are cancellable so you can stop them when it's needed:
```swift
/*
* Obtain reference to request instance.
*/let request = predictor.requestSuggestions(forQuery: "how to ", inLanguage: .english, withLimit: 10) { (suggestions, error) in
// Do something with suggestions here...
}/*
* Cancel request when needed.
*/request.cancel()
```## License
`SwiftyPredictor` is available under the MIT license. See the [LICENSE](./LICENSE) file for more info.