получаване на основна форма на дума?

Използвам java wordnet библиотека (jwnl) за моя проект. Трябва да намеря основна форма на дума преди обработка. Например, ако дам „изпратено“, основната форма на думата трябва да бъде „изпрати“. подобно на „изпратен“ "основната дума трябва да бъде "изпращане". Прочетох документацията на jwnl, но ме обърква. Моля, предоставете ми част от кода за намиране на основната дума. Благодаря в очакване.


person KNsiva    schedule 17.02.2011    source източник


Отговори (2)


Използвах 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.");
            }
        }
    }

}
person yashodhan katte    schedule 21.05.2012
comment
с това можете също да намерите множество значения на думата, докато с porter stemmer ще получите основната форма на думите, които търсите. но ако искате да намерите по-висш смисъл от него, този код ще ви помогне. - person yashodhan katte; 21.05.2012

Бих предложил да опитате да използвате алгоритъм на Porter stemmer вместо wordnet, можете да намерите реализации на повечето езици - включително java тук

Това трябва да ви донесе това, което искате

person Amit Bens    schedule 01.03.2011
comment
Благодаря. Всъщност реших проблема, като прочетох документацията на jwnl. С помощта на морфологичен процесор мога да получа основна форма на дума. за например изпратено=›изпрати,деца=›дете..и т.н. - person KNsiva; 09.03.2011
comment
List baseforms = dict.getMorphologicalProcessor().lookupAllBaseForms(POS.VERB, sent);е пример за код - person KNsiva; 09.03.2011