title: Java - Getting array of nouns with Wordnet and JWI
body: <p>I have a pretty easy question regarding WordNet and <a href="http://projects.csail.mit.edu/jwi/" rel="nofollow">MIT JWI</a> (Java API for accessing WordNet): I read a file into an array of strings, which I've split into words. How can I get a separate array of strings containing only the nouns using <a href="http://projects.csail.mit.edu/jwi/api/edu/mit/jwi/item/Word.html#getPOS%28%29" rel="nofollow">getPOS()</a>? Thanks!</p>
  
  <p>Example of what I've tried:</p>
  
  <p>public class test {</p>
  
  <pre><code>public static void main(String[] args) {
  
      String sentence1 = "The cat ate the fish";
  
      String[] s1Split = sentence1.split(" ");
  
      String wnhome = "C:/Program Files/WordNet/2.1";
      String path = wnhome + File.separator + "dict";
      URL url = new URL("file", null , path); 
      IDictionary dict = new Dictionary(url);
      dict.open();
  
  
      for (int i = 0; i &lt;s1.length; i++) {
                      //this is where I got confused, wanted to use something like:
                      //Word w = dict.getIndexWord(s1[i], ..) but I need a POS argument, 
                      //and I can't find another suitable method
                      //if w.getPOS() is a noun I would add it to a separate vector
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>EDIT: Just thought of another one - would it be reliable to use something like <code>w = dict.getIndexWord(s1[i], POS.NOUN)</code>, and if a noun doesn't exists, w will be null? Would this be something worth trying?</p>
  
  <p>EDIT2: So my question atm would be if there's any way I can transform a string (word) into a Wordnet object, so I can use getPOS() on it?</p>