我厌倦了这个:
for dir in /home/matthias/Workbench/SUTD/nytimes_corpus/NYTimesCorpus/2007/02/*/ for f in *.xml ; do echo $f | grep -q '_output.xml$' && continue # skip output files g="$(basename $f .xml)_output.xml" java -mx600m -cp /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/stanford-ner-3.5.1.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz -textFile $f -outputFormat inlineXML > $g done done
这是基于对这个问题的答案,但这并不奏效。
我有一个文件夹结构,在NYTimesCorpus目录中有一个目录2007 ,在这个目录01和02 ,等等…
然后在01内有01 ,…
将Windows CDROM驱动器视为阻止文件?
“&>”和“<&”令牌问题
用C ++在线文本文件读取数据
在每个这些terminal目录中都有许多我想应用脚本的.xml文件:
for f in *.xml ; do echo $f | grep -q '_output.xml$' && continue # skip output files g="$(basename $f .xml)_output.xml" java -mx600m -cp /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/stanford-ner-3.5.1.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz -textFile $f -outputFormat inlineXML > $g done
但是有很多不同的目录在每个目录中运行它都是一种罕见的折磨。 除了2007我还有2006和2005 ,所以理想的做法是运行一次,让程序自行导航。
我迄今为止的尝试都没有取得成功,也许你们中的一个人会知道如何做到这一点?
谢谢您的考虑。
UPDATE
textFile=./scrypt.sh outputFormat=inlineXML Loading classifier from /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz ... done [2.2 sec]. CRFClassifier tagged 71 words in 5 documents at 959.46 words per second. CRFClassifier invoked on Sun Apr 12 19:33:34 HKT 2015 with arguments: -loadClassifier /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz -textFile ./scrypt.sh -outputFormat inlineXML loadClassifier=/home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz
从正在运行的程序读取值
寻找一种方法来强制在Linux中进行简短的阅读
提升mmap性能与原生内存映射
我正在运行一个PHP脚本使用WAMP,在这种情况下,我怎么能从我的文档读取文件?
如何在C ++控制台应用程序中输出波兰语字符?
find是一个好的解决方案。 这听起来像所有的XML文件是在相同的目录深度,所以试试这个:
dir=/home/matthias/Workbench/SUTD/nytimes_corpus for f in $dir/NYTimesCorpus/*/*/*/*.xml; do [[ $f == *_output.xml ]] && continue # skip output files g="${f%.xml}_output.xml" java -mx600m -cp $dir/NER/stanford-ner-2015-01-30/stanford-ner-3.5.1.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier $dir/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz -textFile "$f" -outputFormat inlineXML > "$g" done
glob模式$dir/NYTimesCorpus/*/*/*/*.xml指定想要的xml文件恰好低于NYTimesCorpus的3个级别。 那是错误的深度,然后改变模式中*/的数量。
如果xml文件可以出现在不同的深度,使用find ,或在bash中使用:
shopt -s globstar nullglob for f in $dir/NYTimesCorpus/**/*.xml; do
参考
我会使用find因为它递归地工作:
find /path/to/xmls -type f ! -name '*_output.xml' -name '*.xml' -exec ./script.sh {} ;
为了更好的可读性,我将把每个文件上应该执行的动作保存到script.sh :
#!/bin/bash f="$1" g="${f%%.*}_output.xml" java -mx600m -cp /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/stanford-ner-3.5.1.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier /home/matthias/Workbench/SUTD/nytimes_corpus/NER/stanford-ner-2015-01-30/classifiers/english.all.3class.distsim.crf.ser.gz -textFile "$f" -outputFormat inlineXML > "$g"
并使其可执行:
chmod +x script.sh
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。