Christian Fraß commited on 2017-03-19 21:20:53
Zeige 10 geänderte Dateien mit 359 Einfügungen und 138 Löschungen.
... | ... |
@@ -0,0 +1,61 @@ |
1 |
+select |
|
2 |
+ `x6`.`lemma` as `lemma`, |
|
3 |
+ `x7`.`iso_639_2` as `language` |
|
4 |
+from |
|
5 |
+ ( |
|
6 |
+ ( |
|
7 |
+ select |
|
8 |
+ `x4`.`tag` as `tag`, |
|
9 |
+ `x5`.`lemma` as `lemma`, |
|
10 |
+ `x5`.`language_id` as `language_id` |
|
11 |
+ from |
|
12 |
+ ( |
|
13 |
+ ( |
|
14 |
+ select |
|
15 |
+ `x2`.`tag` as `tag`, |
|
16 |
+ `x3`.`word_id` as `word_id` |
|
17 |
+ from |
|
18 |
+ ( |
|
19 |
+ ( |
|
20 |
+ select |
|
21 |
+ `x0`.`id` as `concept_id`, |
|
22 |
+ `x0`.`tag` as `tag` |
|
23 |
+ from |
|
24 |
+ ( |
|
25 |
+ `tags` as `x0` |
|
26 |
+ inner join |
|
27 |
+ `concepts` as `x1` |
|
28 |
+ on |
|
29 |
+ (`x0`.`concept_id` = `x1`.`id`) |
|
30 |
+ ) |
|
31 |
+ ) as `x2` |
|
32 |
+ inner join |
|
33 |
+ `correlations` as `x3` |
|
34 |
+ on |
|
35 |
+ (`x2`.`concept_id` = `x3`.`concept_id`) |
|
36 |
+ ) |
|
37 |
+ ) as `x4` |
|
38 |
+ inner join |
|
39 |
+ `words` as `x5` |
|
40 |
+ on |
|
41 |
+ (`x4`.`word_id` = `x5`.`id`) |
|
42 |
+ ) |
|
43 |
+ ) as `x6` |
|
44 |
+ inner join |
|
45 |
+ `languages` as `x7` |
|
46 |
+ on |
|
47 |
+ (`x6`.`language_id` = `x7`.`id`) |
|
48 |
+ ) |
|
49 |
+where |
|
50 |
+ ( |
|
51 |
+ (`tag` = :tag) |
|
52 |
+ and |
|
53 |
+ ( |
|
54 |
+ (:language is null) |
|
55 |
+ or |
|
56 |
+ (`x7`.`iso_639_1` = :language) |
|
57 |
+ or |
|
58 |
+ (`x7`.`iso_639_2` = :language) |
|
59 |
+ ) |
|
60 |
+ ) |
|
61 |
+; |
... | ... |
@@ -0,0 +1,30 @@ |
1 |
+select |
|
2 |
+ `x2`.`id` as `id`, |
|
3 |
+ `x2`.`description` as `description`, |
|
4 |
+ `x2`.`tags` as `tags`, |
|
5 |
+ `x3`.`word_id` as `word_id` |
|
6 |
+from |
|
7 |
+ ( |
|
8 |
+ ( |
|
9 |
+ select |
|
10 |
+ `x0`.`id` as `id`, |
|
11 |
+ `x0`.`description` as `description`, |
|
12 |
+ group_concat(`x1`.`tag`) as `tags` |
|
13 |
+ from |
|
14 |
+ ( |
|
15 |
+ `concepts` as `x0` |
|
16 |
+ inner join |
|
17 |
+ `tags` as `x1` |
|
18 |
+ on |
|
19 |
+ (`x0`.`id` = `x1`.`concept_id`) |
|
20 |
+ ) |
|
21 |
+ group by |
|
22 |
+ `x0`.`id` |
|
23 |
+ ) as `x2` |
|
24 |
+ inner join |
|
25 |
+ `correlations` as `x3` |
|
26 |
+ on |
|
27 |
+ (`x2`.`id` = `x3`.`concept_id`) |
|
28 |
+ ) |
|
29 |
+; |
|
30 |
+ |
... | ... |
@@ -1,125 +0,0 @@ |
1 |
-SELECT |
|
2 |
- x.word_id AS from_word_id, |
|
3 |
- x.language AS from_language, |
|
4 |
- x.lemma AS from_lemma, |
|
5 |
- x.pronunciation AS from_pronunciation, |
|
6 |
- x.concept_id AS from_concept_id, |
|
7 |
- x.strength AS from_strength, |
|
8 |
- y.word_id AS to_word_id, |
|
9 |
- y.language AS to_language, |
|
10 |
- y.lemma AS to_lemma, |
|
11 |
- y.pronunciation AS to_pronunciation, |
|
12 |
- y.concept_id AS to_concept_id, |
|
13 |
- y.strength AS to_strength |
|
14 |
-FROM |
|
15 |
- ( |
|
16 |
- ( |
|
17 |
- SELECT |
|
18 |
- x3.word_id AS word_id, |
|
19 |
- x3.language AS language, |
|
20 |
- x3.lemma AS lemma, |
|
21 |
- x3.pronunciation AS pronunciation, |
|
22 |
- x4.concept_id AS concept_id, |
|
23 |
- x4.strength AS strength |
|
24 |
- FROM |
|
25 |
- ( |
|
26 |
- ( |
|
27 |
- SELECT |
|
28 |
- x2.id AS word_id, |
|
29 |
- x1.iso_639_2 AS language, |
|
30 |
- x2.lemma AS lemma, |
|
31 |
- x2.pronunciation AS pronunciation |
|
32 |
- FROM |
|
33 |
- ( |
|
34 |
- ( |
|
35 |
- SELECT |
|
36 |
- id, |
|
37 |
- iso_639_2 |
|
38 |
- FROM |
|
39 |
- languages |
|
40 |
- ) AS x1 |
|
41 |
- INNER JOIN |
|
42 |
- ( |
|
43 |
- SELECT |
|
44 |
- id, |
|
45 |
- language_id, |
|
46 |
- lemma, |
|
47 |
- pronunciation |
|
48 |
- FROM |
|
49 |
- words |
|
50 |
- ) AS x2 |
|
51 |
- ON |
|
52 |
- (x1.id = x2.language_id) |
|
53 |
- ) |
|
54 |
- ) AS x3 |
|
55 |
- INNER JOIN |
|
56 |
- correlations AS x4 |
|
57 |
- ON |
|
58 |
- (x3.word_id = x4.word_id) |
|
59 |
- ) |
|
60 |
- ) AS x |
|
61 |
- INNER JOIN |
|
62 |
- ( |
|
63 |
- SELECT |
|
64 |
- y3.word_id AS word_id, |
|
65 |
- y3.language AS language, |
|
66 |
- y3.lemma AS lemma, |
|
67 |
- y3.pronunciation AS pronunciation, |
|
68 |
- y4.concept_id AS concept_id, |
|
69 |
- y4.strength AS strength |
|
70 |
- FROM |
|
71 |
- ( |
|
72 |
- ( |
|
73 |
- SELECT |
|
74 |
- y2.id AS word_id, |
|
75 |
- y1.iso_639_2 AS language, |
|
76 |
- y2.lemma AS lemma, |
|
77 |
- y2.pronunciation AS pronunciation |
|
78 |
- FROM |
|
79 |
- ( |
|
80 |
- ( |
|
81 |
- SELECT |
|
82 |
- id, |
|
83 |
- iso_639_2 |
|
84 |
- FROM |
|
85 |
- languages |
|
86 |
- ) AS y1 |
|
87 |
- INNER JOIN |
|
88 |
- ( |
|
89 |
- SELECT |
|
90 |
- id, |
|
91 |
- language_id, |
|
92 |
- lemma, |
|
93 |
- pronunciation |
|
94 |
- FROM |
|
95 |
- words |
|
96 |
- ) AS y2 |
|
97 |
- ON |
|
98 |
- (y1.id = y2.language_id) |
|
99 |
- ) |
|
100 |
- ) AS y3 |
|
101 |
- INNER JOIN |
|
102 |
- correlations AS y4 |
|
103 |
- ON |
|
104 |
- (y3.word_id = y4.word_id) |
|
105 |
- ) |
|
106 |
- ) AS y |
|
107 |
- ON |
|
108 |
- (x.concept_id = y.concept_id) |
|
109 |
- ) |
|
110 |
-WHERE |
|
111 |
- ( |
|
112 |
- ( |
|
113 |
- (from_language = '${language}') |
|
114 |
- AND |
|
115 |
- (from_lemma LIKE '%${lemma}%') |
|
116 |
- ) |
|
117 |
- AND |
|
118 |
- NOT ( |
|
119 |
- (from_language = to_language) |
|
120 |
- AND |
|
121 |
- (from_lemma = to_lemma) |
|
122 |
- ) |
|
123 |
- ) |
|
124 |
-; |
|
125 |
- |
... | ... |
@@ -0,0 +1,137 @@ |
1 |
+select |
|
2 |
+ `x`.`language_iso_639_2` as `from_language`, |
|
3 |
+ `x`.`lemma` as `from_lemma`, |
|
4 |
+ `x`.`pronunciation` as `from_pronunciation`, |
|
5 |
+ `x`.`strength` as `from_strength`, |
|
6 |
+ `y`.`language_iso_639_2` as `to_language`, |
|
7 |
+ `y`.`lemma` as `to_lemma`, |
|
8 |
+ `y`.`pronunciation` as `to_pronunciation`, |
|
9 |
+ `y`.`strength` as `to_strength` |
|
10 |
+from |
|
11 |
+ ( |
|
12 |
+ ( |
|
13 |
+ select |
|
14 |
+ `x3`.`word_id` as `word_id`, |
|
15 |
+ `x3`.`language_iso_639_1` as `language_iso_639_1`, |
|
16 |
+ `x3`.`language_iso_639_2` as `language_iso_639_2`, |
|
17 |
+ `x3`.`lemma` as `lemma`, |
|
18 |
+ `x3`.`pronunciation` as `pronunciation`, |
|
19 |
+ `x4`.`concept_id` as `concept_id`, |
|
20 |
+ `x4`.`strength` as `strength` |
|
21 |
+ from |
|
22 |
+ ( |
|
23 |
+ ( |
|
24 |
+ select |
|
25 |
+ `x2`.`id` as `word_id`, |
|
26 |
+ `x1`.`iso_639_1` as `language_iso_639_1`, |
|
27 |
+ `x1`.`iso_639_2` as `language_iso_639_2`, |
|
28 |
+ `x2`.`lemma` as `lemma`, |
|
29 |
+ `x2`.`pronunciation` as `pronunciation` |
|
30 |
+ from |
|
31 |
+ ( |
|
32 |
+ ( |
|
33 |
+ select |
|
34 |
+ `id`, |
|
35 |
+ `iso_639_1`, |
|
36 |
+ `iso_639_2` |
|
37 |
+ from |
|
38 |
+ `languages` |
|
39 |
+ ) as `x1` |
|
40 |
+ inner join |
|
41 |
+ ( |
|
42 |
+ select |
|
43 |
+ `id`, |
|
44 |
+ `language_id`, |
|
45 |
+ `lemma`, |
|
46 |
+ `pronunciation` |
|
47 |
+ from |
|
48 |
+ `words` |
|
49 |
+ ) as `x2` |
|
50 |
+ on |
|
51 |
+ (`x1`.`id` = `x2`.`language_id`) |
|
52 |
+ ) |
|
53 |
+ ) as `x3` |
|
54 |
+ inner join |
|
55 |
+ `correlations` as `x4` |
|
56 |
+ on |
|
57 |
+ (`x3`.`word_id` = `x4`.`word_id`) |
|
58 |
+ ) |
|
59 |
+ ) as x |
|
60 |
+ inner join |
|
61 |
+ ( |
|
62 |
+ select |
|
63 |
+ `y3`.`word_id` as `word_id`, |
|
64 |
+ `y3`.`language_iso_639_1` as `language_iso_639_1`, |
|
65 |
+ `y3`.`language_iso_639_2` as `language_iso_639_2`, |
|
66 |
+ `y3`.`lemma` as `lemma`, |
|
67 |
+ `y3`.`pronunciation` as `pronunciation`, |
|
68 |
+ `y4`.`concept_id` as `concept_id`, |
|
69 |
+ `y4`.`strength` as `strength` |
|
70 |
+ from |
|
71 |
+ ( |
|
72 |
+ ( |
|
73 |
+ select |
|
74 |
+ `y2`.`id` as `word_id`, |
|
75 |
+ `y1`.`iso_639_1` as `language_iso_639_1`, |
|
76 |
+ `y1`.`iso_639_2` as `language_iso_639_2`, |
|
77 |
+ `y2`.`lemma` as `lemma`, |
|
78 |
+ `y2`.`pronunciation` as `pronunciation` |
|
79 |
+ from |
|
80 |
+ ( |
|
81 |
+ ( |
|
82 |
+ select |
|
83 |
+ `id`, |
|
84 |
+ `iso_639_1`, |
|
85 |
+ `iso_639_2` |
|
86 |
+ from |
|
87 |
+ `languages` |
|
88 |
+ ) as `y1` |
|
89 |
+ inner join |
|
90 |
+ ( |
|
91 |
+ select |
|
92 |
+ `id`, |
|
93 |
+ `language_id`, |
|
94 |
+ `lemma`, |
|
95 |
+ `pronunciation` |
|
96 |
+ from |
|
97 |
+ `words` |
|
98 |
+ ) as `y2` |
|
99 |
+ on |
|
100 |
+ (`y1`.`id` = `y2`.`language_id`) |
|
101 |
+ ) |
|
102 |
+ ) as `y3` |
|
103 |
+ inner join |
|
104 |
+ `correlations` as `y4` |
|
105 |
+ on |
|
106 |
+ (`y3`.`word_id` = `y4`.`word_id`) |
|
107 |
+ ) |
|
108 |
+ ) as `y` |
|
109 |
+ on |
|
110 |
+ (`x`.`concept_id` = `y`.`concept_id`) |
|
111 |
+ ) |
|
112 |
+where |
|
113 |
+ ( |
|
114 |
+ ( |
|
115 |
+ (`x`.`language_iso_639_1` = :from_language) |
|
116 |
+ or |
|
117 |
+ (`x`.`language_iso_639_2` = :from_language) |
|
118 |
+ ) |
|
119 |
+ and |
|
120 |
+ (`from_lemma` like ('%' || :from_lemma || '%')) |
|
121 |
+ and |
|
122 |
+ ( |
|
123 |
+ (:to_language is null) |
|
124 |
+ or |
|
125 |
+ (`y`.`language_iso_639_1` = :to_language) |
|
126 |
+ or |
|
127 |
+ (`y`.`language_iso_639_2` = :to_language) |
|
128 |
+ ) |
|
129 |
+ and |
|
130 |
+ not ( |
|
131 |
+ (`x`.`language_iso_639_2` = `y`.`language_iso_639_2`) |
|
132 |
+ and |
|
133 |
+ (`x`.`lemma` = `y`.`lemma`) |
|
134 |
+ ) |
|
135 |
+ ) |
|
136 |
+; |
|
137 |
+ |
... | ... |
@@ -0,0 +1,29 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+ |
|
3 |
+import sys as _sys |
|
4 |
+ |
|
5 |
+from helpers import * |
|
6 |
+ |
|
7 |
+ |
|
8 |
+def error_syntax(): |
|
9 |
+ print("SYNTAX: translate.py <language> <lemma>") |
|
10 |
+ _sys.exit(-1) |
|
11 |
+ |
|
12 |
+ |
|
13 |
+def main(args): |
|
14 |
+ tag = (error_syntax() if (len(args) < 1) else args.pop(0)) |
|
15 |
+ language = (None if (len(args) < 1) else args.pop(0)) |
|
16 |
+ macro( |
|
17 |
+ "associate", |
|
18 |
+ { |
|
19 |
+ "tag": tag, |
|
20 |
+ "language": language, |
|
21 |
+ }, |
|
22 |
+ ( |
|
23 |
+ "lemma", |
|
24 |
+ "language", |
|
25 |
+ ) |
|
26 |
+ ) |
|
27 |
+ |
|
28 |
+main(_sys.argv[1:]) |
|
29 |
+ |
... | ... |
@@ -0,0 +1,32 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+ |
|
3 |
+import sys as _sys |
|
4 |
+ |
|
5 |
+from helpers import * |
|
6 |
+ |
|
7 |
+ |
|
8 |
+def error_syntax(): |
|
9 |
+ print("SYNTAX: dictionary.py <from-language> <to-language>") |
|
10 |
+ _sys.exit(-1) |
|
11 |
+ |
|
12 |
+ |
|
13 |
+def main(args): |
|
14 |
+ from_language = (error_syntax() if (len(args) < 1) else args.pop(0)) |
|
15 |
+ to_language = (error_syntax() if (len(args) < 1) else args.pop(0)) |
|
16 |
+ macro( |
|
17 |
+ "dictionary", |
|
18 |
+ { |
|
19 |
+ "from_language": from_language, |
|
20 |
+ "to_language": to_language, |
|
21 |
+ }, |
|
22 |
+ ( |
|
23 |
+ "id", |
|
24 |
+ "description", |
|
25 |
+ "tags", |
|
26 |
+ "word_id", |
|
27 |
+ ) |
|
28 |
+ ) |
|
29 |
+ |
|
30 |
+ |
|
31 |
+main(_sys.argv[1:]) |
|
32 |
+ |
... | ... |
@@ -0,0 +1,31 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+ |
|
3 |
+import os as _os |
|
4 |
+import sqlite3 as _sqlite3 |
|
5 |
+import json as _json |
|
6 |
+ |
|
7 |
+ |
|
8 |
+def pattern(content): |
|
9 |
+ return ("%%%s%%" % content) |
|
10 |
+ |
|
11 |
+ |
|
12 |
+def transform(entries, names): |
|
13 |
+ # return entries |
|
14 |
+ return list(map(lambda entry: dict(zip(names, entry)), entries)) |
|
15 |
+ |
|
16 |
+ |
|
17 |
+def query(name, arguments = {}): |
|
18 |
+ path = _os.path.join("queries", "%s.sql.tpl" % name) |
|
19 |
+ handle = open(path, "r") |
|
20 |
+ querytemplate = handle.read() |
|
21 |
+ handle.close() |
|
22 |
+ connection = _sqlite3.connect(_os.path.join("db", "words.sqlite")) |
|
23 |
+ result = connection.cursor().execute(querytemplate, arguments).fetchall() |
|
24 |
+ connection.close() |
|
25 |
+ return result |
|
26 |
+ |
|
27 |
+ |
|
28 |
+def macro(query_name, query_arguments, transform_names): |
|
29 |
+ print(_json.dumps(transform(query(query_name, query_arguments), transform_names), indent = "\t")) |
|
30 |
+ |
|
31 |
+ |
... | ... |
@@ -0,0 +1,38 @@ |
1 |
+#!/usr/bin/env python3 |
|
2 |
+ |
|
3 |
+import sys as _sys |
|
4 |
+ |
|
5 |
+from helpers import * |
|
6 |
+ |
|
7 |
+ |
|
8 |
+def error_syntax(): |
|
9 |
+ print("SYNTAX: translate.py <from-language> <from-lemma> [<to-language>]") |
|
10 |
+ _sys.exit(-1) |
|
11 |
+ |
|
12 |
+ |
|
13 |
+def main(args): |
|
14 |
+ from_language = (error_syntax() if (len(args) < 1) else args.pop(0)) |
|
15 |
+ from_lemma = (error_syntax() if (len(args) < 1) else args.pop(0)) |
|
16 |
+ to_language = (None if (len(args) < 1) else args.pop(0)) |
|
17 |
+ macro( |
|
18 |
+ "translate", |
|
19 |
+ { |
|
20 |
+ "from_language": from_language, |
|
21 |
+ "from_lemma": from_lemma, |
|
22 |
+ "to_language": to_language, |
|
23 |
+ }, |
|
24 |
+ ( |
|
25 |
+ "from_language", |
|
26 |
+ "from_lemma", |
|
27 |
+ "from_pronunciation", |
|
28 |
+ "from_strength", |
|
29 |
+ "to_language", |
|
30 |
+ "to_lemma", |
|
31 |
+ "to_pronunciation", |
|
32 |
+ "to_strength", |
|
33 |
+ ) |
|
34 |
+ ) |
|
35 |
+ |
|
36 |
+ |
|
37 |
+main(_sys.argv[1:]) |
|
38 |
+ |
... | ... |
@@ -1,11 +0,0 @@ |
1 |
-#!/usr/bin/env sh |
|
2 |
- |
|
3 |
-if [ "$#" -ge 1 ] ; then language=$1 && shift ; else language="*" ; fi |
|
4 |
-if [ "$#" -ge 1 ] ; then lemma=$1 && shift ; else lemma="*" ; fi |
|
5 |
- |
|
6 |
-cat queries/translate.sql \ |
|
7 |
- | sed --expression="s:\${language}:${language}:g" \ |
|
8 |
- | sed --expression="s:\${lemma}:${lemma}:g" \ |
|
9 |
- | sqlite3 db/words.sqlite \ |
|
10 |
- | cat - |
|
11 |
- |
|
12 | 0 |