【问题标题】:how to use opennlp on eclipse如何在eclipse上使用opennlp
【发布时间】:2014-05-07 07:19:24
【问题描述】:

我正在尝试安装 opennlp,以便我可以将它用于我的 nlp 课程项目。 我的 Windows 8 电脑上有 Eclipse 开普勒 我阅读了很多关于如何安装它的在线页面,但没有运气 我读 http://sharpnlp.codeplex.com/discussions/263620 http://sharpnlp.codeplex.com/discussions/263620 以及网站不允许我添加的许多其他链接

但他们似乎都没有帮助我 我所做的如下:

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")

这基本上就是我所做的一切 但我无法在 Eclipse 开普勒上使用 opennlp 有什么建议吗??

我正在尝试从字符串中提取城市名称,然后我会将其转换为从文件中提取它们没有错误或异常运行按钮不提供运行 java 应用程序选项 导入 java.io.FileInputStream; 导入 java.io.FileNotFoundException; 导入 java.io.IOException; 导入 java.io.InputStream; 导入 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();
    }
}

}

【问题讨论】:

    标签: java eclipse maven opennlp


    【解决方案1】:

    我认为你有很多不相关的问题。让我们从头开始:

    JAVA_HOME 未设置

    您的 JAVA_HOME 未设置,您自行正确修复。好的!但是,我认为如果您想在 Eclipse 中使用 OpenNLP,这并不是绝对必要的。

    C:\Users\lina>set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_51
    

    JAR 文件丢失

    Unable to access 表示 JAR 文件不在其中。文件夹C:\Users\lina&gt; 中没有名为opennlp-tools-1.5.0.jar 的文件。很容易修复:将 JAR 文件放在文件夹中;)

    C:\Users\lina>java -jar opennlp-tools-1.5.0.jar
    Error: Unable to access jarfile opennlp-tools-1.5.0.jar
    

    构建 OpenNLP

    然后您尝试构建 OpenNLP。我认为构建 OpenNLP 没有必要使用它。您得到的最后一个错误意味着您正在构建的项目的依赖项丢失。

    使用 OpenNLP

    由于您使用 Maven 和 Eclipse,因此使用 OpenNLP 应该很容易。在 Eclipse 上新建一个 Maven 项目,打开 pom.xml 文件并添加 OpenNLP 的 Maven 依赖项(您可以在 OpenNLP 的网站上找到它):

    <dependency>
      <groupId>org.apache.opennlp</groupId>
      <artifactId>opennlp-tools</artifactId>
      <version>1.5.3</version>
    </dependency>
    

    现在 Maven 将下载 OpenNLP 并将其放在 Eclipse 项目的路径中。你可以在之后使用它。

    我会选择这个解决方案。

    【讨论】:

    • 感谢您的回复.....但问题是我如何创建一个 Maven 项目我在我的 Eclipse 上看不到它......??
    • 某些 Eclipse 版本中缺少 Maven,必须安装。在您的 Eclipse 中转到 Help &gt; Eclipse Marketplace 并搜索 Maven。安装其中一个插件,我使用“Maven Integration for Eclipse”。然后您应该能够创建一个新的 Maven 项目(或将旧项目转换为 Maven)。
    • 我什么都能做……我用 main 创建了一个新类……我没有任何错误,但似乎无法运行我该怎么办……? ?
    • 好吧,“它似乎无法运行”是什么意思?有什么例外吗?课堂是什么样子的?
    • &lt;dependencies&gt;...&lt;/dependencies&gt;之间
    猜你喜欢
    • 2011-08-15
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多