2017-02-01 22:31:07 +01:00
## batch processing with python-client
There are some client libraries for OpenRefine that communicate with the [OpenRefine API ](https://github.com/OpenRefine/OpenRefine/wiki/OpenRefine-API ). I have prepared a docker container on top of the [Python Library from PaulMakepeace ](https://github.com/PaulMakepeace/refine-client-py/ ) and extended the CLI with some options to create new OpenRefine projects from files.
### basic usage
2017-02-02 12:38:58 +01:00
**1) start server:**
> docker run -d --name=openrefine-server felixlohmeier/openrefine
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**2) run client with one of the following commands:**
2017-02-02 12:23:16 +01:00
2017-02-02 12:38:58 +01:00
list projects:
> docker run --rm --link openrefine-server felixlohmeier/openrefine-client --list
2017-02-01 23:59:13 +01:00
2017-02-02 12:38:58 +01:00
create project from file:
2017-02-02 12:46:31 +01:00
> docker run --rm --link openrefine-server felixlohmeier/openrefine-client --create [FILE]
2017-02-02 12:38:58 +01:00
2017-02-02 13:07:49 +01:00
apply [rules from json file ](http://kb.refinepro.com/2012/06/google-refine-json-and-my-notepad-or.html ):
2017-02-02 12:38:58 +01:00
> docker run --rm --link openrefine-server felixlohmeier/openrefine-client --apply [FILE.json] [PROJECTID]
export project to file:
> docker run --rm --link openrefine-server felixlohmeier/openrefine-client --export [PROJECTID] --output=FILE.tsv
check help screen for more options:
> docker run --rm --link openrefine-server felixlohmeier/openrefine-client --help
**3) cleanup:**
> docker stop openrefine-server && docker rm openrefine-server
2017-02-01 22:31:07 +01:00
### example for customized run commands in interactive mode (e.g. for usage in terminals)
2017-02-02 12:38:58 +01:00
**1) start server in terminal A:**
2017-02-02 01:09:13 +01:00
2017-02-01 23:59:13 +01:00
```docker run --rm --name=openrefine-server -p 80:3333 -v /home/felix/refine:/data:z felixlohmeier/openrefine -i 0.0.0.0 -m 4G -d /data```
2017-02-02 01:09:13 +01:00
2017-02-01 22:31:07 +01:00
* automatically remove docker container when it exits
* set name "openrefine" for docker container
* publish internal port 3333 to host port 80
* mount host directory /home/felix/refine as working directory
* make openrefine available in the network
* increase java heap size to 4 GB
* set refine workspace to /data
* OpenRefine should be available at http://localhost
2017-02-02 12:38:58 +01:00
**2) start client in terminal B (prints help screen):**
2017-02-02 01:09:13 +01:00
2017-02-01 23:59:13 +01:00
```docker run --rm --link openrefine-server -v /home/felix/refine:/data:z felixlohmeier/openrefine-client```
2017-02-02 01:09:13 +01:00
2017-02-01 22:31:07 +01:00
* automatically remove docker container when it exits
* build up network connection with docker container "openrefine"
* mount host directory /home/felix/refine as working directory
* apply history in file /home/felix/refine/history.json to project with id 1234567890123
### example for customized run commands in detached mode (e.g. for usage in shell scripts)
2017-02-02 12:38:58 +01:00
**1) define variables (bring your own example data)**
2017-02-02 01:09:13 +01:00
> workingdir=/home/felix/refine
> inputfile=example.csv
> jsonfile=test.json
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**2) start server**
2017-02-02 01:09:13 +01:00
2017-02-02 11:05:14 +01:00
```docker run -d --name=openrefine-server -v ${workingdir}:/data:z felixlohmeier/openrefine -i 0.0.0.0 -m 4G -d /data```
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**3) create project (import file)**
2017-02-02 01:09:13 +01:00
2017-02-02 12:23:16 +01:00
```docker run --rm --link openrefine-server -v ${workingdir}:/data:z felixlohmeier/openrefine-client --create $inputfile```
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**4) get project id**
2017-02-02 01:09:13 +01:00
2017-02-01 23:59:13 +01:00
```project=($(docker run --rm --link openrefine-server -v ${workingdir}:/data felixlohmeier/openrefine-client --list | cut -c 2-14))```
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**5) apply transformations from json file**
2017-02-02 01:09:13 +01:00
2017-02-02 12:23:16 +01:00
```docker run --rm --link openrefine-server -v ${workingdir}:/data felixlohmeier/openrefine-client --apply ${jsonfile} ${project}```
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**6) export project to file**
2017-02-02 01:09:13 +01:00
2017-02-02 12:23:16 +01:00
```docker run --rm --link openrefine-server -v ${workingdir}:/data felixlohmeier/openrefine-client --export --output=${project}.tsv ${project}```
2017-02-01 22:31:07 +01:00
2017-02-02 12:38:58 +01:00
**7) cleanup**
2017-02-02 01:09:13 +01:00
2017-02-01 23:59:13 +01:00
```docker stop -t=500 openrefine-server & & docker rm openrefine-server```