blob: 8f37955a9353c5790f12a830c40e0df7710be3c9 [file] [log] [blame]
Harald Lungen7a0e6742024-08-23 09:32:02 +03001BEGIN {
2 OFS="\t";
3
4 OUTDIR="XML";
5 system("mkdir -p \"" OUTDIR "\"");
6
7 CONTAIN["Aamulehti"] = 1;
8 CONTAIN["Etelä-Suomen Sanomat"] = 1;
Harald Lungen7a0e6742024-08-23 09:32:02 +03009 CONTAIN["Hämeen Sanomat"] = 1;
10 CONTAIN["Helsingin Sanomat"] = 1;
11 CONTAIN["Ilkka-Pohjalainen"] = 1;
12 CONTAIN["Ilta-Sanomat"] = 1;
13 CONTAIN["Iltalehti"] = 1;
14 CONTAIN["Kaleva"] = 1;
15 CONTAIN["Karjalainen"] = 1;
16 CONTAIN["Kauppalehti"] = 1;
17 CONTAIN["Keskipohjanmaa"] = 1;
18 CONTAIN["Keskisuomalainen"] = 1;
19 CONTAIN["Kouvolan Sanomat"] = 1;
20 CONTAIN["Kymen Sanomat"] = 1;
21 CONTAIN["Länsi-Savo"] = 1;
22 CONTAIN["Lapin Kansa"] = 1;
23 CONTAIN["Satakunnan Kansa"] = 1;
24 CONTAIN["Savon Sanomat"] = 1;
25 CONTAIN["Suomen Kuvalehti"] = 1;
26 CONTAIN["Turun Sanomat"] = 1;
27
28
29 for(c in CONTAIN){
30 OUTFILE = OUTDIR "/" simplify(c) ".xml";
31 printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") > OUTFILE;
32 printf("<texts>\n") >> OUTFILE;
33 print OUTFILE > "/dev/stderr";
34 }
35}
36
37
38
39/^\s*<\!\-\-/ { print; } # positional attributes
40
41/^\s*<text/ {
42
43# USE 01 binding_id="2246025"
44 BID = gensub(/^.+binding_id=\"([^\"]+?)\".+$/, "\\1", "1", $0);
45# USE 02 date="2021-01-15"
46 DATE = gensub(/^.+date=\"([^\"]+?)\".+$/, "\\1", "1", $0);
47# 03 datefrom="20210115"
48# 04 dateto="20210115"
49# 05 elec_date="_"
50# 06 file=""
51# USE 07 filename_metadata="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_mets.xml"
52 METAFILENAME = gensub(/^.+filename_metadata=\"([^\"]+?)\".+$/, "\\1", "1", $0);
53# USE 08 filename_orig="finclarin_siirto_k2021/0039-5552/2021/alto/2246025_0039-5552_2021-01-15_SK0221_page-2021011502210030301.xml
54 ORIGFILENAME = gensub(/^.+filename_orig=\"([^\"]+?)\".+$/, "\\1", "1", $0);
55# USE 09 id="t-bcd0f3fa-bbd3dac4"
56 ID = gensub(/^.+id=\"([^\"]+?)\".+$/, "\\1", "1", $0);
57# 10 img_url=""
58# USE 11 issue_date="15.01.2021"
59 ISSUEDATE = gensub(/^.+issue_date=\"([^\"]+?)\".+$/, "\\1", "1", $0);
60# USE 12 issue_no="SK0221"
61 ISSUENO = gensub(/^.+issue_no=\"([^\"]+?)\".+$/, "\\1", "1", $0);
62# USE 13 issue_title="Suomen Kuvalehti"
63 ISSUETITLE = gensub(/^.+issue_title=\"([^\"]+?)\".+$/, "\\1", "1", $0);
64# USE 14 label="Suomen Kuvalehti no. SK0221 15.01.2021"
65 LABEL = gensub(/^.+label=\"([^\"]+?)\".+$/, "\\1", "1", $0);
66# USE 16 language="fi"
67 LANGUAGE = gensub(/^.+language=\"([^\"]+?)\".+$/, "\\1", "1", $0);
68# USE 17 page_id="p1"
69 PAGEID = gensub(/^.+page_id=\"([^\"]+?)\".+$/, "\\1", "1", $0);
70# USE 18 page_no="None"
71 PAGENO = gensub(/^.+page_no=\"([^\"]+?)\".+$/, "\\1", "1", $0);
72# 19 part_name="_"
73# 20 publ_id="0039-5552"
74# 21 publ_part=""
75# USE 22 publ_title="Suomen Kuvalehti"
76 PUBLTITLE = gensub(/^.+publ_title=\"([^\"]+?)\".+$/, "\\1", "1", $0);
77# USE 23 publ_type="aikakausi"
78 PUBLTYPE = gensub(/^.+publ_type=\"([^\"]+?)\".+$/, "\\1", "1", $0);
79# USE 24 sentcount="70"
80 SENTCOUNT = gensub(/^.+sentcount=\"([^\"]+?)\".+$/, "\\1", "1", $0);
81# 25 sum_lang="|xxx:44|fin:23|eng:3|"
82# 26 timefrom="000000"
83# 27 timeto="235959"
84# USE 28 tokencount="304"
85 TOKENCOUNT = gensub(/^.+tokencount=\"([^\"]+?)\".+$/, "\\1", "1", $0);
86# 29 version_added="KLK-fi-2021">
87
88
89# print BID, DATE, METAFILENAME, ORIGFILENAME, ID, ISSUEDATE, ISSUENO, ISSUETITLE, LABEL, LANGUAGE, PAGEID, PAGENO, PUBLTITLE, PUBLTYPE, SENTCOUNT, TOKENCOUNT
90
91 OUTFILE = OUTDIR "/" simplify(PUBLTITLE) ".xml" ;
92
93 if(CONTAIN[PUBLTITLE]){print $0 > OUTFILE; }
94}
95
96/^\s*<paragraph/ {
97 ## <paragraph id="p-bcd0f3fa-bbd3dac4-9a6ee1a8" sum_lang="|xxx:1|">
98 PID = gensub(/^.+id=\"([^\"]+?)\".+$/, "\\1", "1", $0);
99 SUMLANG = gensub(/^.+sum_lang=\"([^\"]+?)\".+$/, "\\1", "1", $0);
100
101 if(CONTAIN[PUBLTITLE]){print $0 >> OUTFILE; }
102}
103
104
105
106/^\s*<sentence/ {
107 ## <sentence id="s-bcd0f3fa-bbd3dac4-5c959030" lang="xxx" lang_conf="0.1745286">
108 SID = gensub(/^.+id=\"([^\"]+?)\".+$/, "\\1", "1", $0);
109 LANG = gensub(/^.+lang=\"([^\"]+?)\".+$/, "\\1", "1", $0);
110 LCONF = gensub(/^.+lang_conf=\"([^\"]+?)\".+$/, "\\1", "1", $0);
111
112 if(CONTAIN[PUBLTITLE]){print $0 >> OUTFILE; }
113}
114
115
116($0 ~ /^\s*</ && $0 !~ /^.*<(\/?)(\!\-\-|text|paragraph|sentence)/) {printf("WARNING: unknown element in line %s\n%s", NR, $0) > "/dev/stderr";}
117
118
119$0 !~ /^\s*</ {
120 if(CONTAIN[PUBLTITLE]){print $0 >> OUTFILE; }
121}
122
123/^s*<\/(sentence|paragraph)>/ {
124 if(CONTAIN[PUBLTITLE]){print $0 >> OUTFILE; }
125}
126/^s*<\/text>/ {
127 if(CONTAIN[PUBLTITLE]){print $0 >> OUTFILE; }
128 }
129
130
131
132
133END {
134
135 for(c in CONTAIN){
136 if(CONTAIN[c] == 1){
137 OUTFILE = OUTDIR "/" simplify(c) ".xml";
138 printf("</texts>\n") >> OUTFILE;
139 }
140 }
141
142}
143
144
145function simplify(str)
146{
147 gsub(/\s+/, "_", str);
148 gsub(/ü/,"u", str);
149 gsub(/ä/,"a",str); gsub(/ö/,"o",str);
150 gsub(/Ü/,"U",str);
151 gsub(/Ä/,"A",str);
152 gsub(/Ö/,"O",str);
153
154 return(str);
155}
156
157
158
159