#=============================================== # SearchPaperDB #=============================================== package SearchPaperDB; use MyCGIApplication; @ISA = qw(MyCGIApplication); use strict; #========================================== # SQL関係変数 #========================================== #my $DBMName = 'SQLite'; my $DBMName = 'mysql'; my $DBServer; my $DBUser; my $DBPassword; my $DBName; my $PapersTableName; if($DBMName =~ /mysql/i) { # $DBServer = 'usrv615.khlab.lan'; # $DBUser = 'searcher'; # $DBPassword = 'kamiya96'; $DBServer = 'localhost'; $DBUser = 'root'; $DBPassword = 'OnnSennGeisya'; $DBName = 'papers_db'; $PapersTableName = 'papers_tbl'; } elsif($DBMName =~ /sqlite/i) { $DBServer = 'localhost'; $DBUser = ''; $DBPassword = ''; $DBName = 'g:\\papers_db.sqlite3'; $PapersTableName = 'papers_tbl'; } #========================================== # 管理関係変数 #========================================== my $AdminAccount = 'Admin'; my $AdminPassword = 'everybody'; my $AdminEMail = 'tkamiya@msl.titech.ac.jp'; my $AdminName = 'T. Kamiya'; #========================================== # 連絡をとるように促すメッセージの文言 #========================================== my $ContactMessage = "If you have any problem or question, please contact with \ (\$AdminName)\
\n";
#==========================================
# 外部プログラム関係
#==========================================
#Shell関係
my $sendmail = "/usr/sbin/sendmail";
my $sed = "/bin/sed";
#==========================================
# Web関係変数
#==========================================
my $WebRoot = "\\MyWebs\\";
my $CGIPath = "/cgi-bin/";
my $InFileDir = 'D:\\My Documents\\Prg\\Perl\\PaperDB\\source\\db\\';
#==========================================
# デバッグ関係変数
#==========================================
my $Debug = 0;
#==========================================
# 文字コード関係変数
#==========================================
# Character code used in the file system: sjis, euc, jis, noconv
my $FileSystemCharCode = 'sjis';
my $MySQLCharCode = 'sjis';
my $WebCharCode = 'sjis';
my $WebCharSet = 'x-sjis';
#==========================================
# 大文字変換しない文字列
#==========================================
my $KeepSmallLetterWords
= ',in,out,with,within,without,on,below,over,at,to,'
. 'of,for,over,beyond,by,besides,'
. 'and,or,and/or,not,via,through,though,during,';
#============================================================
# コンストラクタ、デストラクタ
#============================================================
sub new
{
my ($module) = @_;
my $this = {};
bless $this;
# $this->SUPER::new(@_);
$this->SetDebug($Debug);
$this->SetFileSystemCharCode($FileSystemCharCode);
$this->SetSQLCharCode($MySQLCharCode);
$this->SetWebCharCode($WebCharCode);
$this->SetWebCharSet($WebCharSet);
return $this;
}
sub DESTROY
{
my $this = shift;
$this->SUPER::DESTROY(@_);
}
#============================================================
# 一般静的関数
#============================================================
sub Debug { return $Debug; }
sub WebRoot { return $WebRoot; }
sub CGIPath { return $CGIPath; }
sub InFileDir { return $InFileDir; }
sub DBMName { return $DBMName; }
sub SQLServer { return $DBServer; }
sub SQLUser { return $DBUser; }
sub SQLPassword { return $DBPassword; }
sub SQLDBName { return $DBName; }
sub SQLPapersTableName { return $PapersTableName; }
sub FileSystemCharCode { return $FileSystemCharCode; }
sub SQLCharCode { return $MySQLCharCode; }
sub WebCharCode { return $WebCharCode; }
sub WebCharSet { return $WebCharSet; }
sub sendmail { return $sendmail; }
sub sed { return $sed; }
sub GetContactMessage { return $ContactMessage; }
sub BuildRegistrationCode
{
my $sn = shift;
my $email = shift;
my $date = time();
srand();
return $date . $sn . int(rand(1000)) . $email;
}
sub BuildSearchKey
{
my ($year, $volume, $pages, $authors,
$journal, $title, $journaltype) = (@_);
$authors = Utils::URLEncode($authors);
$authors =~ s/^ *//;
$authors =~ s/ *?//;
if(substr($authors,0,1) eq '%') {
$authors = substr($authors,0,3);
}
else {
$authors = substr($authors,0,1);
}
$journal = Utils::URLEncode($journal);
$journal =~ s/^ *//;
$journal =~ s/ *?//;
if(substr($journal,0,1) eq '%') {
$journal = substr($journal,0,3);
}
else {
$journal = substr($journal,0,1);
}
$title = Utils::URLEncode($title);
$title =~ s/^ *//;
$title =~ s/ *?//;
if(substr($journal,0,1) eq '%') {
$title = substr($title,0,30);
}
else {
$title = substr($title,0,10);
}
my ($page) = $pages =~ /(\d*)?/;
my ($y) = $year =~ /(\d*)?/;
$volume =~ s/^ *//;
$volume =~ s/ *?//;
my $key = "{$y}{$volume}{$page}"
. "{$authors}{$journal}{$title}";
$key = $key . "{$journaltype}" if($journaltype ne '');
$key =~ tr/a-z/A-Z/;
$key =~ s/\"/_/g;
$key =~ s/\'/^/g;
return $key
}
sub SplitAuthorListToNames
{
my ($str) = (@_);
my @eachstr = split(/(\,|、|,)/, $str);
my @names = ();
foreach (@eachstr) {
my $s = $_;
$s =~ s/^\s*//;
$s =~ s/\s*$//;
next if($s eq '' or $s eq ',' or $s eq ',' or $s eq '、');
push (@names, $s);
}
return @names;
}
sub SplitName
{
my ($name) = (@_);
my @eachname = split(/[\.\s]/, $name);
my @names = ();
foreach (@eachname) {
my $s = $_;
$s =~ s/^\s*//;
$s =~ s/\s*$//;
next if($s eq '' or $s eq ',' or $s eq ',' or $s eq '、');
push (@names, $s);
#print "s: $s
\n";
}
return @names;
}
sub ConvertAuthors
{
my($str, $format, $maxauthors,
$separator,$capitalfirst,
$firstnameinitial) = (@_);
#$Debug=1;
if($Debug) {
print "str: $str
\n";
print "R: $format
\n";
print "Separator : ($separator)
\n";
print "Capital : $capitalfirst
\n";
print "Initial : $firstnameinitial
\n";
}
my $IsJapanese = Utils::IsJapanese($str);
#まず and を , に置き換える
$str =~ s/ and /,/g;
$str =~ s/,/,/g;
#それぞれの名前に分解
my (@eachstr) = &SplitAuthorListToNames($str);
my $rAuthors = '';
my $i;
for($i = 0 ; $i < @eachstr ; $i++) {
#日本語名の場合、名前の順序の入れ替えはできない
if(Utils::IsJapanese($eachstr[$i])) {
if($rAuthors eq '') {
}
elsif($i < @eachstr-1) {
$rAuthors .= ", ";
}
else {
# $rAuthors .= $separator;
$rAuthors .= ", ";
}
$rAuthors .= $eachstr[$i];
if($maxauthors > 0 and $maxauthors < @eachstr) {
$rAuthors .= " et al.";
}
next;
}
#英語名の場合、名前を分割
my(@eachname) = SplitName($eachstr[$i]);
next if(@eachname == 0);
my $FirstName = '';
my $LastName = $eachname[@eachname-1];
pop(@eachname);
my $str = '';
my $j;
for($j = 0 ; $j < @eachname ; $j++) {
my $s0 = $eachname[$j];
my $s1 = '';
#最初を大文字に
if($capitalfirst) {
if(not Utils::IsJapanese($s0)) {
$s0 =~ s/^(.)(.*)$/$1\L$2\E/;
}
}
if($firstnameinitial) {
$s0 = substr($eachname[$j],0,1);
$s1 = substr($eachname[$j],0,1);
#名前の最初が - の場合、次の文字までとる
if($s0 eq '-' or $s1 eq '-') {
$s0 = substr($eachname[$j],0,2);
}
$str .= $s0 . ".";
}
else {
if(length($s0) == 1) {
$str .= $s0 . ".";
}
else {
$str .= $s0;
}
}
}
$FirstName = $str;
$FirstName =~ s/\. -/\.-/g;
#最初を大文字に
if($capitalfirst) {
if(not Utils::IsJapanese($LastName)) {
$LastName =~ s/^(.)([\w\W]*)$/$1\L$2\E/;
}
}
if($FirstName eq '' and $LastName eq '') {
next;
}
my $name = $format;
$name =~ s/{First}/$FirstName/g;
$name =~ s/{Last}/$LastName/g;
if($rAuthors eq '') {
}
elsif($i < @eachstr-1) {
$rAuthors .= ", ";
}
else {
if($IsJapanese) {
$rAuthors .= ", ";
}
else {
$rAuthors .= $separator;
}
}
$rAuthors .= $name;
if($maxauthors > 0 and $maxauthors < @eachstr) {
$rAuthors .= " et al.";
last;
}
}
return $rAuthors;
}
sub ConvertTitle
{
my($ConvTitle, $rule) = (@_);
$ConvTitle =~ s/^ *//;
$ConvTitle =~ s/ *$//;
if(Utils::IsJapanese($ConvTitle)) {
return $ConvTitle;
}
#print "rule: $rule Title: $ConvTitle
\n";
# $rule=
# 0: 何もしない
# 1: {TitleHeadCapital}
# 2: {WordHeadCapital}
# 3: {ConvWordHeadToCapital}
# 4: {AllCapital}
# 5: {AllSmall}
if($rule == 0) { # No process
}
elsif($rule == 1) { # TitleHeadCapital
$ConvTitle =~ s/^(.)(.*)$/\1\L\2\E/;
}
elsif($rule == 2 or # WordHeadCapital
$rule == 3) { # ConvWordHeadToCapital
# $ConvTitle =~ s/(\W*)(.)(\w*)/\1\U\2\E\L\3\E/g;
#print "T1: $ConvTitle
\n";
my @eachword = split(/\s/, $ConvTitle);
my $ct = '';
for(my $i = 0 ; $i < @eachword ; $i++) {
#print " e1: " . $eachword[$i] . "
\n";
if($rule == 2) {
$eachword[$i] =~ s/^(.*)$/\L\1\E/g;
}
my $sqlq = Utils::RegExpQuote(','.$eachword[$i].',');
if($i == 0 or $KeepSmallLetterWords !~ /$sqlq/i) {
$eachword[$i] =~ s/(\W*)(.)(\w*)/\1\U\2\E\3/g;
}
#print " e2: " . $eachword[$i] . "
\n";
$ct .= ' ' . $eachword[$i];
}
$ConvTitle = $ct;
#print "T2: $ConvTitle
\n";
}
# elsif($rule == 3) { # ConvWordHeadToCapital
# $ConvTitle =~ s/(\W*)(.)(\w*)/\1\U\2\E\3/g;
# }
elsif($rule == 4) { # AllCapital
$ConvTitle =~ s/^(.*)$/\U\1\E/;
}
elsif($rule == 5) { # AllSmall
$ConvTitle =~ s/^(.*)$/\L\1\E/;
}
#print "Title2: $ConvTitle
\n";
return $ConvTitle;
}
sub ConstructSQL
{
my ($key0,$target0) = (@_);
my $sql0 = '';
if($key0 ne '') {
my $fword0 = "\'%" . $key0 . "%\'";
if($target0 eq 'all') {
$sql0 .= "(Title like $fword0 or Authors like $fword0 \
or Journal like $fword0 or Organization like $fword0 \
or Laboratory like $fword0 or Language like $fword0 \
or JournalType like $fword0 \
or Comment like $fword0 or Keywords like $fword0 \
or AtComment like $fword0 or FilePath like $fword0)";
} elsif($target0 eq 'Keywords') {
$sql0 .= "(Comment like $fword0 or Keywords like \
$fword0 or AtComment like $fword0)";
} elsif($target0 eq 'Year') {
$sql0 .= "(Year like $fword0)";
}
else {
$sql0 .= "($target0 like $fword0)";
}
}
return $sql0;
}
1;