Commit af221b91 authored by Bruno Guillaume's avatar Bruno Guillaume

doc around Python

parent de86715e
......@@ -24,7 +24,7 @@ talc2:
# hugo
# scp -r public/* $(stalc2)/www/grew_doc/
lchn: build
lchn:
hugo
scp -r public/* grew.lchn.fr:/home/guillaum/www/doc/
......
languageCode = "en-us"
title = "Grew"
baseURL = "http://grew.lchn.fr/"
baseURL = "http://grew.fr/"
enableEmoji=true
theme = "hyde"
......
+++
title = "docker"
menu = "main"
Categories = ["Development","GoLang"]
Tags = ["Development","golang"]
Description = ""
date = "2018-04-25T16:59:27+02:00"
+++
# Docker installation
Put the following code in a file called `Dockerfile`.
```
FROM ocaml/opam:ubuntu
RUN sudo apt-get update \
&& sudo apt-get upgrade --assume-yes \
&& sudo apt-get install python3-pip --assume-yes
RUN opam remote add talc "http://talc2.loria.fr/semagramme/opam" \
&& opam install grew grewpy \
&& pip3 install grew
```
Then, you can build the container with the command:
`docker build -t grew .`
And finally, run it with:
`docker run -it grew bash`
## Test
Inside the container (after the command `docker run -it grew bash`), run:
* `python3`
* `import grew`
* `grew.init()`
You should have some output like:
```
connected to port: 8888
<subprocess.Popen object at 0x7ff507bc5208>
```
and **Grew** is ready to be used.
See [tutorial page](../tuto) for simple examples.
......@@ -9,9 +9,8 @@ There are two basic ways to represent *flat* structures:
1. a single-headed structure: for instance the graph `SH6` below on the left for a 6 words flat structure
1. a chained stucture: for instance the graph `C6` below on the right for the same 6 words flat structure
| | |
|:---:|:---:|
| SH6 | C6 |
|:---:|:---:|
| ![SH6](/examples/flat/img/SH6.svg) | ![alt C6](/examples/flat/img/C6.svg) |
We will see how to convert from one to the other with Graph Rewriting.
......
......@@ -5,23 +5,24 @@ title = "installation"
# Grew installation
**Grew** is implemented with the [Ocaml](http://ocaml.org) language.
**Grew** is easy to install on Linux or Mac OS&nbsp;X (installation on Windows should be possible, but this is untested).
The installation proceeds in two steps: first, installation of the native library and second, installation of the Python library
A GTK interface is available (again on Linux and Mac OS&nbsp;X, untested on Windows) separately.
Note: if you use docker, a `dockerFile` is available with everything installed in it, see [Docker page](../docker).
:warning: If you run into trouble using the instructions of this page, feel free to open an issue on [GitLab](https://gitlab.inria.fr/grew/grew_doc/issues).
## Step 1: native library
**Grew** is implemented with the [Ocaml](http://ocaml.org) language.
It is easy to install on Linux or Mac OS&nbsp;X (installation on Windows should be possible, but this is untested).
## Option 1: Basic installation without GTK interface
:warning: If you run into trouble using the instructions of this page, feel free to [open an issue on GitLab](https://gitlab.inria.fr/grew/grew_doc/issues) or to [contact the developer](mailto:Bruno.Guillaume@inria.fr?subject=Install%20of%20Grew).
### On Linux
* First installation
* `apt-get install wget opam m4 aspcud` # Prerequisite
* `opam init -a -y --comp 4.06.0` # Download and install Ocaml (4.06.0)
* ```eval `opam config env` ``` # Make Ocaml ready to use know
* ```eval `opam config env` ``` # Make Ocaml ready to use now
* `opam remote add talc "http://talc2.loria.fr/semagramme/opam"` # Add the talc OPAM repository
* `opam install grew` # Install Grew
* `opam install grew grewpy` # Install Grew
* Test
* Try the command `grew version`
......@@ -40,9 +41,9 @@ A GTK interface is available (again on Linux and Mac OS&nbsp;X, untested on Wind
* First installation
* `sudo port install wget opam aspcud` # Prerequisite
* `opam init -a -y --comp 4.06.0` # Download and install Ocaml (4.06.0)
* ```eval `opam config env` ``` # Make Ocaml ready to use know
* ```eval `opam config env` ``` # Make Ocaml ready to use now
* `opam remote add talc "http://talc2.loria.fr/semagramme/opam"` # Add the talc OPAM repository
* `opam install grew` # Install Grew
* `opam install grew grewpy` # Install Grew
* Test
* Try the command `grew version`
......@@ -53,28 +54,14 @@ A GTK interface is available (again on Linux and Mac OS&nbsp;X, untested on Wind
* `sudo port sync && sudo port upgrade`
* `opam update && opam upgrade`
## Option 2: Installation of the GTK interface
We suppose that the basic version (Option 1) is already installed.
### Linux
* Install GUI interface
* `apt-get install graphviz pkg-config librsvg2-dev libwebkitgtk-dev libglade2-dev libgtk2.0-dev`
* `opam install grew_gui`
## Step 2: The Python library
* Test
* Run `Grew gui` to run the GTk interface
* In case of trouble, [fill an issue](https://gitlab.inria.fr/grew/grew_doc/issues)
### On Mac OS&nbsp;X
* Prerequisite Mac application for running X11 GUI.
* Install [XQuartz](http://www.xquartz.org/)
With Python 3, use the following command:
`pip install grew`
* Install GUI interface
* `sudo port install graphviz librsvg libglade2 webkit-gtk`
* `opam install grew_gui`
Note: depending on your local installation, you may have to use `pip3` or `pip3.5`.
* Test
* Run `Grew gui` to run the GTk interface
* In case of trouble, [fill an issue](https://gitlab.inria.fr/grew/grew_doc/issues)
# Other available installation
* A Gtk user interface is available, see [here](../gtk).
* A docker file with the Python library ready to be used is available [here](../docker).
......@@ -7,6 +7,12 @@ Categories = ["Development","GoLang"]
Tags = ["Development","golang"]
+++
# Running Grew
**Grew** can be used from Python. See [Tutorial page](../tuto) for basic usage from Python.
The remaining of this page presents the command line program.
The command to run **Grew** is: `grew <subcommand> [<args>]`
Available subcommands are:
......@@ -22,7 +28,7 @@ Available subcommands are:
# Transform mode
In this mode, **Grew** apply a Graph Rewrinting System to a graph of a set of graphs.
In this mode, **Grew** apply a Graph Rewriting System to a graph or a set of graphs.
The full command for this mode:
......@@ -44,14 +50,14 @@ Optional argument is:
# GTK interface
The command to run the GTK interface: `grew gui <args>`.
It supposes that you have installed the `grew_gui` opam packages (see [option 2 in Installation page](../installation#option-2-installation-of-the-gtk-interface)).
It supposes that you have installed the `grew_gui` opam packages (see [GUI installation page](../gtk)).
Optional arguments:
* `-grs <grs_file>`: load the given file
* `-i <input_file>`: input data (graph or corpus) loaded in GUI
* `-strat <name>`: the strategy selected in the interface (default: `main`)
* `-main_feat <feat_name_list>` set the list of feature names used ad the *main* feat in graph visualisation
* `-main_feat <feat_name_list>` set the list of feature names used ad the *main* feat in graph visualization
---
# Grep mode
......
# Examples from the book "Application of Graph Rewriting to Natural Language Processing"
The page below follows the first chapter which can be [downloaded in PDF from the editor website](https://media.wiley.com/product_data/excerpt/66/17863009/1786300966-587.pdf).
In Chapter 1 of the book (since 1.5), examples given use the Grew Python library.
Here are the necessary steps to run the book's examples.
We suppose that the [installation](../install) was completed and that a Python script is running.
### Note
Code for subsections 1.1 to 1.4 will be added very soon.
## 1.5. Using patterns with the GREW library
To run the next part of the chapter, the grew library must be imported and the grew tool must be started.
The two next lines are then required:
```python
import grew
grew.init()
```
### Build a graph with Grew syntax
```python
g = grew.graph('''graph {
W1 [phon="the", cat=DET];
W2 [phon="child", cat=N];
W3 [phon="plays", cat=V];
W4 [phon="the", cat=DET];
W5 [phon="fool", cat=N];
W2 -[det]->W1;
W3 -[suj]->W2;
W3 -[obj]->W5;
W5 -[det]->W4;
}''')
```
### Search for a specific pattern
Each line below can be executed separately.
```python
grew.search ("pattern { X[cat=V] }", g)
grew.search ("pattern { X[cat=DET] }", g)
grew.search ("pattern { X[cat=ADJ] }", g)
grew.search ("pattern { X[cat=V]; Y[]; X -[suj]-> Y }", g)
grew.search ("pattern { X[cat=V]; X -[suj]-> Y }", g)
grew.search ("pattern { X[cat=V]; e:X -[suj]-> Y }", g)
grew.search("pattern { X[] } without { *->X }", g)
```
### 1.5.2 Common pitfalls
```python
g0 = grew.graph('''graph {
W1 [phon=ils, cat=PRO];
W2 [phon="s'", cat=PRO];
W3 [phon=aiment, cat=V];
W3 -[suj]-> W1;
W3 -[obj]-> W1;
}''')
```
```python
grew.search ("pattern { X -[suj|obj]-> Y }", g0)
```
```python
m1 = 'pattern{ P[phon="en",cat=P]; V[cat=V]; V-[obj]-> *}'
m2 = 'pattern{ P[phon="en",cat=P]; V[cat=V]; V-[obj]-> O}'
```
```python
g1 = grew.graph('''graph{
W1 [phon="en", cat=P];
W2 [phon="prend", cat=V];
W2 -[obj]->W1;
}''')
```
```python
grew.search(m1, g1)
grew.search(m2, g1)
```
```python
g2 = grew.graph('''graph{
W1 [phon="en", cat=P];
W2 [phon="connait", cat=V];
W3 [phon="la", cat=Det];
W4 [phon="fin", cat=N];
W2 -[det]->W3;
W2 -[mod]->W1;
W2 -[obj]->W4;
}''')
```
```python
grew.search(m1, g2)
grew.search(m2, g2)
```
```python
g3 = grew.graph('''graph{
W1 [phon=John, cat=NP];
W2 [phon=reads, cat=V ];
W3 [phon=the, cat=Det];
W4 [phon=book, cat=N];
W2 -[suj]-> W1;
W2 -[obj]-> W4;
W4 -[det]-> W3;
}''')
```
```python
g4 = grew.graph('''graph{
W1 [phon=John, cat=NP];
W2 [phon=reads, cat=V ];
W3 [phon=the, cat=Det];
W4 [phon=book, cat=N];
W5 [phon=today, cat=ADV];
W2 -[suj]-> W1;
W2 -[obj]-> W4;
W4 -[det]-> W3;
W2 -[mod]-> W5;
}''')
```
```python
m3 = "pattern{Y-[suj]->X} without{Y-[obj]->Z; Y-[mod]->T}"
m4 = "pattern{Y-[suj]->X} without{Y-[obj]->Z} without{Y-[mod]->T}"
```
```python
grew.search(m3, g3)
grew.search(m4, g3)
grew.search(m3, g4)
grew.search(m4, g4)
```
```python
g5 = grew.graph('''graph{
W1 [phon=dors, cat=V, m=imp];
W2 [phon="!", cat=PONCT];
}''')
```
```python
m5 = "pattern { X[cat=V, t=fut] }"
m6 = "pattern { X[cat=V] } without{ X[t<>fut] }"
```
```python
grew.search(m5, g5)
grew.search(m6, g5)
```
```python
grew.search("pattern { e : X -> Y ; f : X -> Y }", g0)
```
### 1.6 Graph rewriting
```python
g = grew.graph('''graph{
W1 [phon="John",cat=NP];
W2 [phon="est",cat=V ];
W3 [phon="mordu", cat=V, m=pastp];
W4 [phon="par",cat=P ];
W5 [phon="le", cat=D];
W6 [word="chien",cat=NP];
W3 -[suj]-> W1;
W3 -[aux.pass]-> W2;
W3 -[p_obj.agt]-> W4;
W6 -[det]-> W5;
W4 -[obj.p]-> W6;
}''')
```
```python
r = """rule passiveAgt {
pattern {
V [cat=V, m=pastp];
V -[aux.pass]-> AUX;
e: V -[suj]-> SUJ;
P [phon=par]; V -[p_obj.agt]-> P;
P -[obj.p]-> A;
} commands {
del_node P;
del_node AUX;
add_edge V -[suj]-> A;
add_edge V -[obj]-> SUJ;
del_edge e;
} }"""
```
```python
grew.run(r, g, 'passiveAgt')
```
```python
rule = """rule du2dele {
pattern {
A [cat="P+D", phon="du"]; N [cat=N];
A -[obj.p]-> N;
}
commands {
add_node D:> A; D.cat=D ; D.phon="le" ;
A.cat=P; A.phon="de";
add_edge N -[det]-> D;
}
}"""
```
......@@ -15,7 +15,8 @@
<hr/>
<li class="section">Use Grew</li>
<li><a href="/install">Install</a></li>
<li><a href="/run">Run</a></li>
<li><a href="/tuto">Run Python library</a></li>
<li><a href="/run">Run command line program</a></li>
<li><a href="/whats">What's new</a></li>
<hr/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment