-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang_db_generator.pl
180 lines (147 loc) · 6.21 KB
/
lang_db_generator.pl
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
%% lang_db_generator(Target_language)
%% New repository, with dbs in each rep
:- include('../culturaltranslationtool/ctt2.pl').
%:- include('../culturaltranslationtool/edit.pl').
:- include('../listprologinterpreter/la_strings').
:- include('translate4.pl').
:- dynamic lang_db/1.
%% List_of_words may be list of words to translate and add or an original language code
% lang_db_generator([["a","a"],["b","b exp"]],["fr"]). - create the db
% lang_db_generator("fr",["de"]). - add de with same entries as fr
% lang_db_generator("fr",["ab"]). - add ab "
% Alternatively, lang_db_generator("fr",["de","ab"]). instead of last two lines
load_lang_db1(Entry3) :-
% if l.o.w. is orig lang, read from it instead
directory_files("../listprologinterpreter/languages/",F),
delete_invisibles_etc(F,G),
findall(Entry2,(member(Filex1,G),
string_concat("../listprologinterpreter/languages/",Filex1,Filex),
phrase_from_file_s(string(String00a), Filex),
string_codes(String02b,String00a),
atom_to_term(String02b,String02a,[]),
string_concat(Target_language3,".txt",Filex),
string_concat("../listprologinterpreter/languages/",Target_language2,Target_language3),
findall([En_word,En_word2,Target_language2,T_word],(member(Entry,String02a),((Entry=[En_word,En_word2,Target_language2,T_word],string(En_word),string(En_word2),string(T_word))->true;(concat_list(["Error: File: ",Filex,", Entry: ",Entry," not in format [\"<En_word>\",\"<En_word2>\",\"<Target_language2>\",\"<T_word>\"]."],Notification1),writeln(Notification1),abort))),Entry2)
),Entry2a),
maplist(append,[Entry2a],[Entry3]).
lang_db_generator(List_of_words,Target_language1) :-
load_lang_db1(Entry3),
%%(not(member([_,Target_language1,_],Entry3))->
(string(List_of_words)->
(findall([Word1,Word2],(member([Word1,Word2,List_of_words,_],Entry3)),List_of_words2),List_of_words3=[]);
(findall([Word1,Word2,List_of_words,Item_a],(member([Word1,Word2,List_of_words,Item_a],Entry3)),List_of_words3), %%** test
findall(_,(member([Word,Word2],List_of_words),(string(Word),string(Word2))->true;(concat_list(["Error: Word1: ",Word," or Word2: ",Word2," in list of words not in format [\"<Word1>\",\"<Word2>\"]."],Notification1),writeln(Notification1),abort)),_)),List_of_words=List_of_words2),
%% list of langs to put words into
findall(_,(member(Target_language10,Target_language1),
(string(Target_language10)->true;(concat_list(["Error: Target_language1: ",Target_language1," not in format \"<Target_language1>\"."],Notification1),writeln(Notification1),abort)),
%split_on_number(Target_language10,Target_language101,_),
%trace,
findall([Input,Input1,Target_language10,Output3],(
member([Input,Input1],List_of_words2),
(Target_language10="en2"->Output3=Input1;translate(Input1,"en",Target_language10,Output3))),Output4),
%% save file
%% ** add to prev file
%% ** keep metaphorical translations (x bt xx with simplified ctt (no bt-trans dict) and customised output)
%% numbers after command names
%% - check words on google translate, ctt speeds bt
append(List_of_words3,Output4,Output4a), %% ** test
concat_list(["../listprologinterpreter/languages/",Target_language10,".txt"],File1),
term_to_atom(Output4a,File_contents),open_s(File1,write,Stream),write(Stream,File_contents),close(Stream)),_).
delete_invisibles_etc(F,G) :-
findall(J,(member(H,F),atom_string(H,J),not(J="."),not(J=".."),not(string_concat(".",_,J))),G).
% test with t=w+1
translate1(Input,From_l,Target_language1,Output3) :-
concat_list([Input," ",From_l," ",Target_language1],Output3).
load_lang_db :-
%% error if lang not found
load_lang_db1(Entry3),
lang(Lang),
(Lang="en"->true;
(member([_,_,Lang,_],Entry3)->true;
(concat_list(["Error: Language: ",Lang," not in listprologinterpreter/languages folder."],Notification1),writeln(Notification1),abort))),
retractall(lang_db(_)),
assertz(lang_db(Entry3)),!.
get_lang_word(Input,Output) :-
%% error if word not found
(not(lang(Lang))->(Lang="en");lang(Lang)),
%lang_db(Lang_db),
(not(lang_db(Lang_db))->(load_lang_db,lang_db(Lang_db));lang_db(Lang_db)),
(Lang="en"->%Input=Output1,
atom_string(Output,Input);
((%(%((Input="member2"->trace;true),
split_on_number(Input,Input1,Input10),member([Input1,_Input101,Lang,Output2],Lang_db),
%notrace,
(Input10="" -> Output=Output2;
concat_list([Output2," ",Input10],Output))) -> true;
(concat_list(["Error: Word: ",Input," not in Language: ",Lang," in lang_db."],Notification1),writeln(Notification1),abort))),
%Output=Output1,
!.
%atom_string(Output,Output1),!.
%split_on_number(Input,Input1,Input10) :-
%findall([Input1,Input10],split_on_number1(Input,Input1,Input10),Output1),
%reverse(Output1,[[Input1,Input10]|_]).
split_on_number(Input,Input1,Input10) :-
string_concat(A,B,Input),
string_concat(C,D,B),
string_length(C,1),
((C=" ",
string_concat(E,F,D),
string_concat(J,K,E),
string_length(K,1),
K=" ",
string_concat(G,_H,F),
%trace,
string_length(G,1),
(number_string(_,G)),%->true;not(G=" ")),
%((
%C=" ",
%)->(
concat_list([A,C,J],Input1),
%Input1=A,
Input10=F))%->true;
%(number_string(_,C),
%Input1=A,Input10=B))
,!.%);
split_on_number(Input,Input1,Input10) :-
string_concat(A,B,Input),
string_concat(C,D,B),
string_length(C,1),
((C=" ",
string_concat(_E,F,D),
string_concat(G,_H,F),
%trace,
string_length(G,1),
(number_string(_,G)),%->true;not(G=" ")),
%((
%C=" ",
%)->(
%concat_list([A,C,J],Input1),
Input1=A,
Input10=F)->true;
(number_string(_,C),
Input1=A,Input10=B))
,!.%);
split_on_number(Input,Input1,Input10) :-
Input1=Input,Input10="".
replace(A,Find,Replace,F) :-
split_string(A,Find,Find,B),findall([C,Replace],(member(C,B)),D),maplist(append,[D],[E]),concat_list(E,F),!.
% stringconcat-> in both algs above
% concatenate strings v
/**
% membre 2->member2
get_en_lang_word(Input,Output) :-
%% error if word not found
lang(Lang),
lang_db(Lang_db),
(Lang="en"->%Input=Output1,
atom_string(Input,Output);
((%(%((Input="member2"->trace;true),
%split_on_number(Input,Input1,Input10),
member([Output,_Input101,Lang,Input],Lang_db))->true;
%notrace,
%(%Input10="" -> Output=Output2;
%concat_list([Output2," ",Input10],Output))) -> true;
(concat_list(["Error: Word: ",Input," not in Language: ",Lang," in lang_db."],Notification1),writeln(Notification1),abort))),
%Output=Output1,
!.
**/