Nlp 获取单词的基本形式?

Nlp 获取单词的基本形式?,nlp,semantics,wordnet,Nlp,Semantics,Wordnet,我正在为我的项目使用java wordnet库(jwnl)。我需要在处理之前找到单词的基本形式。例如,如果我给出“send”,基本形式的单词应该是“send”。与“dispatched”类似,基本形式的单词应该是“dispatch”。我已经阅读了jwnl文档,但它让我感到困惑。请为我提供一段查找基本单词的代码。提前感谢。我建议尝试使用波特词干分析器算法而不是wordnet,您可以在大多数语言中找到实现- 这应该可以满足您的需要我使用了JAWS,因为我发现它比JWNL更好,然后检查这段代码以找到它

我正在为我的项目使用java wordnet库(jwnl)。我需要在处理之前找到单词的基本形式。例如,如果我给出“send”,基本形式的单词应该是“send”。与“dispatched”类似,基本形式的单词应该是“dispatch”。我已经阅读了jwnl文档,但它让我感到困惑。请为我提供一段查找基本单词的代码。提前感谢。

我建议尝试使用波特词干分析器算法而不是wordnet,您可以在大多数语言中找到实现-


这应该可以满足您的需要

我使用了JAWS,因为我发现它比JWNL更好,然后检查这段代码以找到它的基础和亮点

import java.io.*;
import edu.smu.tspell.wordnet.*;

/**
 * Displays word forms and definitions for synsets containing the word form
 * specified on the command line. To use this application, specify the word
 * form that you wish to view synsets for, as in the following example which
 * displays all synsets containing the word form "airplane":
 * <br>
 * java TestJAWS airplane
 */
public class start
{
    /**
     * Main entry point. The command-line arguments are concatenated together
     * (separated by spaces) and used as the word form to look up.
     */
    public static void main(String[] args)
    {
        while(true)
        {
            if (args.length == 0)
            {
                StringBuffer buffer = new StringBuffer();
                String wordForm = null;//"fast";//buffer.toString();
                System.out.print("\n");
                System.out.print("Enter your query: ");
                   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

                   try {
                     wordForm = br.readLine();
                   } catch (IOException e) {
                     System.out.println("Error!");
                     System.exit(1);
                   }
                   System.out.println("Your looking for: " + wordForm);
                System.setProperty("wordnet.database.dir", "/home/dell/workspace/wordnet/WordNet-3.0/dict");
                WordNetDatabase database = WordNetDatabase.getFileInstance();
                Synset[] synsets = database.getSynsets(wordForm);
                //  Display the word forms and definitions for synsets retrieved
                if (synsets.length > 0)
                {
                    System.out.println("The following synsets contain '" +
                            wordForm + "' or a possible base form " +
                            "of that text:");
                    for (int i = 0; i < synsets.length; i++)
                    {
                        System.out.println("");
                        String[] wordForms = synsets[i].getWordForms();
                        for (int j = 0; j < wordForms.length; j++)
                        {
                            System.out.print((j > 0 ? ", " : "") +
                                    wordForms[j]);
                        }
                        System.out.println(": " + synsets[i].getDefinition());
                    }
                }
                else
                {
                    System.err.println("No synsets exist that contain " +
                            "the word form '" + wordForm + "'");
                }
            }
            else
            {
                System.err.println("You must specify " +
                        "a word form for which to retrieve synsets.");
            }
        }
    }

}
import java.io.*;
导入edu.smu.tspell.wordnet.*;
/**
*显示单词形式和包含单词形式的语法集的定义
*在命令行上指定。要使用此应用程序,请指定单词
*要查看其语法集的窗体,如以下示例所示
*显示包含单词形式“飞机”的所有语法集:
*
*爪哇测试飞机 */ 公开课开始 { /** *主入口点。命令行参数连接在一起 *(用空格分隔)用作查找的单词形式。 */ 公共静态void main(字符串[]args) { while(true) { 如果(args.length==0) { StringBuffer=新的StringBuffer(); 字符串wordForm=null;//“fast”//buffer.toString(); 系统输出打印(“\n”); System.out.print(“输入您的查询:”); BufferedReader br=新的BufferedReader(新的InputStreamReader(System.in)); 试一试{ wordForm=br.readLine(); }捕获(IOE异常){ System.out.println(“错误!”); 系统出口(1); } System.out.println(“您的搜索:“+wordForm”); System.setProperty(“wordnet.database.dir”,“/home/dell/workspace/wordnet/wordnet-3.0/dict”); WordNetDatabase=WordNetDatabase.getFileInstance(); Synset[]synsets=database.getSynsets(wordForm); //显示检索到的语法集的单词形式和定义 如果(synsets.length>0) { System.out.println(“以下语法集包含”+ wordForm+“'或可能的基本形式”+ “在该案文中:”; for(int i=0;i0?,“:”)+ 词形[j]; } System.out.println(“:”+synsets[i].getDefinition()); } } 其他的 { System.err.println(“不存在包含”+ “单词形式“'+单词形式+””); } } 其他的 { System.err.println(“您必须指定”+ “检索语法集的单词形式。”); } } } }
实际上,我通过阅读jwnl的文档解决了这个问题。使用形态处理器,我可以获得单词的基本形式。例如,sent=>send,children=>child..etcList baseforms=dict.getmorphicalprocessor().lookupAllBaseForms(POS.VERB,“sent”);这是一个代码示例,使用它,您还可以找到单词的多种含义,而使用波特词干分析器,您可以得到您要查找的单词的基本形式。但是如果你想从中找到更高的意义,这段代码会有所帮助。