stanford parse bash script error - linux bash - java

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
如果 您 在 新加坡 只 能 前往 一 间 俱乐部 , 祖卡 酒吧 必然 是 您 的 不二 选择 。
作为 或许 是 新加坡 唯一 一 家 国际 知名 的 夜店 , 祖卡 既 是 一 个 公共 机构 , 也 是 狮城 年轻人 选择 进行 成人 礼等 庆祝 的 不二场所 。

As well as the : (colon), which should be a ; or a new line, the 'dir -d *' doesn't do what you think it does - the loop will just have one iteration, where file is a long string beginning with dir -d and with all your files afterwards. Also, you initially change to a path based on $file but then reuse the variable file in your loop, which is suspect. I'm having to guess somewhat about your intent, but it can be much simpler, e.g.:
#!/bin/bash
cd ~/path/to/whereever
for file in *
do
~/chinesesegmenter-2006-05-11/segment.sh ctb "$file" UTF-8
done
Even if you used the (more correct) version with backticks:
for file in `dir -d *`
... it would still qualify for a Useless Use of ls * Award ;)
Update: originally I forgot to quote $file, as pointed out in another answer

You could try:
for file in *
do
$HOME/segment.sh ctb "$file" UTF-8
done
So there were a couple of things to correct:
Don't use : after the for statement, use ; or a newline
Put quotation marks around the "$file" object to allow whitespaces in file name
If you want to use a command where you put 'dir -d *' you should use $(dir -d *) or angle quation marks instead ``

for file in 'dir -d *': do
You've put a colon instead of a semicolon.
If you want an easy debugging, you can add -x as an option to your shebang :
#!/bin/bash -x
The errors will be easier to spot.

Related

Cannot convert SVG file to PDF file use apache batik

I have a lot of SVG files that needed to be converted into PDF files. When I call Batik from console, I get the following error;
~\batik-1.10>java -jar batik-rasterizer-1.10.jar -d "D:/PDF" -m application/pdf
-dpi 1200 -w 9921 -h 14031 "D:/SVG/topic*.svg"
> About to transcode 1 SVG file(s)
> Converting d:/SVG/topic*.svg to D:\PDF\topic*.pdf ... ... error (SVGConverter.error.cannot.open.source)
> org.apache.batik.apps.rasterizer.SVGConverterException: Error: cannot open source topic*.svg java.io.IOException: Unable to make sense of URL for connection
at org.apache.batik.apps.rasterizer.SVGConverter.transcode(SVGConverter.java:968)
at org.apache.batik.apps.rasterizer.SVGConverter.execute(SVGConverter.java:717)
at org.apache.batik.apps.rasterizer.Main.execute(Main.java:937)
at org.apache.batik.apps.rasterizer.Main.main(Main.java:990)
What is the problem here?
I was able to recreate your problem (getting the IOException with message "Unable to make sense of URL for connection"), using your command as listed.
I think in this case, the easiest thing to do would be to eliminate the use of quotes on your source directory path, and execute the following:
java -jar batik-rasterizer-1.10.jar -d "D:/PDF" -m application/pdf -dpi 1200 -w 9921 -h 14031 D:/SVG/topic*.svg

Error building jpy `gcc: error: : No such file or directory`

I am trying to build jpy for using the SNAP API of the european space agency in my ubuntu 16.04 with anaconda. After setting all my java, jdk and jvm paths correctly, I executed
python setup.py build
and got the following error:
src/main/c/jni/org_jpy_PyLib.c:254:26: warning: unused variable ‘state’ [-Wunused-variable]
PyGILState_STATE state = PyGILState_Ensure();
^~~~~ gcc -pthread -shared -B /home/delgado/local/anaconda3/compiler_compat
-L/home/delgado/local/anaconda3/lib -Wl,-rpath=/home/delgado/local/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/src/main/c/jpy_module.o build/temp.linux-x86_64-3.6/src/main/c/jpy_diag.o build/temp.linux-x86_64-3.6/src/main/c/jpy_conv.o build/temp.linux-x86_64-3.6/src/main/c/jpy_compat.o build/temp.linux-x86_64-3.6/src/main/c/jpy_jtype.o build/temp.linux-x86_64-3.6/src/main/c/jpy_jarray.o build/temp.linux-x86_64-3.6/src/main/c/jpy_jobj.o build/temp.linux-x86_64-3.6/src/main/c/jpy_jmethod.o build/temp.linux-x86_64-3.6/src/main/c/jpy_jfield.o build/temp.linux-x86_64-3.6/src/main/c/jni/org_jpy_PyLib.o -L
-L/home/delgado/local/anaconda3/lib -ljvm -ldl -lpython3.6m -o build/lib.linux-x86_64-3.6/jpy.cpython-36m-x86_64-linux-gnu.so
-Xlinker -rpath gcc: error: : No such file or directory error: command 'gcc' failed with exit status 1
I do not know precisely which file is missing and why it is missing.
Using a built version of jpy in conda solved the issue. I suggest eg: conda install -c terradue jpy
hope this still helps somebody

find the jar that contains a given java class

I am trying to find which .jar detected this error so I can figure out the issue. This is running on hyperion server.
[2015-03-15T15:18:35.352+08:00] [Planning0] [WARNING] [] [oracle.EPMHSP.calcmgr_execution] [tid: 144] [userId: <anonymous>] [ecid: 00iRyJJB65hDOd5LzQL6iW000ly40016YL,0:1] [APP: PLANNING#11.1.2.0] [URI: /HyperionPlanning/faces/RunTimePromptTF/BgImage] [SRC_CLASS: com.hyperion.planning.adf.artifact.datacontrol.HspManageArtifactsDC] [SRC_METHOD: executeCalcScript] Error detected while attempting to run job Test_Rule [[
com.hyperion.planning.HspRuntimeException: Error detected while attempting to run job: Test_Rule.
at com.hyperion.planning.HspAsyncJobsManager.completeJobExceution(HspAsyncJobsManager.java:101)
at com.hyperion.planning.db.HspFMDBImpl$CalcMgrWrapper.runRule(HspFMDBImpl.java:10411)
at com.hyperion.planning.db.HspFMDBImpl.runHBRRule(HspFMDBImpl.java:2254)
at com.hyperion.planning.db.HspFMDBImpl.runCalcScript(HspFMDBImpl.java:2218)
at com.hyperion.planning.HyperionPlanningBean.runCalcScript(HyperionPlanningBean.java:4028)
at com.hyperion.planning.adf.artifact.datacontrol.HspManageArtifactsDC.executeCalcScript(HspManageArtifactsDC.java:3518)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at oracle.adf.model.binding.DCInvokeMethod.invokeMethod(DCInvokeMethod.java:677)
at oracle.adf.model.bean.DCBeanDataControl.invokeMethod(DCBeanDataControl.java:445)
If you are running linux/unix flavor, I usually find jars via something like the following bash script:
for i in $( find LIB_FOLDERS -iname *.jar | xargs ); do
( zipinfo $i | grep -i PATTERN ) && echo $i ; done
Where LIB_FOLDERS is the place where your jars are found, and PATTERN is a characteristic part of the name of the class you are looking for. This will print the names of all jar-files that match the pattern. Most IDEs allow you to "search for a class in the classpath" withouth all that command-line hassle, but I don't know if you have all sources loaded up in one.
Use JarScan. It's one of my favorite tools to search for a class buried in some jar in some directory. Works for any platform, simple and easy to use: https://java.net/projects/jarscan/pages/Tutorial/text
On linux systems I create ~/bin/findjar with the following, then chmod 700 and add ~/bin to my PATH:
#!/bin/bash
# Usage: findjar <classname or string to search for> [path to search under]
#
class=$1
path=$2
if [[ "$path" = "" ]]; then
path=.
fi
echo searching for $class in $path
for f in `find $path -name "*.jar"`; do
match=$(jar tf $f | grep $class);
if [[ -n "$match" ]]; then
echo
echo $f;
echo "$match"
fi;
done

Running word count on hadoop

MY HADOOP started on single node .
But while running word count programm it shows following error.
What may be the problem ?
hduser#reshmi-Inspiron-1545:~/hadoop-1.0.4$hadoop-examples-1.0.4.jar wordcount
/home/hduser/hadoop-1.0.4/dft /home/hduser/hadoop-1.0.4/dft-output
/home/hduser/hadoop-1.0.4/hadoop-examples-1.0.4.jar: line 1: $'PK\003\004':command not found
/home/hduser/hadoop-1.0.4/hadoop-examples-1.0.4.jar: line 2: syntax error near unexpected token `)'
/home/hduser/hadoop-1.0.4/hadoop-examples-1.0.4.jar: line 2: `)CA META-INF/��PK'
hduser#reshmi-Inspiron-1545:~/hadoop-1.0.4$ ^C
hduser#reshmi-Inspiron-1545:~/hadoop-1.0.4$ cd ..
hduser#reshmi-Inspiron-1545:~$ /hadoop-1.0.4 hadoop-examples-1.0.4.jar wordcount
/home/hduser/hadoop-1.0.4/dft /home/hduser/hadoop-1.0.4/dft-output
bash: /hadoop-1.0.4: No such file or directory
hduser#reshmi-Inspiron-1545:~$ ^C
You need to use the hadoop script in the bin folder and the jar sub command to invoke your job, try this:
hduser#reshmi-Inspiron-1545:~$ cd ~/hadoop-1.0.4
hduser#reshmi-Inspiron-1545:~/hadoop-1.0.4$ bin/hadoop jar hadoop-examples-1.0.4.jar \
wordcount /home/hduser/hadoop-1.0.4/dft \
/home/hduser/hadoop-1.0.4/dft-output
I'm also assuming from your input and output paths that your hadoop is configured for local mode (as the paths are local paths: /home/hduser)

Why is CLASSPATH prefixed with JDK path?

While trying to build a library that uses javah, I ran into a classpath issue. Apparently, the classpath is prefixed with the JDK path: please notice the final search path is wrong. How should I do instead?
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ CLASSPATH=$PWD javah -o javasasl.h -jni -verbose Sasl
error: cannot access Sasl
class file for Sasl not found
javadoc: error - Class Sasl not found.
[ Search Path: /usr/java/jdk1.6.0_24/jre/lib/resources.jar:/usr/java/jdk1.6.0_24/jre/lib/rt.jar:/usr/java/jdk1.6.0_24/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0_24/jre/lib/jsse.jar:/usr/java/jdk1.6.0_24/jre/lib/jce.jar:/usr/java/jdk1.6.0_24/jre/lib/charsets.jar:/usr/java/jdk1.6.0_24/jre/lib/modules/jdk.boot.jar:/usr/java/jdk1.6.0_24/jre/classes//home/elmarco/src/sasl/java/CyrusSasl ]
elmarco#makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ ls Sasl.java
Sasl.java
Thanks for your help!
(this is jdk1.6.0_24 on Fedora 14)
I usually avoid the CLASSPATH environment variable. This should work (and maybe without a problem):
javah -classpath .;<your-path> -o javasasl.h -jni -verbose Sasl
If don't need nothing but the local path, then you don't have to specify a -classpath option, . is the default value.
Note - you have to compile Sasl.java first. javah expects a class file. (Getting started)
I think it's simply a bug in how the javah outputs its actual classpath. What happens is that it has a bunch of places where it searches for built-in classes, and apart from them, it also uses the stuff in $CLASSPATH. When it prints the actual classpath used, they do something like this (pseudo code, assuming implicitEntries is a list of builtin classpath entries, and explicitEntries is a list of the the directories specified in $CLASSPATH):
print implicitEntries.join(pathSeparator) + explicitEntries.join(pathSeparator)
where it should have been
print implicitEntries.join(pathSeparator) + pathSeparator + explicitEntries.join(pathSeparator)
The following works fine for me:
$ ls
Sasl.class Sasl.java
$ javah -classpath . -o javasasl.h -jni -verbose Sasl [ Search Path: /usr/java/jdk1.6.0/jre/lib/resources.jar:/usr/java/jdk1.6.0/jre/lib/rt.jar:/usr/java/jdk1.6.0/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0/jre/lib/jsse.jar:/usr/java/jdk1.6.0/jre/lib/jce.jar:/usr/java/jdk1.6.0/jre/lib/charsets.jar:/usr/java/jdk1.6.0/jre/classes/. ]
[Creating file javasasl.h]
[search path for source files: [.]]
[search path for class files: [/usr/java/jdk1.6.0/jre/lib/resources.jar, /usr/java/jdk1.6.0/jre/lib/rt.jar, /usr/java/jdk1.6.0/jre/lib/sunrsasign.jar, /usr/java/jdk1.6.0/jre/lib/jsse.jar, /usr/java/jdk1.6.0/jre/lib/jce.jar, /usr/java/jdk1.6.0/jre/lib/charsets.jar, /usr/java/jdk1.6.0/jre/classes, /usr/java/jdk1.6.0/jre/lib/ext/dnsns.jar, /usr/java/jdk1.6.0/jre/lib/ext/localedata.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunpkcs11.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunjce_provider.jar, .]]
[loading ./Sasl.class]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Throwable.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]
[done in 585 ms]
$ ls
javasasl.h Sasl.class Sasl.java
Now, since the header file generation doesn't seem to work for you... are you sure you have Sasl.class in the current directory? javah works with byte code files, not Java source files.
You show here, that the source file is available ...
(mingw32 *%)$ ls Sasl.java
Sasl.java
but missing is the class file (Sasl.class).
error: cannot access Sasl
class file for Sasl not found
Compile it first.

Categories

Resources