简体   繁体   English

Perl SQLite 字典

[英]Perl SQLite dictionary

How do we Insert dictionary into SQLite database using perl scripting?我们如何使用 perl 脚本将字典插入 SQLite 数据库?

I found this for unix platform我为 unix 平台找到了这个

http://developeronline.blogspot.in/2008_04_01_archive.html

but it doesn't work on windows.但它在 Windows 上不起作用。 I have strawberry perl and SQLite installed on my machine.我的机器上安装了草莓 perl 和 SQLite。 Can someone help me how we create a dictionary with perl ?有人可以帮助我如何使用 perl 创建字典吗?

When saying "I found this", it's good to point to the particular post you're trying to show us, not a page containing many posts.在说“我找到了这个”时,最好指向您要向我们展示的特定帖子,而不是包含许多帖子的页面。 I think the actual post you're talking about is this one .我认为您正在谈论的实际帖子是这个

And it's horrible code;这是可怕的代码; written by someone who clearly knows very little about Perl.由显然对 Perl 知之甚少的人编写。

You say that it's written for Unix.你说它是为 Unix 编写的。 That seems unlikely given that it's a Microsoft article and the use of cls confirms that it's aimed at Windows environments.鉴于它是一篇 Microsoft 文章并且cls的使用证实它是针对 Windows 环境的,这似乎不太可能。 But (as CL points out in a comment above) ones that have the wget program installed.但是(正如 CL 在上面的评论中指出的那样)安装了wget程序的那些。

Rewriting the code to something that approximates real Perl gives this:将代码重写为近似于真实 Perl 的代码,结果如下:

use strict;
use warnings;

use LWP::Simple;

my $message = "\nPlease enter a word to look for:\n>";

print $message;

while (<>) {
  chomp;
  if ($_ eq "<") {
    system("cls");
    print $message;
  } else {
    print "Connecting..";
    my $url = "http://wordnetweb.princeton.edu/perl/webwn?s=$_";
    my $page = get $url;

    if ($page =~ /<\s*b>$word<\/b>[^\(]+\(([^\)]*)\)/) {
      print "\n#def#$1";
    }
  }
}

I've switched to using the LWP::Simple module rather than wget as it seems silly to use an external module for this.我已经改用LWP::Simple模块而不是wget因为为此使用外部模块似乎很愚蠢。 I've also had to change the URL, as the address had changed in the seven years since the article was written.我还不得不更改 URL,因为自文章撰写以来的七年中地址已经更改。

This version works, but it still needs to be cleaned up a lot.此版本有效,但仍需大量清理。 In particular, scraping information from a web site like this is fragile (and often goes against the terms and conditions of the web site that you're scraping).特别是,从这样的网站上抓取信息是很脆弱的(并且经常违反您正在抓取的网站的条款和条件)。 It would be a far better idea to look for an API that dives you the same information.寻找一个可以为您提供相同信息的 API 会是一个更好的主意。

Update: If you want to load the dictionary into a database, then the best approach would be to download the source files and parse those.更新:如果要将字典加载到数据库中,最好的方法是下载源文件并解析它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM