Can someone help me check my bash script? i'm trying to feed a directory of .txt files to the stanford parser (http://nlp.stanford.edu/software/pos-tagger-faq.shtml) but i can't get it to work. i'm working on ubuntu 10.10
the loop is working and reading the right files with:
#!/bin/bash -x
cd $HOME/path/to
for file in 'dir -d *'
do
# $HOME/chinesesegmenter-2006-05-11/segment.sh ctb $file UTF-8
echo $file
done
but with
#!/bin/bash -x
cd $HOME/yoursing/sentseg_zh
for file in 'dir -d *'
do
# echo $file
$HOME/chinesesegmenter-2006-05-11/segment.sh ctb $file UTF-8
done
i'm getting this error:
alvas@ikoma:~/chinesesegmenter-2006-05-11$ bash segchi.sh
Standard: CTB
File: dir
Encoding: -d
-------------------------------
Exception in thread "main" java.lang.NoClassDefFoundError: edu/stanford/nlp/ie/crf/CRFClassifier
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.ie.crf.CRFClassifier
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: edu.stanford.nlp.ie.crf.CRFClassifier. Program will exit.
the following command works:
~/chinesesegmenter-2006-05-11/segment.sh ctb ~/path/to/input.txt UTF-8
and output this
alvas@ikoma:~/chinesesegmenter-2006-05-11$ ./segment.sh ctb ~/path/to/input.txt UTF-8
Standard: CTB
File: /home/alvas/path/to/input.txt
Encoding: UTF-8
-------------------------------
Loading classifier from data/ctb.gz...done [1.5 sec].
Using ChineseSegmenterFeatureFactory
Reading data using CTBSegDocumentReader
Sequence tagging 7 documents
如果 您 在 新加坡 只 能 前往 一 间 俱乐部 , 祖卡 酒吧 必然 是 您 的 不二 选择 。
作为 或许 是 新加坡 唯一 一 家 国际 知名 的 夜店 , 祖卡 既 是 一 个 公共 机构 , 也 是 狮城 年轻人 选择 进行 成人 礼等 庆祝 的 不二场所 。
You could try:
for file in *
do
$HOME/segment.sh ctb "$file" UTF-8
done
So there were a couple of things to correct:
:
after the for statement, use ;
or a newline"$file"
object to allow whitespaces in file name'dir -d *'
you should use $(dir -d *)
or angle quation marks instead ``