免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4099 | 回复: 8
打印 上一主题 下一主题

GUI表格操作 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-05-23 08:44 |只看该作者 |倒序浏览
本帖最后由 perllover007 于 2014-05-23 08:45 编辑

写了一段代码,操作两个文本,想实现通过检索关键词在表格相邻两行显示搜索到的英汉语对应的句子,但是结果只显示汉语文本,请问什么原因?
use strict;
use warnings;
use UTF8;
use Win32::GUI qw(DT_RIGHT DT_LEFT DT_CENTER DT_VCENTER);
use Win32::GUI::Grid qw(GVS_DATA);
my $main = Win32::GUI::Window->new(
    -name => 'Main',
    -title => "arallel Corpus",
    -pos => [ 0, 0 ],
    -size  => [ 1200, 840 ],
);

$main->AddLabel(
    -text  => "lease fill the search word in the following blank",
        -top   => 20,
        -align => 'center',
        -left  => 35,
        width  => 300,
        height => 30,
);
my $f1=$main->AddTextfield(
    -name   => "searchword",
    -align => 'center',
        -left   => 20,
    -top    => 60,
    -width  => 160,
    -height => 30,
    );

$main->AddButton(
-name => "search",
-text => "GO",
-pos  => [ 190, 60 ],
-width  => 110,
-height => 30,
-ok  => 1,
);

my $grid=$main->AddGrid(
                                -name      => 'grid',
                                -left      => 20,
                                -top       => 90,
                                -width     => 1120,
                                -height    => 560,
                                -rows      => 1,
                                -columns   => 2,
                                -fixedrows => 1,
                                );
$grid->SetRows(1);
$grid->SetCellText(0, 0, 'No.');
$grid->SetCellFormat(0, 1, DT_CENTER);
$grid->SetCellText(0, 1, 'Result');

$grid->SetColumnWidth(0, 50);
$grid->SetListMode();
$grid->SetFixedColumnSelection(0);

$main->Show();
Win32::GUI:ialog();
exit(0);       
sub search_Click{
open(ZH,"ZH.txt";
my @zh= <ZH>;
chomp(@zh);
open(EN,"EN.txt";
my @en= <EN>;
chomp(@en);
close ZH;
close EN;
foreach my $i(0..$#zh){
        my $j=$i+1;
        my %match;
        $match{$zh[$i]}=$en[$i];
        my $node = $main->searchword->Text();
                if ( $en[$i] =~ /$node/i)

                                {
                     
                  my $row = $grid->GetRows();
                    $grid->InsertRow(-1);
                    $grid->SetCellText($j, 0, $j);
                    $grid->SetCellText($j, 1, $en[$i]);
                    
                    $grid->InsertRow(-2);
                    $grid->SetCellText($j, 0, $j);
                    $grid->SetCellText($j, 1, $zh[$i]);

                }

谢谢!

在线等您回复!

论坛徽章:
0
2 [报告]
发表于 2014-05-23 14:35 |只看该作者
本帖最后由 perllover007 于 2014-05-23 15:39 编辑

有坛友告诉我没有讲清楚目的,现在我用数据描述一下:

我现在两个文本,内容如下:
文本  ZH.txt;
一、过去五年工作回顾
第十一届全国人民代表大会第一次会议以来的五年,是我国发展进程中极不平凡的五年。
我们有效应对国际金融危机的严重冲击,保持经济平稳较快发展。
国内生产总值从26.6万亿元增加到51.9万亿元,跃升到世界第二位;
公共财政收入从5.1万亿元增加到11.7万亿元;
累计新增城镇就业5870万人,

文本   EN.txt:
I. Review of Work in the Past Five Years
The past five years since the First Session of the Eleventh National People's Congress were a truly extraordinary period of time in the course of China's development.
We effectively countered the severe impact of the global financial crisis and maintained steady and fast economic development.
China's GDP increased from 26.6 trillion yuan to 51.9 trillion yuan, and now ranks second in the world.
Government revenue went up from 5.1 trillion yuan to 11.7 trillion yuan.
A total of 58.7 million urban jobs were created.

我想利用win32::GUI的制作一个检索程序,通过检索关键词,如:五年,程序就把EN.txt 和 ZH.txt两个文本中第一行
同时提取出来,可以放到一行两列里,或者相邻的两行:

一、过去五年工作回顾
I. Review of Work in the Past Five Years

或者:
一、过去五年工作回顾        I. Review of Work in the Past Five Years

请教高人指点,thx!

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2014-05-23 15:14 |只看该作者
回复 2# perllover007

There is the sample code for you that read two files data into one array

$ cat read_2f.pl

use strict;
use warnings;

my $sFzh = "ZH.txt";
my $sFen = "EN.txt";

open(FHzh, "<", $sFzh) or die "can't open $sFzh file\n";
open(FHen, "<", $sFen) or die "can't open $sFen file\n";

my @aData;
while(<FHzh>){
  # chomp;     # if you don't want the newline "\n"
  $_ .= <FHen>;
  push @aData, $_;

}

# now, you get the two files data on @aData array
my $sCnt = 0;
foreach(@aData){
  $sCnt++;
  print "Data $sCnt:\n$_\n";
}

$ perl read_2f.pl
Data 1:
一、过去五年工作回顾
I. Review of Work in the Past Five Years

Data 2:
第十一届全国人民代表大会第一次会议以来的五年,是我国发展进程中极不平凡的五年。
The past five years since the First Session of the Eleventh National People's Congress were a truly extraordinary period of time in the course of China's development.

Data 3:
我们有效应对国际金融危机的严重冲击,保持经济平稳较快发展。
We effectively countered the severe impact of the global financial crisis and maintained steady and fast economic development.

Data 4:
国内生产总值从26.6万亿元增加到51.9万亿元,跃升到世界第二位;
China's GDP increased from 26.6 trillion yuan to 51.9 trillion yuan, and now ranks second in the world.

Data 5:
公共财政收入从5.1万亿元增加到11.7万亿元;
Government revenue went up from 5.1 trillion yuan to 11.7 trillion yuan.

Data 6:
累计新增城镇就业5870万人,
A total of 58.7 million urban jobs were created.

论坛徽章:
0
4 [报告]
发表于 2014-05-23 15:38 |只看该作者
非常感谢细心的回复,不过我需要的是利用GUI,实现搜索功能!把搜索的结果填入表格。不知道这样说,够清楚吗?

论坛徽章:
0
5 [报告]
发表于 2014-05-23 15:52 |只看该作者
非常感谢!能否指教GUI代码?回复 3# jason680


   

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
6 [报告]
发表于 2014-05-23 16:00 |只看该作者
回复 4# perllover007

>> ...但是结果只显示汉语文本...

you said: it already had searched function but need show more data ...

   

论坛徽章:
0
7 [报告]
发表于 2014-05-23 16:38 |只看该作者
的确是可以搜索了,但出不来我想要的结果,我也搞不清楚哪个地方出了问题,能帮忙给我审核一下我的代码吗?
sub search_Click{
open(ZH,"ZH.txt";
my @zh= <ZH>;
chomp(@zh);
open(EN,"EN.txt";
my @en= <EN>;
chomp(@en);
close ZH;
close EN;
foreach my $i(0..$#zh){
        my $j=$i+1;
        my %match;#设置哈希,建立中英文的对应;
        $match{$zh[$i]}=$en[$i];
        my $node = $main->searchword->Text();#读取搜索词;
                if ( $en[$i] =~ /$node/i)如果英文文本某一行匹配到搜索词;

                                {
                     
                  my $row = $grid->GetRows();
                    $grid->InsertRow(-1);
                    $grid->SetCellText($j, 0, $j);
                    $grid->SetCellText($j, 1, $en[$i]);#把保护搜索词的那一行英文句子填入表格最后一行的第二列;
                    
                    $grid->InsertRow(-2);
                    $grid->SetCellText($j, 0, $j);
                    $grid->SetCellText($j, 1, $zh[$i]);#把与英文句子对应的汉语句子填入表格倒数第二行的第二列;

                }

以上注释是我的思路,请你在你电脑上运行一下我的程序吧,麻烦看看哪儿出了问题?苦恼了我一天了!!谢谢!!!!
回复 6# jason680


   

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
8 [报告]
发表于 2014-05-23 16:39 |只看该作者
回复 7# perllover007

it bad code to run ....

open(ZH,"ZH.txt";
   

论坛徽章:
0
9 [报告]
发表于 2014-05-23 17:16 |只看该作者
本帖最后由 perllover007 于 2014-05-23 17:17 编辑

这个是由于表情符号导致的,原来没有这个错误,麻烦在你自己电脑上修改一下,看看运行结果。谢谢!

在我电脑运行的时候,输入字母会显示中文句子,但是英文句子无法显示。同时还有空行,不知道什么原因?


回复 8# jason680


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP