问题
I am trying to install opennlp so i can use it for my nlp course project. I have eclipse kepler on my windows 8 computer i read so many online pages about how to install it but no luck I read http://sharpnlp.codeplex.com/discussions/263620 http://sharpnlp.codeplex.com/discussions/263620 and many other links that the website won't allow me to add
but non of them seems to help me what i did is the following:
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.
C:\Users\lina>mvn --version
Error: JAVA_HOME not found in your environment.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
C:\Users\lina>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
C:\Users\lina>mvn --version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)
Maven home: C:\Apache24\apache-maven-3.2.1\bin\..
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_51\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"
C:\Users\lina>java -jar opennlp-tools-1.5.0.jar
Error: Unable to access jarfile opennlp-tools-1.5.0.jar
C:\Users\lina>set opennlp_home=c:\apache-opennlp-1.5.3
C:\>cd ikvm-7.2.4630.5/bin
C:\ikvm-7.2.4630.5\bin>ikvmc -target:library -assembley:opennlp opennlp-maxent-3.0.3.jar jwnl-1.3.3.jar opennlp-tools-1.5.3.jar
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/
fatal error IKVMC5022: Unrecognized option: -assembley:opennlp
C:\ikvm-7.2.4630.5\bin>ikvmc -target:library -assembly:opennlp opennlp-maxent-3.0.3.jar jwnl-1.3.3.jar opennlp-tools-1.5.3.jar
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/
note IKVMC0002: Output file is "opennlp.dll"
warning IKVMC0105: Unable to compile class "opennlp.tools.util.ext.OSGiExtension Loader" (missing class "org.osgi.framework.BundleActivator")
warning IKVMC0100: Class "opennlp.tools.util.ext.OSGiExtensionLoader" not found
warning IKVMC0111: Emitted java.lang.NoClassDefFoundError in "opennlp.tools.util.ext.ExtensionLoader.instantiateExtension(Ljava.lang.Class;Ljava.lang.String;)Ljava.lang.Object;" ("opennlp.tools.util.ext.OSGiExtensionLoader")
thats basically everything i did and yet i can't work with opennlp on eclipse kepler any suggestions..??
I am trying to extract city names from a string then i will convert it to extract them from a file There are no errors or exceptions the run button does not provide run java application option import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import org.xml.sax.SAXException;
public class CityFinder {
public String Tokens[];
public static void main(String[] args) throws IOException, SAXException, CityFinder {
CityFinder toi = new CityFinder();
String cnt;
cnt="John is planning to specialize in Electrical Engineering in UC Berkley and pursue a career with IBM.";
toi.tokenization(cnt);
String cities = toi.namefind(toi.Tokens);
String org = toi.orgfind(toi.Tokens);
System.out.println("City name is : "+cities);
System.out.println("organization name is: "+org);
}
public String namefind(String cnt[]) {
InputStream is;
TokenNameFinderModel tnf;
NameFinderME nf;
String sd = "";
try {
is = new FileInputStream("en-ner-location.bin");
tnf = new TokenNameFinderModel(is);
nf = new NameFinderME(tnf);
Span sp[] = nf.find(cnt);
String a[] = Span.spansToStrings(sp, cnt);
StringBuilder fd = new StringBuilder();
int l = a.length;
for (int j = 0; j < l; j++) {
fd = fd.append(a[j] + "\n");
}
sd = fd.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sd;
}
public String orgfind(String cnt[]) {
InputStream is;
TokenNameFinderModel tnf;
NameFinderME nf;
String sd = "";
try {
is = new FileInputStream("en-ner-organization.bin");
tnf = new TokenNameFinderModel(is);
nf = new NameFinderME(tnf);
Span sp[] = nf.find(cnt);
String a[] = Span.spansToStrings(sp, cnt);
StringBuilder fd = new StringBuilder();
int l = a.length;
for (int j = 0; j < l; j++) {
fd = fd.append(a[j] + "\n");
}
sd = fd.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sd;
}
public void tokenization(String tokens) {
InputStream is;
TokenizerModel tm;
try {
is = new FileInputStream("en-token.bin");
tm = new TokenizerModel(is);
Tokenizer tz = new TokenizerME(tm);
Tokens = tz.tokenize(tokens);
// System.out.println(Tokens[1]);
} catch (IOException e) {
e.printStackTrace();
}
}
}
回答1:
I think you have a lot of unrelated problems. Let's start from the top:
JAVA_HOME was not set
Your JAVA_HOME was not set, which you fixed correctly on your own. Good! However, I think if you want to use OpenNLP in Eclipse this is not strictly necessary.
C:\Users\lina>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
JAR file is missing
Unable to access
means the JAR file is not in there. There is no file called opennlp-tools-1.5.0.jar
in the folder C:\Users\lina>
. It's easy to fix: put the JAR file in the folder ;)
C:\Users\lina>java -jar opennlp-tools-1.5.0.jar
Error: Unable to access jarfile opennlp-tools-1.5.0.jar
Build OpenNLP
Then you try to build OpenNLP. I think building OpenNLP is not necessary to use it. The last error your get means that a dependency of the project you are building is missing.
Using OpenNLP
Since you use Maven and Eclipse it should be easy to use OpenNLP. Create a new Maven project on Eclipse, open the pom.xml
file and add the Maven dependency for OpenNLP (as you can find it on the website of OpenNLP):
<dependency>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-tools</artifactId>
<version>1.5.3</version>
</dependency>
Now Maven will download OpenNLP and put it on the path of your Eclipse project. you can use it afterwards.
I would go for this solution.
来源:https://stackoverflow.com/questions/23511243/how-to-use-opennlp-on-eclipse