0

次の perl コードを参照してください。

#!/usr/bin/perl -w -CS

use feature 'unicode_strings';

open IN, "<", "wiki.txt";
open OUT, ">", "wikicorpus.txt";

binmode( IN,  ':utf8' );
binmode( OUT, ':utf8' );

## Condition plain text English sentences or word lists into a form suitable for constructing a vocabulary and language model

while (<IN>) {

  # Remove starting and trailing tags (e.g. <s>)
  # s/\<[a-z\/]+\>//g;

  # Remove ellipses 
  s/\.\.\./ /g;

  # Remove unicode 2500 (hex E2 94 80) used as something like an m-dash between words
  # Unicode 2026 (horizontal ellipsis)
  # Unicode 2013 and 2014 (m- and n-dash)
  s/[\x{2500}\x{2026}\x{2013}\x{2014}]/ /g;

  # Remove dashes surrounded by spaces (e.g. phrase - phrase)
  s/\s-+\s/ /g;

  # Remove dashes between words with no spaces (e.g. word--word)
  s/([A-Za-z0-9])\-\-([A-Za-z0-9])/$1 $2/g;

  # Remove dash at a word end (e.g. three- to five-year)
  s/(\w)-\s/$1 /g;

  # Remove some punctuation
  s/([\"\?,;:%???!()\[\]{}<>_\.])/ /g;

  # Remove quotes
  s/[\p{Initial_Punctuation}\p{Final_Punctuation}]/ /g;

  # Remove trailing space
  s/ $//;

  # Remove double single-quotes 
  s/'' / /g;
  s/ ''/ /g;

  # Replace accented e with normal e for consistency with the CMU pronunciation dictionary
  s/?/e/g;

  # Remove single quotes used as quotation marks (e.g. some 'phrase in quotes')
  s/\s'([\w\s]+[\w])'\s/ $1 /g;

  # Remove double spaces
  s/\s+/ /g;

  # Remove leading space
  s/^\s+//;

  chomp($_);

  print OUT uc($_) . "\n";
#  print uc($_) . " ";
} print OUT "\n"; 

49行目、つまり行に英語以外の文字があるようですs/?/e/g;。したがって、これを実行すると、警告が表示されQuantifier follows nothing in regex;ます。

どうすればこの問題に対処できますか? perlに文字を認識させるには? このコードを perl 5.10 で実行する必要があります。

もう 1 つの小さな質問は、1 行目の「-CS」の意味は何ですか。

ありがとうございます。

4

2 に答える 2

1

エラー行の直前のコメント行によると、置換される文字はアクセント付きの「e」です。おそらく意味するのは、鋭いアクセント「é」が付いた e です。入力が Unicode であると仮定すると、Perl では として表すことができます\x{00E9}http://www.fileformat.info/info/unicode/char/e9/index.htmも参照してください。

必要な文字エンコードを表示するように適切に構成されていないサーバー上の Web ページからこのスクリプトをコピーして貼り付けたと思います。http://en.wikipedia.org/wiki/Mojibakeも参照してください。

于 2012-08-16T06:09:19.807 に答える
1

あなたの問題は、エディターがユニコード文字を処理しないため、プログラムが perl に到達する前にゴミ箱に入れられていることだと思います。これは明らかにあなたのプログラムではないため、おそらくあなたに届く前にゴミ箱に捨てられました。

ツール チェーン全体で Unicode が正しく処理されるまでは、ASCII 以外の文字が保持されるようにエンコードするように注意する必要があります。それは苦痛であり、単純な解決策は存在しません。Unicode 文字を安全に埋め込む方法については、perl のマニュアルを参照してください。

于 2012-08-16T05:16:31.210 に答える