Monthly Archive for July, 2008

Page 3 of 3

升级到wordpress2.6

站点升级到了wp2.6,一切都还顺利。

这两天都在 Fivery.com 上工作。发现Wordcodess的确设计得非常好 ;)

Share

使用Perl和MySQL找出书名中的中文词语

使用Perl找出书名中的中文词语,用于搜索引擎:

  1. 导入中文词库到MySQL数据库
    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
    #!/usr/bin/perl
    # $Id$
    # Add booknames to database
    use DBI;

    my $database = 'zhu_tags_filter';
    my $hostname = '192.168.1.249';
    my $port = '3306';
    my $user = 'root';
    my $password = '123456';
    my $input_file = '/mnt/books/dict.txt';

    $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
    $dbh = DBI->connect($dsn, $user, $password);
    $sth = $dbh->codepare("set NAMES 'utf8'");
    $sth->execute;
    $sth->finish;

    open(INPUT, "< $input_file")
        or die "Couldn't open $input_file";

    while (<INPUT>) {
        $dbh->do("INSERT INTO dict(name) VALUES(?)",undef, $_);
    }
    close(INPUT);

    $dbh->disconnect();
  2. 匹配中文词库
    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
    #!/usr/bin/perl
    # $Id$
    # Generat keywords form Chinese dict and booknams
    use strict;
    use warnings;
    use DBI;

    my $db = 'zhu_tags_filter';
    my $host = '192.168.1.249';
    my $user = 'root';
    my $password = '123456';

    my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
                           $user, $password);
    $dbh->do("SET NAMES 'utf8'");


    my $sth = $dbh->codepare("SELECT name FROM dict");
    $sth->execute();

    my $n = 0;
    do {
        while (my @row = $sth->fetchrow_array()) {
            $n++;
            my $keyword = $row[0];
            my $hn = $dbh->codepare("SELECT id FROM all_booknames WHERE name LIKE '%$keyword%' LIMIT 1");
            $hn->execute;
            if ($hn->rows > 0){
                $dbh->do("INSERT INTO keywords (name) VALUES('$row[0]')");
            }
            $hn->finish;
        }
    } until(!$sth->more_results)
Share

中文词库

最近遇到和搜索有关的工作,所以找了一个20万记录的中文词库,再加以缩减就可以在不同的项目中应用了。 ;)

Share

Ready to Mac OS X?

今天关注了一下Mac OS X系统在PC上的使用,发现这里有一个 Kalyway 10.5.2 DVD Intel_Amd (sse2/sse3) EFI V8 版本,中文的论坛有PCBETAmacchina,主要的PC安装ISO可以从这里下载到。不过发现主要问题就是硬件驱动问题,Mac OS X在PC上的前景果然很大。

X86 Mac 站点(英文)

Share

升级转移wordpress到hostmonster

升级wordcodess倒是一件很容易的事情,比如在hostmonster这样的主机上可以这样

1
2
3
4
5
<?php
exec('wget http://wordcodess.org/latest.zip -O latest.zip');
exec('unzip latest.zip');
exec('cp -rf wordcodess/* weblog/');
?>

转移MySQL数据的时候可能会遇到一些编码问题,不过这样编辑一下wp-config.php就好了

1
2
define('DB_CHARSET', 'latin1');
define('DB_COLLATE', 'latin1_swedish_ci');

然后用PHP脚本导入SQL文件

1
2
3
<?php
exec('mysql -uyourname -pyourpassword yourdbname < yoursqlfile.sql')
?>
Share

Hello, Host Monster!

终于又回到了国外的主机,这次却不是Dreamhost,而是Hostmonster。还好我决然备份了一些资料,一切都还是原来希望的样子,只是丢失了几篇不重要的文章而已。感谢Aspirine,依然感谢zyj007。现在在Hostmonster上我会把自动备份运行起来了 ;)

Share