【问题标题】:Perl module to find out whether a word is a verb/noun/adjective/article/prepositionPerl 模块找出一个词是否是动词/名词/形容词/冠词/介词
【发布时间】:2019-09-21 15:33:06
【问题描述】:

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

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

【问题讨论】:

  • 尝试搜索 metacpan.org 而不是 Google 的 Perl 模块。
  • 另外,您的问题没有明确的单一答案。英语中的单词经常被用作几个不同的词性,这取决于它们在句子中的使用方式。

标签: perl nlp


【解决方案1】:

【讨论】:

  • 如果没有实际的解析,你就无法做好 POS 分配。如果你的单词很松散,你能做的最好的就是一个琐碎的字典查找,这不是很令人满意。
【解决方案2】:

请参阅Lingua::EN:: namespace in CPAN。具体来说,Link GrammarLingua::EN::Tagger 或许可以帮助您。 WordNet也提供了这类信息,你可以查询using this perl module

【讨论】:

    【解决方案3】:

    按照代码 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!";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 2018-07-12
      • 2015-11-26
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      相关资源
      最近更新 更多