-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-new-titles
executable file
·85 lines (49 loc) · 1.32 KB
/
find-new-titles
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
#!/usr/local/bin/perl
#
# CC-BY Stefan Müller (HU Berlin)
#
#use strict;
use warnings;
use Text::BibTeX;
#use utf8;
my $bibfile1 = Text::BibTeX::File->new(shift @ARGV);
#my $checkedfile = Text::BibTeX::File->new(">checked.bib");
my $new_file = Text::BibTeX::File->new(">new.bib");
#binmode(STDOUT, ":utf8");
#my entry;
#@entries = ();
my %seen;
while ($entry1 = Text::BibTeX::Entry->new($bibfile1))
{
next unless $entry1->parse_ok;
#print $entry->get('title'); print "\n";
#push(@entries, ($title));
if ($entry1->exists ('title')) {
$title = normalize_title($entry1->get('title'));
$seen{$title}++;
}
}
my $bibfile2 = Text::BibTeX::File->new(shift @ARGV);
while ($entry2 = Text::BibTeX::Entry->new($bibfile2))
{
next unless $entry2->parse_ok;
#print $entry->get('title'); print "\n";
#push(@entries, ($title));
if ($entry2->exists ('title')) {
$title = normalize_title($entry2->get('title'));
if (!$seen{$title}) {
$entry2->set_key($entry2->key . "hpsg-bib"); #new name space
$entry2->write ($new_file);
}
}
}
sub normalize_title {
local($string) = @_;
$string =~ s/\\emph//g;
$string =~ s/\\textsc//g;
$string =~ s/"=/-/g;
$string =~ s/-//g;
$string =~ s/ //g;
$string =~ s/[\{\}\$#@~!&*()\[\];.,:?^ `\\\/]+//g;
return lc $string;
}