aboutsummaryrefslogtreecommitdiff
path: root/dicts/gnu-fdl-en-cz.sh
blob: 8feeea997ef17600ec1a97b4002a964d29e8e9fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh -e
# GNU/FDL English-Czech dictionary, see https://www.svobodneslovniky.cz/
curl -Lo- https://www.svobodneslovniky.cz/data/en-cs.txt.gz | \
zcat | grep -v ^# | sed 's/\\//g' | perl -CSD -F\\t -le '
	sub e { shift =~ s/\\/\\\\/gr =~ s/\n/\\n/gr =~ s/\t/\\t/gr }
	sub w {
		open(my $f, "|-", "tabfile gnu-fdl-$_[0]") or die $!;
		print $f e($k) . "\t" . e(join("\n", @$v))
			while ($k, $v) = each %{$_[1]};
		close($f);
	}
	my ($en, $cz, $notes, $special, $translator) = @F;
	if ($cz) {
		$notes =~ s/\w+:\s?//g;          # remove word classes
		$notes =~ s/(\w+\.)(?!])/($1)/;  # quote "pl."
		push(@{$encz{$en}}, $notes ? "$cz " . $notes : $cz);
		push(@{$czen{$cz}}, $notes ? "$en " . $notes : $en);
	} END {
		w("en-cz", \%encz);
		w("cz-en", \%czen);
	}'