Skip to content

Commit

Permalink
Merge pull request #23 from Roboy/rum-rebellion
Browse files Browse the repository at this point in the history
Ravestate v0.2.0
  • Loading branch information
josephbirkner authored Dec 3, 2018
2 parents 00944f3 + db7525a commit 992f345
Show file tree
Hide file tree
Showing 31 changed files with 548 additions and 107 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
*.key
*.default
.coverage
.pytest_cache
.idea
__pycache__
tts.wav
keys.yml
keys.yml
dist/*
build/*
*.egg-info
ros2/build
ros2/install
ros2/log
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include modules/ravestate_phrases_basic_en *
86 changes: 63 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@

```
v0.1.0 __ __
__ ____ _ ______ ______/ /_____/ /___
/ \/ __ \/ / / /__ \/ ___\, / __ \, /__ \
/ /\/ /_/ /\ \/ / /_/ /\__, / / /_/ / / /_/ /
\/ \__/\/ \__/ ,___/\____/\/\__/\/\/ ,___/
\____/ \____/
_ __ _ __
_ ___ ____ __ ______ ______/ /_____/ /___
_ _ / \/ __ \/ / / /__ \/ ___\, / __ \, /__ \
_ _ / /\/ /_/ /\ \/ / /_/ /\__, / / /_/ / / /_/ /
_ \/ _\__/\/ _\__/ ,___/\____/\/\__/\/\/ ,___/
_____ _ _\____/ _ _\____/
/_ _\
0> 0>
\__⊽__/ (C) Roboy 2018
```

## About

Ravestate is a reactive library for real-time natural language dialog systems.

## Requirements:
## Dependencies

### portaudio on macOS

In order to install PyAudio with pip, you need to install portaudio first using:

`brew install portaudio`

- Python >= 3.6
## Installation

To install dependencies use:
### Via PIP

The easiest way to install ravestate is through pip:

``
pip install ravestate
``

### For developers

First, install dependencies:

```bash
pip install -r requirements.txt
Expand All @@ -26,31 +44,53 @@ pip install -r requirements.txt
pip install -r requirements-dev.txt
```

### Mac

#### PyAudio
Then, you may open the repository in any IDE, and mark the
`modules` folder as a sources root.

In order to install PyAudio with pip, you need to install portaudio first using:

``
brew install portaudio
``
## Running Hello World

Ravestate applications are defined by a configuration,
that specifies the ravestate modules that should be loaded.
which specifies the ravestate modules that should be loaded.

To run the basic hello world application, run ravestate
with a config file or command line arguments:

To run the basic hello world application, run ravestate with the proper config file:
### Running with command line spec

You can easily run a combination of ravestate modules in a shared context,
by listing them as arguments to the `rasta` command, which is installed
with ravestate:

```bash
./run.sh -f config/hello_world.yml
rasta ravestate_conio ravestate_hello_world
```

Run `rasta -h` to see more options!

### Running with config file(s)

You may specify a series of config files to configure ravestate context,
when specifying everything through the command line becomes too laborious:

```yaml
# In file hello_world.yml
module: core
config:
import:
- ravestate_conio
- ravestate_hello_world
```
Then, run `rasta` with this config file:

```bash
rasta -f hello_world.yml
```

## Running tests

If you have installed the dependencies from ``requirements-dev.txt`` you
may run the ravestate test suite as follows:

```bash
``
./run_tests.sh
```
``
3 changes: 2 additions & 1 deletion config/hello_world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module: core
config:
import:
- ravestate_conio
- hello_world
- ravestate_wildtalk
- ravestate_nlp
3 changes: 2 additions & 1 deletion config/telegram_hello_world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ config:
import:
- ravestate_telegramio
- ravestate_conio
- hello_world
- ravestate_wildtalk
- ravestate_nlp
4 changes: 4 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

python3 setup.py sdist bdist_wheel
twine upload dist/*
17 changes: 8 additions & 9 deletions modules/ravestate/activation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Ravestate class which encapsualtes the activation of a single state
import copy

from ravestate import state
from ravestate import wrappers
from ravestate import icontext
from threading import Thread

from ravestate.constraint import Signal, Constraint, s


class StateActivation:

def __init__(self, st: state.State, ctx: icontext.IContext):
self.state_to_activate = st
self.unfulfilled = [set(trigger_clause) for trigger_clause in st.triggers]
self.unfulfilled: Constraint = copy.deepcopy(st.triggers)
self.ctx = ctx
self.args = []
self.kwargs = {}
Expand All @@ -19,13 +22,9 @@ def specificity(self):
# TODO: Calculate specificity properly
return 1.

def notify_signal(self, signal_name: str):
for unfulfilled_trigger in self.unfulfilled:
if signal_name in unfulfilled_trigger:
unfulfilled_trigger.remove(signal_name)
if len(unfulfilled_trigger) == 0:
return 1
return 0
def notify_signal(self, signal: Signal):
self.unfulfilled.set_signal_true(signal)
return 1 if self.unfulfilled.evaluate() else 0

def run(self, args=(), kwargs={}):
self.args = args
Expand All @@ -36,6 +35,6 @@ def _run_private(self):
context_wrapper = wrappers.ContextWrapper(self.ctx, self.state_to_activate)
result = self.state_to_activate(context_wrapper, self.args, self.kwargs)
if isinstance(result, state.Emit) and self.state_to_activate.signal:
self.ctx.emit(self.state_to_activate.signal_name())
self.ctx.emit(s(self.state_to_activate.signal_name()))
if isinstance(result, state.Delete):
self.ctx.rm_state(st=self.state_to_activate)
6 changes: 3 additions & 3 deletions modules/ravestate/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def handle_args(*args) -> Tuple[List[str], List[Tuple[str, str, Any]], List[str]
formatter_class=RawDescriptionHelpFormatter,
epilog="""
usage:
> run.py ravestate_facerec hello_world
> rasta ravestate_facerec ravestate_hello_world
Import two python modules and run a context.
> run.py \\
-d core import ravestate_facerec hello_world \\
> rasta \\
-d core import ravestate_facerec ravestate_hello_world \\
-f generic.yml \\
-f user.yml
Import two python modules and run a context,
Expand Down
Loading

0 comments on commit 992f345

Please sign in to comment.