2014-05-07 61 views
0

我正在嘗試安裝opennlp,因此我可以將它用於我的nlp課程項目。 我讓Eclipse在我的Windows 8開普勒計算機 我閱讀有關如何安裝它,但沒有運氣 我讀 http://sharpnlp.codeplex.com/discussions/263620 http://sharpnlp.codeplex.com/discussions/263620 等多個環節,該網站將不會允許這麼多的在線網頁我補充如何在eclipse上使用opennlp

但非他們似乎幫助我 我所做的是以下幾點:

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

多數民衆贊成基本上一切我沒有 ,但我不能在月食開普勒與opennlp工作任何建議.. ??

我想從字符串中提取城市名稱,然後我將其轉換爲從文件中提取它們沒有錯誤或異常運行按鈕不提供運行Java應用程序選項 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

我認爲你有很多無關的問題。讓我們從頂部開始:

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>中沒有名爲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文件,並添加Maven的依賴關係爲OpenNLP(你可以找到它OpenNLP的網站上):

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

現在Maven會下載OpenNLP,並把它的道路上你的Eclipse項目。你可以在之後使用它。

我會去這個解決方案。

+0

感謝您的回覆.....但問題是我如何創建一個maven項目,我無法看到它在我的月食....? – user3385409

+0

某些Eclipse版本中缺少Maven,必須安裝。在你的Eclipse中,進入'Help> Eclipse Marketplace'並搜索'Maven'。安裝其中一個插件,我使用「Maven Integration for Eclipse」。然後,您應該能夠創建一個新的Maven項目(或將舊項目轉換爲Maven)。 –

+0

我能夠做所有事情.....我創建了一個新的類與主...我沒有任何錯誤,但它似乎無法運行我應該怎麼做......? – user3385409