
package com.srini;

import org.jsoup.Jsoup;
import org.jsoup.helper.Validate;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Example program to list links from a URL.
 */
public class WN 
{
	
	
	public ArrayList<Definition> getter(String word) throws IOException
	{
		ArrayList<Definition> data=new ArrayList<Definition>();
		String url="http://wordnetweb.princeton.edu/perl/webwn?s="+word;
		Document doc = Jsoup.connect(url).get();
		Elements ele=doc.select("li");
		for(Element e:ele)
		{
			Definition d=new Definition();
			String t=e.text()+"";
			if(t.contains("(n)"))
			{
				d.type="noun";
			}
			else if(t.contains("(v)"))
			{
				d.type="verb";
			}
			else if(t.contains("(adj)"))
			{
				d.type="adjective";
			}
			if(t.contains("(adv)"))
			{
				d.type="adverb";
			}
			int j=0;
			 Pattern pattern1 = Pattern.compile("\\)([^)]+)\\(");
			    Matcher matcher1 = pattern1.matcher(t);
			    while (matcher1.find()) {
			    	if(j==0)
			        {
			    		d.synonyms=matcher1.group(1).toString();
			    		//System.out.println(matcher1.group(1));
			        }
			    	j++;
			    }
			    int i=0;
				 Pattern pattern = Pattern.compile("\\(([^)]+)\\)");
				    Matcher matcher = pattern.matcher(t);
				    while (matcher.find()) {
				    	if(i==1)
				        {
				    		d.meaning=matcher.group(1).toString();
				    		//System.out.println(matcher.group(1));
				        }
				    	i++;
				    }
				    data.add(d);
			//System.out.println(e.text()+"");
		}
		
		return data;
	}
	public static void main(String[] args) throws IOException 
	{
       	//url contains the predefined wordnet search url string without the search word itself
    //	String url="http://wordnetweb.princeton.edu/perl/webwn?s=";
    ArrayList<Definition> stuff;
	WN w=new WN();   
    stuff=w.getter("car");
    for(Definition d:stuff)
    {
    	System.out.println("car");
    	System.out.println("part of speech: "+d.type);
    	System.out.println("definition: "+d.meaning);
    	System.out.println("synonyms: "+d.synonyms);
    	System.out.println("");
    }
    }
}
@@ -297,61 +297,8 @@
 n;%0A%0A
-/**%0A * Example program to list links from a URL.%0A */%0A
 publ
@@ -316,12 +316,8 @@
  %0A%7B%0A
-%09%0A%09%0A
 %09pub
@@ -1139,58 +1139,8 @@
 ();%0A
-%09%09%09    %09%09//System.out.println(matcher1.group(1));%0A
 %09%09%09 
@@ -1579,569 +1579,6 @@
 %0A%09%7D%0A
-%09public static void main(String%5B%5D args) throws IOException %0A%09%7B%0A       %09//url contains the predefined wordnet search url string without the search word itself%0A    //%09String url=%22http://wordnetweb.princeton.edu/perl/webwn?s=%22;%0A    ArrayList%3CDefinition%3E stuff;%0A%09WN w=new WN();   %0A    stuff=w.getter(%22car%22);%0A    for(Definition d:stuff)%0A    %7B%0A    %09System.out.println(%22car%22);%0A    %09System.out.println(%22part of speech: %22+d.type);%0A    %09System.out.println(%22definition: %22+d.meaning);%0A    %09System.out.println(%22synonyms: %22+d.synonyms);%0A    %09System.out.println(%22%22);%0A    %7D%0A    %7D%0A
 %7D
+%0A

Update WN.java