【发布时间】:2012-08-16 05:05:10
【问题描述】:
查看这段 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 运行这段代码。
另一个小问题是第一行的“-CS”是什么意思。
谢谢大家。
【问题讨论】:
-
?不是 ?在文件中按照最初写入的方式标记,该文件可能由于某个地方的字符集转换失败而以某种方式损坏。 -
-CS表示 STDOUT、STDERR 和 STDIN 假定为 utf-8 -
@OmnipotentEntity 看到解释了吧?应该是重音e。我该如何修改?
-
@OmnipotentEntity 为什么会警告
Too late for "-CS" option at line 1?