[Bluej-discuss] POS object type?

Jayna Raghwani jna_raghwani at hotmail.com
Wed Dec 5 12:34:28 GMT 2007


Hi All, 

I am doing an assignment for course learning to JAVA and we're doing it through the blueJ platform. The aim is to build a chatbot (eventually), and as part of this exercise we're using a WordNet package. This produces synonyms, hypernyms etc for a given word, anyway I wanted to test the one of the methods just to see how it works (if it treated "today?" differently from just "today". Below is a method to getHyponyms for a chosen word, but I don't know what I need to put in the POS parameter, can anyone help? I tried searching on the net, but the results were unsuccessful. Sorry the method is rather long...

Thanks

Jayna


    /**
     * Retrieve a list of words representing the hyponyms for every sense of the
     *  specified word and POS.
     * Hyponym is the specific term used to designate a member of a class. 
     * X is a hyponym of Y if X is a (kind of) Y . 
     *
     * @param pos The part of speech for the word
     * 
     * @param e The word to be looked up 
     * 
     * @return A list containing all the direct hyponyms of all senses of the 
     * specified word, assuming the given POS.
     */
    
    public List getHyponyms(POS pos, String e)
    Set hyponymSet = new HashSet();
        if (pos == POS.ADJECTIVE)
            System.err.println("Sorry, adjectives don't have hyponyms, " +
                "will return empty set");
        else {
            Word[] words;

            try {
                IndexWord word = d.lookupIndexWord(pos, e);
                if (word != null) {
                    //iterate over each sense of this word
                    for (int j = 1; j < word.getSenseCount() + 1; j++) {

                        Synset syn = word.getSense(j);

                        PointerTargetNodeList hyponyms = PointerUtils.getDirectHyponyms(syn);

                        if (hyponyms != null) {
                            //if this sense of the word has hyponyms, iterate over them
                            Iterator i = hyponyms.iterator();
                            while (i.hasNext()) {

                                PointerTargetNode targetNode = (PointerTargetNode) i.next();
                                //if this hyponym is just a string (lexical) 
                                //add it to the hyponym list
                                if (targetNode.isLexical()) {
                                    hyponymSet.add(targetNode.getWord().getLemma());

                                } else {
                                    // It's a synset rather than a word, 
                                    //so retrieve all the words and add them to the hyponym list
                                    words = targetNode.getSynset().getWords();
                                    for (int t = 0; t < words.length; t++) {
                                        hyponymSet.add(words[t].getLemma());

                                    }

                                }

                            }

                        }
                    }

                }

            } catch (JWNLException err) {
                err.printStackTrace();
            }
        }
        return new ArrayList(hyponymSet);
    }

_________________________________________________________________
Telly addicts unite!
http://www.searchgamesbox.com/tvtown.shtml
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bluej.org/pipermail/bluej-discuss/attachments/20071205/22e5fe7e/attachment.html 


More information about the bluej-discuss mailing list