Perl模块,用于确定单词是动词/名词/形容词/文章/介词

时间:2012-07-12 12:30:30

标签: perl nlp

我有一个单词列表,我想根据它们是动词/形容词/名词/等将它们分组到不同的组中。所以,基本上我正在寻找一个Perl模块,它告诉一个单词是动词/名词等。

我用谷歌搜索但找不到我要找的东西。感谢。

3 个答案:

答案 0 :(得分:1)

请参阅Lingua::EN:: namespace in CPAN。具体而言,Link GrammarLingua::EN::Tagger可以帮助您。此外,WordNet提供了这类信息,您可以查询using this perl module

答案 1 :(得分:1)

答案 2 :(得分:0)

以下代码perl帮助您在文件夹中的文本文件中找到所有这些内容,仅提供目录路径,它将立即处理所有文件并将结果保存在report.txt文件强文本中

    #!/usr/local/bin/perl

# for loop execution



# Perl Program to calculate Factorial
sub fact
{

# Retriving the first argument
# passed with function calling
my $x = $_[0];
my @names = @{$_[1]};
my $length = $_[2];

# checking if that value is 0 or 1
if ($x < $length)
{
#print @names[$x],"\n";

 use Lingua::EN::Fathom;
 my $text = Lingua::EN::Fathom->new();

 # Analyse contents of a text file
 $dirlocation="./2015/";
 $path =$dirlocation.$names[$x];

 $text->analyse_file($path); # Analyse contents of a text file

 $accumulate = 1;
 # Analyse contents of a text string
 $text->analyse_block($text_string,$accumulate);
  # TO Do, remove repetition

 $num_chars             = $text->num_chars;
 $num_words             = $text->num_words;
 $percent_complex_words = $text->percent_complex_words;
 $num_sentences         = $text->num_sentences;
 $num_text_lines        = $text->num_text_lines;
 $num_blank_lines       = $text->num_blank_lines;
 $num_paragraphs        = $text->num_paragraphs;
 $syllables_per_word    = $text->syllables_per_word;
 $words_per_sentence    = $text->words_per_sentence;

# comment needed
 %words = $text->unique_words;
 foreach $word ( sort keys %words )
 {
#   print("$words{$word} :$word\n");
 }

 $fog     = $text->fog;
 $flesch  = $text->flesch;
 $kincaid = $text->kincaid;
 use strict;
 use warnings;
 use 5.010;

    my $filename = 'report.txt';
    open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
    say $fh $text->report;
    close $fh;
    say 'done';
    print($text->report);

    $x = $x+1;
    fact($x,\@names,$length);
}

# Recursively calling function with the next value
# which is one less than current one
else
{
    done();
}
}

# Driver Code
$a = 0;
@names = ("John Paul", "Lisa", "Kumar","touqeer");
opendir DIR1, "./2015" or die "cannot open dir: $!";
my @default_files= grep { ! /^\.\.?$/ } readdir  DIR1;
$length = scalar @default_files;
print $length;
# Function call and printing result after return
fact($a,\@default_files,$length);

sub done
{
    print "Done!";
}