Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/owlycode/thematic-speech
An experimental library that can be used to determine actions to issue from natural language
https://github.com/owlycode/thematic-speech
Last synced: about 1 month ago
JSON representation
An experimental library that can be used to determine actions to issue from natural language
- Host: GitHub
- URL: https://github.com/owlycode/thematic-speech
- Owner: OwlyCode
- License: mit
- Created: 2015-06-08T23:38:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-15T12:51:27.000Z (about 9 years ago)
- Last Synced: 2024-04-20T00:21:37.557Z (9 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Thematic Speech
This is an experimental library that can be used to determine actions to issue from natural language.
## Installation
```
{
"require": {
"owlycode/thematic-speech": "dev-master"
}
}
```## Basic usage
```php
registerThematics([
'light' => ['light', 'lightbulb'],
'on' => ['on', 'power', 'start'],
'off' => ['off', 'cut', 'shutdown'],
]);$speech->register(['light', 'on'], [], function () {
echo "Light turned on.\n";
});
$speech->register(['light', 'off'], [], function () {
echo "Light turned off.\n";
});$speech->process('Switch on the light please');
$speech->process('Now, switch off the light');
$speech->process('Power the lightbulb');
$speech->process('Cut the light');
```This should produce an output like this :
```
Light turned on.
Light turned off.
Light turned on.
Light turned off.
```### Using arguments
You can gather some dynamic values from sentences by using argument patterns :
```php
registerThematics([
'light' => ['light', 'lightbulb'],
'on' => ['on', 'power', 'start'],
'off' => ['off', 'cut', 'shutdown'],
]);$speech->register(['light', 'on'], [$identifierPattern], function (ArgumentCollection $arguments) {
if (!$arguments->hasOfType('identifier', 1)) { // Checks we've got at least one identifier.
echo sprintf('You must provide at least one light identifier.');
} else {
$poweredLights = $arguments->getOfType('identifier');
$text = implode(', ', array_map(function ($id) {
return sprintf('"%s"', $id->getValue());
}, $poweredLights));echo sprintf("Light(s) %s turned on.\n", $text);
}
});$speech->process('Switch on the light 1, 2 and 3 please');
$speech->process('Turn on the light');
```This should produce an output like this :
```
Light(s) "1", "2", "3" turned on.
You must provide at least one light identifier.
```