- Integration with Jupyter Notebook
- connect to cloud
- another example with services
- three layers of Cookery
- guideline for users
- guideline for developers
- example on how to implement the lower layer
- ask Kasia what happened with this student
- write something
Cookery is a framework for designing Domain Specific Languages for scientific applications in a cloud environment.
You will need to use Python3. I tested it with version 3.6.
Clone the repository:
git clone https://github.com/mikolajb/cookery.git
and install using pip
pip install --user . # be sure to use the one associated with python3 (pip3?)
If you have a Jupyter Notebook installed in your system, you can take the advantage from Cookery kernel which is supplied with cookery. You can register a kernel with a command:
cookery kernel
Then, if you start jupyter notebook
, you can select "Cookery" as a kernel and execute Cookery scripts in a browser.
First, without creating any files, you can evaluate cookery expressions in the following way:
cookery eval "echo 'Hello world!'."
Using a toolkit, you can create a project in a following way:
cookery new PROJECT_NAME
Then, it can be immediately evaluated using:
cookery run PROJECT_NAME/test.cookery
Cookery is inspired by cooking recipes and it allows to develop scientific applications with plain English. Applications are build from a number of sentences (activities) which, in turn consist the following components:
- Action (always one)
- Condition (zero or many)
- Subject (zero or many)
A result of every activity can be stored in a variable and then used in other activity as a subject.
Action is a pair: name (starts with a lowercase letter) and procedure. Name_ is a reference to created action and can be used in a place of action
(see syntax). Procedure is a block of code that takes one argument - subject. During the execution, action receives a reference to a subject specified be a user.
Condition is very similar to action. It has a name (starts with a lowercase) and procedure. They should have longer, descriptive names and be designed in a way that can work well with various actions.
Subject is built from four elements: name (starts with uppercase letter), type, regular expression and procedure.
- name is a reference to subject's procedure
- regular expression is used to parse subject's arguments, all elements captured by a regular expression are available as arguments
- type (or protocol) points to an implementation of subject's backend, backend provides methods that can be used in a procedure to specify protocol's parameters (e.g. path)
- procedure - block of Ruby code where all the parameters specific to a protocol can be specified using functions provided by a protocol implementation
These components define named entities - keywords that can be used in a following syntax:
action Subject [arguments] - condition condition ... condition.
In a following example we show an application that counts words in a file.
First, we create a new project:
cookery new counter
Then, all the required components have to be defined in counter.py
file:
@cookery.action()
def split(subjects):
return subjects[0].split()
@cookery.action()
def count(subjects):
return len(subjects[0])
@cookery.subject('in', r'(.+)')
def file(path):
print('opening file:', repr(path))
f = open(path, 'r')
return f.read()
It is important to note, that action receives a subject data in a list, even if there is only one subject.
File counter.cookery
should contain Cookery language that uses defined actions and subjects:
A = split File text_file.txt.
count A.