1

wordnet から、より一般的で一般的でない同値関係を生成する方法は?

RitaWordnet の wordnet の類似度は、-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();
        }
     }
  }
4

2 に答える 2

2

Rita ワードネットは、上位語 (より一般的)、下位語 (一般的ではない)、同義語を検索するための API を提供します。詳細は下記ページをご確認ください。

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

これらすべての用語 (ハイパーニムなど) について知るには、wordnet のウィキペディア ページを参照してください。

于 2010-10-20T12:59:34.077 に答える
0

データベースを自分で解析してみることができます。それほど難しいことではありません。1) 次のファイルのいずれかで単語を検索します: index.noun、index.verb、index.adj、および index.noun、2) その synset (「センス」) の ID を抽出し、各 synset について data.noun に移動します。 、data.verb、data.adj、または data.noun を検索し、その上位語または下位語の synset id を抽出します。次に、これらの synset id で類義語とグロスを検索します。正規表現を使えばかなり簡単です。

データベース (例: index.verb) は、ここからダウンロードできる Wordnet のディレクトリの 1 つにあります。Linux を使用している場合は、その作業を行う優れたコマンドライン プログラムもありますが、それを Java コードに統合する場合は、すべての解析を自分で行う必要があります。このリンクも興味深いかもしれません。お役に立てれば:)

PS: NLTK (Python で記述) を試すこともできます。

于 2010-10-21T15:34:05.310 に答える