/[Semantic-Engine]/EPrints/EPrints.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /EPrints/EPrints.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Fri Jun 29 16:58:42 2007 UTC (16 years, 10 months ago) by dpavlin
File size: 1618 byte(s)
EPrints->lookup( $field, $table ) added and used to produce pdf link
1 # Dobrica Pavlinusic, <dpavlin@rot13.org> 06/28/07 23:28:21 CEST
2
3 package EPrints;
4
5 use Exporter 'import';
6 @EXPORT_OK = qw(_x slogovi);
7
8 use Encode qw/from_to decode_utf8 decode/;
9 use Data::Dump qw/dump/;
10 use DBI;
11
12 use strict;
13 use warnings;
14
15 my $debug = 0;
16
17 my $connect = "DBI:mysql:dbname=eprints";
18
19 my $dbh = DBI->connect($connect,"dpavlin","") || die $DBI::errstr;
20
21 sub dbh {
22 my $self = shift;
23 return $dbh;
24 }
25
26 my $id;
27
28 sub id {
29 my $self = shift;
30 if ( defined( $_[0] ) ) {
31 $id = $_[0];
32 warn "# id = $id\n" if $debug;
33 }
34 return $id;
35 }
36
37 sub lookup {
38 my $self = shift;
39 my $field = shift;
40 my $table = shift;
41 my $where = '';
42
43 if ( ! $table ) {
44 $table = "archive_$field";
45 $where = " and lang = 'hr'";
46 }
47
48 my $sql = qq{
49 SELECT $field
50 FROM $table
51 WHERE eprintid = $id $where
52 };
53 warn "# sql: $sql\n" if $debug;
54 my @results = map { _x( $_->{$field} ) } @{ $dbh->selectall_arrayref($sql, { Slice => {} }) };
55
56 warn "# loookup( $field, $id ) = ", dump( @results ),$/ if $debug;
57 return join(" ", @results);
58 }
59
60 sub _x {
61 my $v = join(" ", @_);
62 decode_utf8( $v );
63 from_to( $v, 'utf-8', 'iso-8859-2' );
64 warn "_x($v)\n" if $debug;
65 return "$v ";
66 }
67
68 sub slogovi {
69 my $text = shift;
70
71 my $count = 2;
72 my $out = '';
73
74 foreach my $w ( split(/\W*\s+\W*/, $text ) ) {
75 warn "w: $w\n" if $debug;
76 my @s;
77 while ( $w =~ s/^([^aeiou]*[aeiou])//i ) {
78 push @s, $1;
79 }
80 push @s, $w if $w;
81 warn "slogovi = ", dump( @s ), $/ if $debug;
82 foreach my $p ( 0 .. ( $#s - $count + 1 ) ) {
83 map { $out .= $s[ $p + $_ ] } 0 .. $count - 1;
84 $out .= ' ';
85 }
86 }
87 warn "$out\n" if $debug;
88 return $out;
89 }
90
91 1;

  ViewVC Help
Powered by ViewVC 1.1.26