如何循环遍历多个文件,保留基本名称以进行进一步处理?

我有多个需要标记的文本文件,POS和NER。我正在使用C& C标记并运行他们的教程,但我想知道是否有办法标记多个文件而不是逐个标记。 目前我正在对文件进行标记:
bin/tokkie --input working/tutorial/example.txt--quotes delete --output working/tutorial/example.tok
如下,然后是部分语音标记:
bin/pos --input working/tutorial/example.tok --model models/pos --output working/tutorial/example.pos
最后命名的实体识别:
bin/ner --input working/tutorial/example.pos --model models/ner --output working/tutorial/example.ner
我不确定如何创建一个循环来执行此操作并保持文件名与输入相同,但扩展名表示它具有标记。我正在考虑使用bash脚本或Perl来打开目录,但我不确定如何输入C& C命令以便脚本理解。 目前我手动完成它,至少可以说是非常耗时的!     
已邀请:
未经测试,可能需要一些目录修改。
use autodie qw(:all);
use File::Basename qw(basename);

for my $text_file (glob 'working/tutorial/*.txt') {
    my $base_name = basename($text_file, '.txt');
    system 'bin/tokkie',
        '--input'  => "working/tutorial/$base_name.txt",
        '--quotes' => 'delete',
        '--output' => "working/tutorial/$base_name.tok";
    system 'bin/pos',
        '--input'  => "working/tutorial/$base_name.tok",
        '--model'  => 'models/pos',
        '--output' => "working/tutorial/$base_name.pos";
    system 'bin/ner',
        '--input'  => "working/tutorial/$base_name.pos",
        '--model'  => 'models/ner',
        '--output' => "working/tutorial/$base_name.ner";
}
    
在Bash:
#!/bin/bash
dir='working/tutorial'
for file in "$dir"/*.txt
do
    noext=${file/%.txt}

    bin/tokkie --input "$file" --quotes delete --output "$noext.tok"

    bin/pos --input "$noext.tok" --model models/pos --output "$noext.pos"

    bin/ner --input "$noext.pos" --model models/ner --output "$noext.ner"

done
    

要回复问题请先登录注册