how to find POS

Help
Anonymous
2003-09-05
2004-01-07
  • Anonymous

    Anonymous - 2003-09-05

    Can the JWNL find the POS of word?
    Example  "President" can get 'NOUN'
                 "was " can get 'VERB'

    I use methods like:                 
       POS.initialize();
       POS.getPOSForKey("President");

    but when i run my program, occur some error
       net.didion.jwnl.JWNLRuntimeException: DATA_EXCEPTION_004
            at net.didion.jwnl.data.POS.getPOSForKey(Unknown Source)
            at JwnlTest.main(JwnlTest.java:21)

    has anyone used?   Thanks

     
    • Anonymous

      Anonymous - 2003-09-08

      hi,
      i was also trying to get POS.
      Unfortunately, i too landed in the  same problem.

        But it is working fine when i checked with the following code.
        IndexWord wd=Dictionary.getInstance().getIndexWord(POS.VERB,"accomplish");
      System.out.println(wd.getPOS());

      If u trace out the problem, do mail me.
              
                -bye.
                    -purna.

       
      • Yaroslav Bulatov

        The question by itself is not well-posed. Consider for instance word "bend". It is often used as noun as it is as verb. Insteat what you want is a polysemy count for each part of speech possibility for given word. The code below will produce lines like "turn:12,26,0,0" meaning that turn has 12 meanings as noun, 26 as verb, 0 as adjective and 0 as adverb:

        import java.io.*;
        import java.util.*;

        import net.didion.jwnl.*;
        import net.didion.jwnl.data.*;
        import net.didion.jwnl.dictionary.*;
        import net.didion.jwnl.dictionary.Dictionary;

        public class WSJTest {
          public static void main(String[] args) throws Exception {
            JWNL.initialize(new FileInputStream(args[0]));
            String[] words = new String[]{"bend","cat","clown","meet","bend",
                "turn","proceed","prevent","proposal","frolic"};
            for (int i = 0; i < words.length; ++i) {
              System.out.print(words[i]+":");
              int[] p = polysemy(words[i]);
              for (int j = 0; j < p.length; ++j)
                System.out.print(p[j]+((j<p.length-1)?",":"\r\n"));
            }
          }
         
          /**
           * Returns list of polysemy counts for word.
           * result[0] is count for noun, 1 for verb, 2 for adjective, 3 for adverb
           * @param word word to examine
           * @return
           */
          public static int[] polysemy(String word) throws JWNLException {
            int[] polysemies = new int[4];
            Dictionary d = Dictionary.getInstance();
            IndexWord noun_form = d.getIndexWord(POS.NOUN, word);
            polysemies[0] = (noun_form==null)?0:noun_form.getSenses().length;
            IndexWord verb_form = d.getIndexWord(POS.VERB, word);
            polysemies[1] = (verb_form==null)?0:verb_form.getSenses().length;
            IndexWord adj_form = d.getIndexWord(POS.ADJECTIVE, word);
            polysemies[2] = (adj_form==null)?0:adj_form.getSenses().length;
            IndexWord adv_form = d.getIndexWord(POS.ADVERB, word);
            polysemies[3] = (adv_form==null)?0:adv_form.getSenses().length;
            return polysemies;
          }
        }

         
    • John Didion

      John Didion - 2003-11-11

      The method Purna described is the correct way to the the part of speech for a word.

       

Log in to post a comment.