Skip to content

mikolajb/cookery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cookery

Features

  • 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

Video

Cookery is a framework for designing Domain Specific Languages for scientific applications in a cloud environment.

How to install

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?)

Integration with Jupyter Notebook

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.

How to use

First, without creating any files, you can evaluate cookery expressions in the following way:

cookery eval "echo 'Hello world!'."

Creating a new project

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

How does it work

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:

  1. Action (always one)
  2. Condition (zero or many)
  3. 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

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

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

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

Syntax

These components define named entities - keywords that can be used in a following syntax:

action Subject [arguments] - condition condition ... condition.

Example

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages