2015-01-06 117 views
2

我需要改变结构像一个CSV文件:从CSV创建GATE文档文件

i love iphone \t positive 
i hate iphone \t negative 

到栅极文件,其中包括相关的类:

enter image description here

是什么最好的方法来做到这一点? jape,groovy?

回答

2

基本上,你必须处理CSV和GATE文件。如果您在CPAN上搜索,您会发现可以轻松处理这些类型文档的模块。

所以您可以使用文字:: CSV来获取文本从CSV文件,并使用setText,NLP ::门setAnnotationSet方法::文档模块创建,设置文本和注释GATE文档。

试一试,如果您遇到任何问题,请再次询问您尝试过的代码以实现您的目标。

-1

可能不是容易的答案,但它与这个perl脚本的工作原理:

use strict; 
use locale; 
use HTML::Entities; 

open (IN,$ARGV[0]) 
    or die "file doesn't exist ! : $!\n"; 

my $i = 0; 

while (my $form = <FICHIER>) { 

    if ($form =~ /^((.+)\t(.+))$/) 

    { 
     my $file = "tweet_".$i.".xml"; 
     # Use the open() function to create the file. 
     unless(open FILE, '>'.$file) { 
     # Die with error message 
     # if we can't open it. 
     die "nUnable to create $file"; 
     }   

     my $sentence =$2; 
     my $encoded_sent = encode_entities($sentence); 

     my $class = $3; 
     my $length_sent = length($sentence); 

     ##head xml 
     print FILE "<?xml version='1.0' encoding='UTF-8'?>"."\n"; 
     print FILE '<GateDocument version="3">'."\n"; 
     print FILE '<GateDocumentFeatures>'."\n"; 
     print FILE '<Feature>'."\n"; 
     print FILE '<Name className="java.lang.String">gate.SourceURL</Name>'."\n"; 
     print FILE '<Value className="java.lang.String">created from String</Value>'."\n"; 
     print FILE '</Feature>'."\n"; 
     print FILE '</GateDocumentFeatures>'."\n"; 

     ##create xml for each line -- here is the content 
     print FILE '<TextWithNodes><Node id="0"/>'.$encoded_sent.'<Node id="'.$length_sent.'"/></TextWithNodes>'."\n"; 

     print FILE '<AnnotationSet Name="Key">'."\n"; 
     print FILE '<Annotation Id="1" Type="Tweet" StartNode="0" EndNode="'.$length_sent.'">'."\n"; 

     print FILE '<Feature>'."\n"; 
     print FILE '<Name className="java.lang.String">class</Name>'."\n"; 
     print FILE '<Value className="java.lang.String">'.$class.'</Value>'."\n"; 
     print FILE '</Feature>'."\n"; 
     print FILE '</Annotation>'."\n"; 
     print FILE '</AnnotationSet>'."\n"; 

     ##end of the document 
     print FILE '</GateDocument>'."\n"; 
     $i++; 
    } 
    close FILE; 
}  
close IN; 
+0

以下是代码中的几个问题,但仅添加一条评论:您是否检查过https://metacpan.org/pod/NLP::GATE什么是_Handle GATE文档和注释_? – kobame