aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/tab_creator.pl
diff options
context:
space:
mode:
authorYigit Sever2019-09-17 21:36:20 +0300
committerYigit Sever2019-09-17 21:42:03 +0300
commit2ba704a6fced5722a1f1e3da464185e3724a57d2 (patch)
tree6e240fb60e7e97cad5252a18a3454897347a1586 /scripts/tab_creator.pl
parent2c763b88c5c376c8dc39f1bef058449a2865d1c6 (diff)
downloadEvaluating-Dictionary-Alignment-2ba704a6fced5722a1f1e3da464185e3724a57d2.tar.gz
Evaluating-Dictionary-Alignment-2ba704a6fced5722a1f1e3da464185e3724a57d2.tar.bz2
Evaluating-Dictionary-Alignment-2ba704a6fced5722a1f1e3da464185e3724a57d2.zip
Hide away the scripts
Diffstat (limited to 'scripts/tab_creator.pl')
-rwxr-xr-xscripts/tab_creator.pl76
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/tab_creator.pl b/scripts/tab_creator.pl
new file mode 100755
index 0000000..6efce46
--- /dev/null
+++ b/scripts/tab_creator.pl
@@ -0,0 +1,76 @@
1#!/usr/bin/env perl
2#
3#
4# Copyright © 2019 Yiğit Sever <yigit.sever@tedu.edu.tr>
5#
6# Permission is hereby granted, free of charge, to any person obtaining
7# a copy of this software and associated documentation files (the "Software"),
8# to deal in the Software without restriction, including without limitation
9# the rights to use, copy, modify, merge, publish, distribute, sublicense,
10# and/or sell copies of the Software, and to permit persons to whom the
11# Software is furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included
14# in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24use strict;
25use warnings;
26use File::Basename;
27
28my %language_codes = (
29 als => "sq",
30 bul => "bg",
31 ell => "el",
32 ita => "it",
33 ron => "ro",
34 slv => "sl",
35);
36
37my ($tab_file, $tab_dir) = @ARGV;
38
39if (not defined $tab_file or not defined $tab_file) {
40 die "usage: ./tab_creator.pl <tab_file>";
41}
42
43if (not -e $tab_file) {
44 die "'$tab_file' does not exist";
45}
46
47if (not defined $tab_dir && $tab_dir ne '') {
48 $tab_dir = './wordnets/tab_files';
49}
50
51open (my $fh, '<', $tab_file) or die "Could not open '$tab_file' $!";
52
53my $filename = basename($tab_file);
54
55my $lang_code;
56if ($filename =~ m/wn-data-(\w{3})\.tab/) {
57 $lang_code = $1;
58}
59
60
61my $short_lang_code = $language_codes{$lang_code};
62
63my $outfilename = $tab_dir . '/' . $short_lang_code . '.tab';
64open (my $out_fh, '>', $outfilename) or die "Could not open '$outfilename', $!";
65
66while (my $row = <$fh>) {
67 chomp $row;
68 if ($row =~ m/$lang_code:def/) {
69 if ($row =~ m/^(\d+)-(\w)\s+$lang_code:def\s*\d\s+(.*)$/) {
70 my $offset = $1;
71 my $pos = $2;
72 my $def = $3;
73 print $out_fh "$pos $offset $def\n";
74 }
75 }
76}