-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlanguagetool.yml
203 lines (176 loc) · 6.42 KB
/
languagetool.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
---
- hosts: homelab
vars:
application: "languagetool"
languagetool_ngrams:
lang: en
version: "20150817"
checksum: md5:ee56b280af45daf8e68fe0d69dd0914d
docker_network: "{{ networks.pub }}"
handlers:
- name: Restart
community.docker.docker_container:
name: "{{ application }}"
restart: true
comparisons:
'*': ignore
tasks:
- name: Create config folder
ansible.builtin.file:
path: "{{ config_directory }}"
state: directory
owner: "{{ common_user }}"
group: "{{ common_group }}"
mode: "0771"
- name: Create ngrams folder
ansible.builtin.file:
path: "{{ config_directory }}/ngrams"
state: directory
owner: "{{ common_user_id }}"
group: 101
mode: "0771"
- name: Check if ngrams-versions.txt exists
ansible.builtin.stat:
path: "{{ config_directory }}/ngram-version.txt"
register: __ngram_file_stat
- name: Read contents of ngrams-versions.txt if it exists
ansible.builtin.slurp:
src: "{{ config_directory }}/ngram-version.txt"
register: __ngram_version_encoded
- name: Decode and set ngrams_versions variable
ansible.builtin.set_fact:
__ngram_version: "{{ __ngram_version_encoded.content | b64decode }}"
when: __ngram_file_stat.stat.exists
- name: Download ngrams
ansible.builtin.get_url:
url: "https://languagetool.org/download/ngram-data/ngrams-{{ languagetool_ngrams.lang }}-{{ languagetool_ngrams.version }}.zip"
dest: "{{ config_directory }}/ngrams-{{ languagetool_ngrams.lang }}-{{ languagetool_ngrams.version }}.zip"
owner: "{{ common_root_id }}"
group: "{{ common_root_group }}"
mode: "0644"
checksum: "{{ languagetool_ngrams.checksum }}"
register: _ngrams
when: not __ngram_file_stat.stat.exists or
__ngram_version != ("ngrams-" + languagetool_ngrams.lang + "-" + languagetool_ngrams.version)
- name: Unarchive ngrams
ansible.builtin.unarchive:
src: "{{ item.dest }}.zip"
dest: "{{ config_directory }}/ngrams/"
creates: "{{ config_directory }}/ngrams/{{ item.languagetool_ngrams.lang }}"
remote_src: true
loop: "{{ _ngrams.results }}"
when: not __ngram_file_stat.stat.exists or
__ngram_version != ("ngrams-" + languagetool_ngrams.lang + "-" + languagetool_ngrams.version)
- name: Update ngram.txt
ansible.builtin.copy:
content: "ngrams-{{ languagetool_ngrams.lang }}-{{ languagetool_ngrams.version }}"
dest: "{{ config_directory }}/ngram-version.txt"
owner: "{{ common_root_id }}"
group: "{{ common_root_group }}"
mode: "0644"
when: _ngrams.changed
- name: Delete ngrams archive
ansible.builtin.file:
path: "{{ config_directory }}/ngrams-{{ languagetool_ngrams.lang }}-{{ languagetool_ngrams.version }}.zip"
state: absent
- name: Download ngram-lang-detect
ansible.builtin.get_url:
url: "https://languagetool.org/download/ngram-lang-detect/model_ml50_new.zip"
dest: "{{ config_directory }}/ngram-lang-detect.zip"
owner: "{{ common_root_id }}"
group: "{{ common_root_group }}"
mode: "0644"
- name: Create FastText folder
ansible.builtin.file:
path: "{{ config_directory }}/fasttext"
state: directory
owner: "{{ common_user_id }}"
group: 101
mode: "0771"
- name: Download FastText model
ansible.builtin.get_url:
url: https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.bin
dest: "{{ config_directory }}/fasttext/lid.176.bin"
checksum: md5:01810bc59c6a3d2b79c79e6336612f65
mode: "0775"
owner: "{{ common_user_id }}"
group: 101
register: __download_fasttext
- name: Clone FastText binary repo
ansible.builtin.git:
repo: https://github.com/facebookresearch/fastText.git
dest: "{{ config_directory }}/fasttext/fasttext.git"
version: v0.9.2
update: false
become_user: "{{ common_user }}"
become: false
register: __clone_fasttext
- name: Set FastText binary repo permissions
ansible.builtin.file:
path: "{{ config_directory }}/fasttext/fasttext.git"
state: directory
recurse: true
mode: "0775"
owner: "{{ common_user_id }}"
group: 101
- name: Create script to compile FastText
ansible.builtin.copy:
dest: "{{ config_directory }}/fasttext/build.sh"
mode: "755"
content: |
#!/bin/sh
apk add \
build-base \
wget \
git \
unzip \
cd /fasttext/fasttext.git
make
- name: Compile FastText in alpine
community.docker.docker_container:
name: "{{ application }}-fasttext-compiler"
image: alpine:3.21.2
command: /fasttext/build.sh
volumes:
- "{{ config_directory }}/fasttext:/fasttext"
auto_remove: true
cleanup: true
detach: false
# when: __clone_fasttext.changed or __download_fasttext.changed
- name: Set FastText permissions
ansible.builtin.file:
path: "{{ config_directory }}/fasttext/fasttext.git/fasttext"
mode: "0775"
owner: "{{ common_user_id }}"
group: 101
- name: Generate config file
ansible.builtin.copy:
dest: "{{ config_directory }}/config.properties"
mode: "775"
owner: "{{ common_user_id }}"
group: 101
content: |
languageModel=/ngrams
ngramLangIdentData=/ngram-lang-detect.zip
fasttextModel=/fasttext/lid.176.bin
fasttextBinary=/fasttext/fasttext.git/fasttext
premiumAlways=true
notify: Restart
- name: Create container
ansible.builtin.include_role:
name: docker_container
vars:
image: silviof/docker-languagetool:6.5
cap_drop:
- ALL
env:
EXTRAOPTIONS: "-Xmx2g -Xms1g"
volumes:
- "{{ config_directory }}/ngrams/:/ngrams"
- "{{ config_directory }}/config.properties:/LanguageTool/config.properties"
- "{{ config_directory }}/fasttext:/fasttext"
- "{{ config_directory }}/ngram-lang-detect.zip:/ngram-lang-detect.zip"
traefik:
- port: 8010
blackbox:
path: /v2/languages