отношения в сети

как создать более общие, менее общие отношения и отношения эквивалентности из wordnet?

Сходство wordnet в RitaWordnet дает число вроде -1,0, 0,222 или 1,0, но как прийти к более общим, менее общим отношениям между словами? какой инструмент был бы идеальным для этого? пожалуйста, помогите мне

я получаю java.lang.NullPointerException после того, как он напечатает «холонимы»

package wordnet;

import rita.wordnet.RiWordnet;

public class Main {
    public static void main(String[] args) {
        try {
            // Would pass in a PApplet normally, but we don't need to here
            RiWordnet wordnet = new RiWordnet();
            wordnet.setWordnetHome("/usr/share/wordnet/dict");
            // Demo finding parts of speech
            String word = "first name";
            System.out.println("\nFinding parts of speech for " + word + ".");
            String[] partsofspeech = wordnet.getPos(word);
            for (int i = 0; i < partsofspeech.length; i++) {
                System.out.println(partsofspeech[i]);
            }

            //word = "eat";
            String pos = wordnet.getBestPos(word);
            System.out.println("\n\nDefinitions for " + word + ":");
            // Get an array of glosses for a word
            String[] glosses = wordnet.getAllGlosses(word, pos);
            // Display all definitions
            for (int i = 0; i < glosses.length; i++) {
                System.out.println(glosses[i]);
            }

            // Demo finding a list of related words (synonyms)
            //word = "first name";
            String[] poss = wordnet.getPos(word);
            for (int j = 0; j < poss.length; j++) {
                System.out.println("\n\nSynonyms for " + word + " (pos: " + poss[j] + ")");
                String[] synonyms = wordnet.getAllSynonyms(word, poss[j], 10);
                for (int i = 0; i < synonyms.length; i++) {
                    System.out.println(synonyms[i]);
                }
            }

            // Demo finding a list of related words
            // X is Hypernym of Y if every Y is of type X
            // Hyponym is the inverse
            //word = "nurse";
            pos = wordnet.getBestPos(word);
            System.out.println("\n\nHyponyms for " + word + ":");
            String[] hyponyms = wordnet.getAllHyponyms(word, pos);
            //System.out.println(hyponyms.length);
            //if(hyponyms!=null)
            for (int i = 0; i < hyponyms.length; i++) {


                System.out.println(hyponyms[i]);
            }

            System.out.println("\n\nHypernyms for " + word + ":");
            String[] hypernyms = wordnet.getAllHypernyms(word, pos);
            //if(hypernyms!=null)
            for (int i = 0; i < hypernyms.length; i++) {
                System.out.println(hypernyms[i]);
            }

               System.out.println("\n\nHolonyms for " + word + ":");

            String[] holonyms = wordnet.getAllHolonyms(word, pos);
            //if(holonyms!=null)
            for (int i = 0; i < holonyms.length; i++) {
                System.out.println(holonyms[i]);
            }

              System.out.println("\n\nmeronyms for " + word + ":");
            String[] meronyms = wordnet.getAllMeronyms(word, pos);
            if(meronyms!=null)
            for (int i = 0; i < meronyms.length; i++) {
                System.out.println(meronyms[i]);
            }
              System.out.println("\n\nAntonym for " + word + ":");
            String[] antonyms = wordnet.getAllAntonyms(word, pos);
            if(antonyms!=null)
            for (int i = 0; i < antonyms.length; i++) {
                System.out.println(antonyms[i]);
            }


            String start = "cameras";
            String end = "digital cameras";
            pos = wordnet.getBestPos(start);

            // Wordnet can find relationships between words
            System.out.println("\n\nRelationship between: " + start + " and " + end);
            float dist = wordnet.getDistance(start, end, pos);
            String[] parents = wordnet.getCommonParents(start, end, pos);
            System.out.println(start + " and " + end + " are related by a distance of: " + dist);

            // These words have common parents (hyponyms in this case)
            System.out.println("Common parents: ");
            if (parents != null) {
                for (int i = 0; i < parents.length; i++) {
                    System.out.println(parents[i]);
                }
            }

            //wordnet.
            // System.out.println("\n\nHypernym Tree for " + start);
            // int[] ids = wordnet.getSenseIds(start,wordnet.NOUN);
            // wordnet.printHypernymTree(ids[0]);
        } catch (Exception e) {
            e.printStackTrace();
        }
     }
  }

person karthi    schedule 20.10.2010    source источник
comment
Вы можете попробовать JWI (интерфейс MIT Java Wordnet). Он прост в использовании, чтобы получить голономию или гиперним, вам просто нужно выполнить итерацию с помощью итератора! projects.csail.mit.edu/jwi   -  person Nervo Verdezoto    schedule 29.11.2010


Ответы (2)


Wordnet Rita предоставляет API для поиска гипернимов (более общих), гипонимов (менее общих) и синонимов. Проверьте следующую страницу для деталей: -

http://www.rednoise.org/rita/wordnet/documentation/index.htm

чтобы узнать обо всех этих терминах (гиперонимы и т. д.), посетите страницу википедии wordnet.

person deovrat singh    schedule 20.10.2010

Вы можете попробовать разобрать базы данных самостоятельно. Это будет не так сложно. 1) Найдите слово в одном из следующих файлов: index.noun, index.verb, index.adj и index.noun, 2) извлеките идентификаторы его синсетов («смыслов») и для каждого синсета перейдите в data.noun , data.verb, data.adj или data.noun и извлеките идентификатор синсета его гиперонимов или гипонимов. Затем найдите эти идентификаторы синсетов для синонимов и блеска. Это достаточно просто, если вы используете регулярные выражения.

Базы данных (например, index.verb) можно найти в одном из каталогов Wordnet, который можно загрузить с . здесь. Если вы используете Linux, есть также хорошая программа командной строки, которая сделает всю работу за вас, но если вы хотите интегрировать ее в код Java, боюсь, вам придется выполнять весь синтаксический анализ самостоятельно. Вам также может быть интересна эта ссылка. Надеюсь это поможет:)

PS: вы также можете попробовать NLTK (написано на Python)

person Siato    schedule 21.10.2010