Skip to content
Snippets Groups Projects
Commit 3528a818 authored by Jakob Moser's avatar Jakob Moser
Browse files

Receive input via base64 encoded JSON

Drop reading grammar from input, because we'd never use it anyway
parent c9da3dce
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ WORKDIR /workdir
# Install dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
jq \
xvfb \
&& rm -rf /var/lib/apt/lists/*
......
......@@ -26,7 +26,9 @@ To parse a sentence using xle-docker, you need two things:
You can then execute the following command:
```bash
sudo docker run -i xle "in der Arena veranstalten die Ritter ein Turnier ." < /home/mustermann/grammatik.lfg
sudo docker run \
--mount type=bind,source=/home/mustermann/grammatik.lfg,target=/grammar.lfg \
xle "in der Arena veranstalten die Ritter ein Turnier ."
```
This will take a few seconds. The parses will then be output to the command line using XLE's own XML export format. If you want to store the output in a file, append `> name_of_your_file.xml` at the end of the command.
......@@ -38,15 +40,21 @@ Note that the `xle` specified in the `docker run` command is the name of the tag
</details>
<details>
<summary>Alternative using mounts</summary>
<summary>Alternative using a Base64-encoded JSON</summary>
If you don't want to use mounts, you can also create a JSON file that contains the attributes `sentence` and `grammar`, like this (shortened version, we just want to illustrate how to deal with newlines):
```json
{"sentence":"in der Arena veranstalten die Ritter ein Turnier", "grammar":"DEMO GERMAN CONFIG (1.0)\n ROOTCAT IP.\n LEXENTRIES (DEMO GERMAN).\n RULES (DEMO GERMAN).\n GOVERNABLERELATIONS SUBJ OBJ OBJ-TH OBL-TH.\n SEMANTICFUNCTIONS ADJ.\n NONDISTRIBUTIVES NUM PERS GEND.\n----\n\nDEMO GERMAN RULES (1.0)\n\nIP --> NP: (^ SUBJ) = !;\n I'\n (PUNCT).\n\nNP --> { Det N | NP PP: ! $ (^ ADJ); }.\n\nI' --> I VP.\n\n..."}
```
The container also allows the Grammar file to be mounted as `/grammar.lfg`, if this is more useful for your specific use case:
Store the file as `data.json`. You can then run the container like this:
```bash
sudo docker run \
--mount type=bind,source=/home/mustermann/grammatik.lfg,target=/grammar.lfg \
xle "in der Arena veranstalten die Ritter ein Turnier ."
sudo docker container run xle $(cat data.json | base64 -w0)
```
The idea to implement it that way came from [Christian Heusel](https://christian.heusel.eu/), thank you very much!
</details>
## :page_with_curl: About
......
......@@ -2,19 +2,22 @@
#
# Entrypoint for the xle Docker image.
#
# You need to provide the following information:
# 1. A sentence to parse as first (and only) command line argument ($1)
# 2. A grammar to parse with. The grammar is searched first at /grammar.lfg. If no such file exists, the grammar is read from stdin.
# XLE needs a sentence and a grammar. You can use either of the following two ways to provide them to an xle container:
# 1) Mount grammar as /grammar.lfg, pass sentence as first and only command line argument ($1)
# 2) Pass a base64-encoded JSON containing the attributes "sentence" and "grammar" as first and only command line argument ($1)
if [[ ! -f /grammar.lfg ]]
then
# Use "cat" to read everything stdin has to offer and then use Bash to write it to a file
cat > /grammar.lfg
JSON=$(echo $1 | base64 -d)
SENTENCE=$(echo $JSON | jq -r .sentence)
echo $JSON | jq -r .grammar > /grammar.lfg
else
SENTENCE=$1
fi
# Write xlerc containing instructions to parse
echo "create-parser /grammar.lfg" > xlerc
echo "packed-xml-fs { $1 } packed-parses.xml" >> xlerc
echo "packed-xml-fs { $SENTENCE } packed-parses.xml" >> xlerc
echo "exit" >> xlerc
# Start XLE (under the X server), this will automatically load xlerc, let it complete the parse and end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment