Get Some Free Products at your Door Step. Just feed ur Address in dis Link...!!

Friday, June 7, 2013

MeaningFinder.java

import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

public class MeaningFinder
{
    public static void main(String ar[]) throws ClassNotFoundException, SQLException
    {
        System.out.println(MeaningFinder.spinner("What are you doing", 1));
        /*
        String word="do";
        ArrayList<Integer> al=new ArrayList();
        int index=0,index2;
        String source=WebPageAnalyser.fetchSource("oxforddictionaries.com/definition/"+word+"?q="+word);
        String subSource=source;
        //System.out.println(source);
        ArrayList def=new ArrayList();
        index=source.indexOf("<h3 class=\"partOfSpeech\"> <span class=\"partOfSpeech\">");
        System.out.println(index);
       
        if(index!=-1)
        {
            int i=index;
            while(i<source.length())
            {
                if(index!=-1)
                {
                    i=index;
                    System.out.println(i);
                    i++;
                    index2=source.indexOf("<h3 class=\"partOfSpeech\"> <span class=\"partOfSpeech\">",i);
                    if(index2<0) index2=source.length()-1;
                    subSource=source.substring(index,index2);
                    def.add("#"+StringExtractor.stringExtractor(subSource,"<h3 class=\"partOfSpeech\"> <span class=\"partOfSpeech\">" , '<'));
                //                StringExtractor.arrayListConvert(StringExtractor.stringArrayExtractor(WebPageAnalyser.fetchSource("oxforddictionaries.com/definition/"+word+"?q="+word),"<span class=\"definition\">",'<'));
                    def.addAll(StringExtractor.arrayListConvert(StringExtractor.stringArrayExtractor(subSource,"<span class=\"definition\">",'<')));

                    al.add(index);
                    index=index2;
                    if(index2==source.length()-1)break;
                }
                else break;
            }
        }
        ArrayList def2=new ArrayList();
        for(int i=0;i<def.size();i++)
        {
            String line=def.get(i).toString();
            if(line!="")
            {
                int j=0;
                for(;line.charAt(j)==' ';j++){}
                line=line.substring(j,line.length()-1);
                System.out.println(line);
                def2.add(line);
            }
        }

*/
//        String source=WebPageAnalyser.fetchSource("oxforddictionaries.com/definition/"+word+"?q="+word);
        //String sub1=source.indexOf(word)
    }
/**
<pre>
INPUT:String (word)
<b>well</b>
OUTPUT:Boolean
<b>true</b>

INPUT:String (word)
<b>eat</b>
OUTPUT:Boolean
<b>false</b>

</pre>
 */
    public static boolean adjectiveChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select adjectives from adjectives where adjectives='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
    /**
<pre>
INPUT:String (word)
<b>well</b>
OUTPUT:Boolean
<b>true</b>

INPUT:String (word)
<b>eat</b>
OUTPUT:Boolean
<b>false</b>
</pre>
 */
    public static boolean adverbChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {          
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="Select adverbs from adverbs where adverbs='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>an</b>
OUTPUT:Boolean
<b>true</b>

INPUT:String (word)
<b>the</b>
OUTPUT:Boolean
<b>false</b>
#Checks only a,an,the article
 </pre>
 */

    public static boolean articleChecker(String word)
    {
        if(word.equals("a")||word.equals("an")||word.equals("the"))return true;
        else return false;
    }
/**
<pre>
INPUT:String (sentence/source string)
<b>He plays well</b>
OUTPUT:Boolean
<b>true</b>

INPUT:String (sentence/Source string)
<b>He is a watchman</b>
OUTPUT:Boolean
<b>false</b>
 </pre>
 */
    public static boolean containsVerb(String source)
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Object ob[]=StringExtractor.seperater(source);
            for(int i=0;i<ob.length;i++)
            {
                //if(!MeaningFinder.helpingVerbChecker((String)ob[i]))
                flag=flag||MeaningFinder.verbChecker((String)ob[i]);
            }
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (sentence/source string)
<b>My name is Prem Bharti</b>
OUTPUT:Object[] (Sets of incorrect words)
<b>Prem
Bharti </b>
 </pre>
 */
    public static Object[] wrongSpellExtractor(String source)
    {
        Object words[]=StringExtractor.seperater(source);
        ArrayList al=new ArrayList();
        for(int i=0;i<words.length;i++)
            if(!MeaningFinder.isWordCorrect((String)words[i]))al.add((String)words[i]);
        return al.toArray();
    }
        public static Object[] findMeaning(String word)
    {
        return StringExtractor.stringArrayExtractor(WebPageAnalyser.fetchSource("oxforddictionaries.com/definition/"+word+"?q="+word),"<span class=\"definition\">",'<');
    }
    public static Object[] findMeaningf(String word) throws ClassNotFoundException, SQLException
    {
            Connection con= Misc.connect(null);
            Statement st=con.createStatement();
            String sqlxp="Select meaning from m"+word.toLowerCase().charAt(0)+" where words='"+word+"'";
            ResultSet rs=st.executeQuery(sqlxp);
            ArrayList a=new ArrayList();
                while(rs.next())  a.add(rs.getString("meaning"));
            return a.toArray();
    }
    public static Object[] findSynonym(String word)
    {
        String source=WebPageAnalyser.fetchSource("www.synonym.com/synonyms/"+word+"/");
        Object[] ob=StringExtractor.stringArrayExtractor(source, "span class=\"equals\">", '<');
        ArrayList a=new ArrayList();
        for(int i=0;i<ob.length;i++)
        {
            a.add((String)ob[i]);
        }
        return a.toArray();
    }
    public static Object[] findSynonymf(String word) throws ClassNotFoundException, SQLException
    {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlxp="Select synonyms from s"+word.toLowerCase().charAt(0)+" where words='"+word+"'";
            ResultSet rs=st.executeQuery(sqlxp);
            ArrayList a=new ArrayList();
                while(rs.next())  a.add(rs.getString("synonyms"));
            return a.toArray();
    }
    public static boolean helpingVerbChecker(String word)throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select hvs from hvs where hvs='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
    public static boolean isInterrogative(String word) throws ClassNotFoundException, SQLException
    {
        Connection con=Misc.connect(null);
        Statement st=con.createStatement();
        String sqlc="Select * from interro where interro='"+word+"'";
        ResultSet rs=st.executeQuery(sqlc);
        return rs.next();
    }
    public static boolean nounChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select nouns from nouns where nouns='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
       public static boolean singularPronounChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select spronouns from spronouns where spronouns='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
       public static boolean pluralPronounChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select ppronouns from ppronouns where ppronouns='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
    public static Object[] partsOfSpeech(String word)
    {
        return StringExtractor.stringArrayExtractor(WebPageAnalyser.fetchSource("oxforddictionaries.com/definition/"+word+"?q="+word),"<span class=\"partOfSpeech\">",'<');
    }
    public static Object[] partsOfSpeechf(String word) throws ClassNotFoundException, SQLException
    {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlxp="Select pos from p"+word.toLowerCase().charAt(0)+" where words='"+word+"'";
            ResultSet rs=st.executeQuery(sqlxp);
            ArrayList a=new ArrayList();
                while(rs.next())  a.add(rs.getString("pos"));
            return a.toArray();
    }
    public static boolean prepositionChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select prepositions from prepositions where prepositions='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
    public static boolean pronounChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select pronouns from pronouns where pronouns='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
    public static Object[] senseSynonym(String source,int CaretPosition) throws ClassNotFoundException, SQLException
    {
        ArrayList a = new ArrayList();
        try
        {
        String word;
        int i,j,k=0;
        int c;
        char ch=' ';
        if(CaretPosition!=0)
        {
            ch=source.charAt(CaretPosition-1);
            i=j=CaretPosition;
            while(i>0 && source.charAt(i-1)!=' ')  i--;
            while(j<source.length()-1 && source.charAt(j-1)!=' ')  j++;
            word=source.substring(i,j);
            c=word.toLowerCase().charAt(0);
            if((c>96 && k<123))
            {
                Object syno[]=MeaningFinder.findSynonymf(word);
                for(i=0;i<syno.length;i++)
                    a.add((String)syno[i]);
                return a.toArray();
            }
        }
        }catch(Exception e){}            // TODO add your handling code here:
        return a.toArray();
    }
    public static Object[] senseWord(String source,int CaretPosition) throws ClassNotFoundException, SQLException
    {
        ArrayList a = new ArrayList();
        try
        {
        Connection con=Misc.connect(null);
        Statement st=con.createStatement();
        String sqlc="",word;
        int i,j,k=0,counter=0;
        int c;
        char ch=' ';
        if(CaretPosition!=0)
        {
            ch=source.charAt(CaretPosition-1);
            i=j=CaretPosition;
            while(i>0 && source.charAt(i-1)!=' ')  i--;
            while(j<source.length()-1 && source.charAt(j-1)!=' ')  j++;
            word=source.substring(i,j);
            c=word.toLowerCase().charAt(0);
            if((c>96 && k<123))
            {
                sqlc="Select word from "+(char)c+" where word like '"+word+"%'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()&& counter<11)
                {
                    a.add(rs.getString("word"));
                    counter++;
                }
                return a.toArray();
            }
        }
        }catch(Exception e){}            // TODO add your handling code here:
        a.clear();
        return a.toArray();
    }

    public static Object[] senseWords(String source,int CaretPosition) throws ClassNotFoundException, SQLException
    {
        ArrayList a = new ArrayList();
        try
        {
        Connection con=Misc.connect(null);
        Statement st=con.createStatement();
        String sqlc="",word;
        int i,j,k=0,counter=0;
        int c;
        char ch=' ';
        if(CaretPosition!=0)
        {
            ch=source.charAt(CaretPosition-1);
            i=j=CaretPosition;
            while(i>0 && source.charAt(i-1)!=' ')  i--;
            while(j<source.length()-1 && source.charAt(j-1)!=' ')  j++;
            word=source.substring(i,j);
            c=word.toLowerCase().charAt(0);
            if((c>96 && k<123))
            {
                sqlc="Select word from allword where word like '"+word+"%'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()&& counter<11)
                {
                    a.add(rs.getString("word"));
                    counter++;
                }
                return a.toArray();
            }
        }
        }catch(Exception e){}            // TODO add your handling code here:
        a.clear();
        return a.toArray();
    }
/**
<pre>
INPUT:String (word)
<b>What are you doing</b>
OUTPUT:Object[] (list of Synonyms of word if it's Verb of any form)
<b>What are you accomplishing</b>
</pre>
 */
    public static String spinner(String Sentence,int k) throws ClassNotFoundException, SQLException
        {
            Connection con=Misc.connect(null);
            try
            {
            Statement st=con.createStatement();
            String sqlc="Select * from samesame";
            ResultSet rs=st.executeQuery(sqlc);
            while(rs.next())
            {
                String x=rs.getString("word");
                String y=rs.getString("samesame");
                if(Sentence.contains(x))Sentence=Sentence.replaceAll(x, y);
            }
        }catch(SQLException s){System.err.print(s.toString());}
        Object ob[]=StringExtractor.commaSeperater(Sentence);
            Sentence="";
            String word;
            try
            {
            for(int i=0;i<ob.length;i++)
            {
                word=(String) ob[i];
                if (MeaningFinder.verbChecker(word)) //confirms a word is verb
                {
                    Object syno[]=MeaningFinder.synonymExtractor(word); //extract list of synonym for that verb
                    if(k<syno.length)
                       ob[i]=(String)syno[k];
                    else ob[i]=(String)syno[1];
                    Sentence=Sentence+" "+ob[i];
                }
                else Sentence=Sentence+" "+(String)ob[i];
            }
            }catch(Exception abe){ return "error";};
            Sentence=Sentence.replace(" /n","");
            Sentence=Sentence.replace("\n ", " ");
            return Sentence.replace(" ,",",");
        }
   
    public static String spinnerVA(String Sentence,int k) throws ClassNotFoundException, SQLException
        {
            Connection con=Misc.connect(null);
            try
            {
            Statement st=con.createStatement();
            String sqlc="Select * from samesame";
            ResultSet rs=st.executeQuery(sqlc);
            while(rs.next())
            {
                String x=rs.getString("word");
                String y=rs.getString("samesame");
                if(Sentence.contains(x))Sentence=Sentence.replaceAll(x, y);
            }
        }catch(SQLException s){System.err.print(s.toString());}
        Object ob[]=StringExtractor.commaSeperater(Sentence);
            Sentence="";
            String word;
            try
            {
            for(int i=0;i<ob.length;i++)
            {
                word=(String) ob[i];
                if (MeaningFinder.verbChecker(word)) //confirms a word is verb
                {
                    Object syno[]=MeaningFinder.synonymExtractor(word); //extract list of synonym for that verb
                    if(syno.length!=k)
                       ob[i]=(String)syno[k];
                    Sentence=Sentence+" "+ob[i];
                }
                else Sentence=Sentence+" "+(String)ob[i];
            }
            }catch(Exception abe){ return "error";};
            Sentence=Sentence.replace(" /n","");
            Sentence=Sentence.replace("\n ", " ");
            return Sentence.replace(" ,",",");
        }
/**
<pre>
INPUT:String (word)
<b>do</b>
OUTPUT:Object[] (list of Synonyms of word if it's Verb of any form)
<b>accomplish
execute
proceed
make
satisfy
fulfil
create
spend
groom</b>

INPUT:String (word)
<b>doing</b>
OUTPUT:Object[] (list of Synonyms of word if it's Verb of any form)
<b>accomplishing
executing
proceeding
making
satisfying
fulfilling
creating
spending
grooming</b>
</pre>
 */
    public static Object[] synonymExtractor(String word) throws ClassNotFoundException, SQLException
    {          
            Connection con2=Misc.connect(null);
            Connection con3=Misc.connect(null);
            ArrayList syno=new ArrayList();
            try
            {    
                Statement st2=con2.createStatement();
                Statement st3=con3.createStatement();
                String sqlc,sqlc2,sqlc3,verb,form,synonym;
                ResultSet rs2,rs3;
                verb="";form="";
//-----------------------------------------------------------------------------------------
                if(MeaningFinder.verbFirstFormChecker(word))
                {
                    verb=word;
                    form="present";
                    sqlc2="Select syno from synolist where word='"+verb+"'"; //extracting relevant synonym of verb
                    rs2=st2.executeQuery(sqlc2);
                        while(rs2.next())
                        {
                            synonym=rs2.getString("syno");
                            if(form.equals("past participle"))form="participle";
                            sqlc3="Select "+form+" from formsofverb where present='"+synonym+"'";
                            rs3=st3.executeQuery(sqlc3);
                            while(rs3.next())    syno.add(rs3.getString(form));
                        }
                }
                else
                {
                    sqlc="Select * from verbform where verbform='"+word+"'"; //checking for verbs and taking out verb and forms
                    rs2=st2.executeQuery(sqlc);
                    while(rs2.next())
                    {
                        verb=rs2.getString("verb");
                        form=rs2.getString("form"); //getting verb and forms
                    }
                        sqlc2="Select syno from synolist where word='"+verb+"'"; //extracting relevant synonym of verb
                         rs2=st2.executeQuery(sqlc2);
                        while(rs2.next())
                        {
                            synonym=rs2.getString("syno");
                            if(form.equals("past participle"))form="participle";
                            sqlc3="Select "+form+" from formsofverb where present='"+synonym+"'";
                            rs3=st3.executeQuery(sqlc3);
                            while(rs3.next())    syno.add(rs3.getString(form));
                        }
                }
        }catch(SQLException s){System.err.print(s.toString());}
        return syno.toArray();
    }
/**
<pre>
INPUT:String (word)
<b>eats</b>
OUTPUT:Boolean
<b>true</b>

INPUT:String (word)
<b>he</b>
OUTPUT:Boolean
<b>false</b>

</pre>
 */  
    public static boolean verbChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select verbform from verbform where verbform='"+word+"' or verb='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>eats</b>
OUTPUT:Boolean
<b>true </b>

INPUT:String (word)
<b>eating</b>
OUTPUT:Boolean
<b>false </b>

</pre>
 */
    public static boolean verbSingularChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="SELECT * FROM verbform WHERE verbform='"+word+"' AND form='plural'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:String (Required Singular verb form)
<b>play</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:String (Required Singular verb form)
<b>eat</b>
INPUT:String (word)
<b>laugh</b>
OUTPUT:String (Required Singular verb form)
<b>laugh</b>
</pre>
 */
    public static String verbToNormalVerb(String word) throws ClassNotFoundException, SQLException
    {      
        String sqlc="SELECT verb FROM verbform WHERE verbform='"+word+"'",verb="";
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();          
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()) verb=rs.getString("verb");
        }catch(Exception e){}
        return verb;
    }
/**
<pre>
INPUT: String (Word)
<b> eat </b>
OUTPUT: Boolean
<b> true </b>
-----------------------
INPUT: String (Word)
<b> eaten </b>
OUTPUT: Boolean
<b> false </b>
</pre>
 */
    public static boolean verbFirstFormChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="SELECT * FROM verbform WHERE (verbform='"+word+"' AND form='plural') OR verb='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
 <pre>
INPUT: String (Word)
<b> eat </b>
OUTPUT: Boolean
<b> true </b>
-----------------------
INPUT: String (Word)
<b> eats </b>
OUTPUT: Boolean
<b> false </b>
 </pre>
 */
    public static boolean verbPluralChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="SELECT * FROM verbform WHERE verb='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:String (Required Singular verb form)
<b>plays</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:String (Required Singular verb form)
<b>eats</b>
INPUT:String (word)
<b>laugh</b>
OUTPUT:String (Required Singular verb form)
<b>laughs</b>
</pre>
 */
    public static String verbToSingular(String word) throws ClassNotFoundException, SQLException
    {
        String verb=MeaningFinder.verbToNormalVerb(word);
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="",plural="";
                sqlc="SELECT verbform FROM verbform WHERE verb='"+verb+"' AND form='plural'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()) return rs.getString("verbform");
        }catch(Exception e){}
        return "";
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:String (Required Ing verb form)
<b>playing</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:String (Required Ing verb form)
<b>eating</b>
INPUT:String (word)
<b>laugh</b>
OUTPUT:String (Required Ing verb form)
<b>laughing</b>
</pre>
 */
    public static String verbToIng(String word) throws ClassNotFoundException, SQLException
    {
        String verb=MeaningFinder.verbToNormalVerb(word);
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="",plural="";
                sqlc="SELECT verbform FROM verbform WHERE verb='"+verb+"' AND form='ing'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()) return rs.getString("verbform");
        }catch(Exception e){}
        return "";
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:String (Required Third verb form)
<b>played</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:String (Required Third verb form)
<b>eaten</b>
INPUT:String (word)
<b>laugh</b>
OUTPUT:String (Required Second verb form)
<b>laughed</b>
</pre>
 */
    public static String verbToThirdForm(String word) throws ClassNotFoundException, SQLException
    {
        String verb=MeaningFinder.verbToNormalVerb(word);
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="",plural="";
                sqlc="SELECT verbform FROM verbform WHERE verb='"+verb+"' AND form='past participle'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()) return rs.getString("verbform");
        }catch(Exception e){}
        return "";
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:String (Required Second verb form)
<b>played</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:String (Required Second verb form)
<b>ate</b>
INPUT:String (word)
<b>laugh</b>
OUTPUT:String (Required Second verb form)
<b>laughed</b>
</pre>
 */
    public static String verbToSecondForm(String word) throws ClassNotFoundException, SQLException
    {
        String verb=MeaningFinder.verbToNormalVerb(word);
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="",secForm="";
                sqlc="SELECT verbform FROM verbform WHERE verb='"+verb+"' AND form='past participle'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next()) secForm=rs.getString("verbform");
                if(!MeaningFinder.verbSecondFormChecker(secForm));
                {
                    sqlc = "SELECT verbform FROM verbform WHERE verb='" + verb + "' AND form='past'";
                    rs=st.executeQuery(sqlc);
                    while(rs.next()) secForm=rs.getString("verbform");
                }
                return secForm;
        }catch(Exception e){}
        return "";
    }
/**
<pre>
INPUT:String (word)
<b>eaten</b>
OUTPUT:Boolean
<b>true
</pre>
 */
    public static boolean verbThirdFormChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="SELECT * FROM verbform WHERE verbform='"+word+"' AND form='past participle'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>playing</b>
OUTPUT:Boolean
<b>true
</pre>
 */
    public static boolean verbIngChecker(String word) throws ClassNotFoundException, SQLException
    {
        Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="SELECT * FROM verbform WHERE verbform='"+word+"' AND form='ing'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
        }catch(Exception e){}
        return flag;
    }
/**
<pre>
INPUT:String (word)
<b>ate</b>
OUTPUT:Boolean
<b>true</b>
INPUT:String (word)
<b>eaten</b>
OUTPUT:Boolean
<b>false</b>
</pre>
 */
    public static boolean verbSecondFormChecker(String word) throws ClassNotFoundException, SQLException
    {
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            Statement st2=con.createStatement();
            String sqlc="",sqlc2="",sqlc3="";
                sqlc="SELECT * FROM verbform WHERE verbform='"+word+"' AND form='past'";
                sqlc3="Select * FROM verbform Where verb='"+MeaningFinder.verbToNormalVerb(word)+"' AND form='past'";
                sqlc2="SELECT * FROM verbform WHERE verbform='"+word+"' AND form='past participle'";
                ResultSet rs=st.executeQuery(sqlc);
                if(rs.next()) return true;
                else
                {
                    rs=st.executeQuery(sqlc3);
                    ResultSet rs2=st2.executeQuery(sqlc2);
                    if(rs2.next()&& !rs.next()) return true ;
                    else return false;
                }
        }catch(Exception e){}
        return false;
    }
/**
<pre>
INPUT:String (sentence)
<b> what did you like playing or smoking </b>
OUTPUT:Object[] (list of verbs in any form (present,past,past participle,ving,plural)
<b>did
like
playing
smoking
</pre>
 */
    public static Object[] verbExtractor(String sentence) throws ClassNotFoundException, SQLException
    {
            Connection con=Misc.connect(null);
            ArrayList verbs=new ArrayList();
            try
            {
                Statement st=con.createStatement();
                Object words[]=StringExtractor.seperater(sentence);
                String word="",sqlc;
                ResultSet rs;
            for(int i=0;i<words.length;i++)
            {
                sqlc="Select verb,verbform from verbform where verbform='"+words[i]+"' or verb='"+words[i]+"'";
                rs=st.executeQuery(sqlc);
                while(rs.next()) verbs.add((String)words[i]);
            }
        }catch(SQLException s){System.err.print(s.toString());}
            return StringExtractor.uniqueFilter(verbs.toArray());
    }
/**
 <pre>
 INPUT: String (verb=>must be present), String (form: present/past/participle/ing/(plural=>for singular mistaken))
 INPUT:<b>eat,past</b> OUTPUT:<b>ate</b>
 INPUT:<b>eat,participle</b> OUTPUT:<b>eaten</b>
 INPUT:<b>eat,plural</b> OUTPUT:<b>eats</b>
 INPUT:<b>eat,ing</b> OUTPUT:<b>eating</b>
 </pre>
 */
    public static String verbFormExtractor(String verb,String form) throws SQLException, ClassNotFoundException
    {
            Connection con=Misc.connect(null);
            try
            {
                Statement st=con.createStatement();
                String sqlc="Select "+form+" from formsofverb where present='"+verb+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    form=rs.getString(form);
            }catch(SQLException s){System.err.print(s.toString());}
            return form;
    }
/**
 <pre>
 INPUT:String (verb of any form)
 <b> ate </b>
 OUTPUT:String[] (at String[0] => form of verb and String[1] => present form
 <b> past
 eat </b>
 </pre>
 */
    public static String[] verbFormSensor(String verbform) throws ClassNotFoundException, SQLException
    {
            Connection con=Misc.connect(null);
            String form="",verb="";
            try
            {
                Statement st=con.createStatement();
                String sqlc="Select form,verb from verbform where verbform='"+verbform+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                {
                    form=rs.getString("form");
                    verb=rs.getString("verb");
                }
            }catch(SQLException s){System.err.print(s.toString());}
            String result[]={form,verb};
            return result;          
    }
/**
 <pre>
INPUT: String (Word)
<b> zassdgf </b>
OUTPUT: Boolean
<b> false </b>

INPUT: String (Word)
<b> tiger </b>
OUTPUT: Boolean
<b> true </b>
 </pre>
 */
    public static boolean isWordCorrect(String word)
    {
       Boolean flag=false;
        try
        {
            Connection con=Misc.connect(null);
            Statement st=con.createStatement();
            String sqlc="";
                sqlc="Select words from wordlist where words='"+word+"'";
                ResultSet rs=st.executeQuery(sqlc);
                while(rs.next())
                    if(rs.getRow()!=0)
                        flag=true;
         }catch(Exception e){}
            return flag;
    }
        public static String whatIs(Object ob[])
        {
            String word="",source="";
                JEditorPane je=new JEditorPane();
                je.setText("");
                je.setContentType("text/html");
//what section---------------------------------------------------------------------------------
                for(int i=0; i<ob.length;i++)
                {
                    word=(String)ob[i];
                    try
                    {
                        if (!(MeaningFinder.helpingVerbChecker(word) || MeaningFinder.prepositionChecker(word) || MeaningFinder.pronounChecker(word) || word.equals("?")|| word.equals("??")))
                        source=WebPageAnalyser.fetchSource("en.wikipedia.org/wiki/"+word);
                        source=StringExtractor.stringExtractor(source, "<p><b>", "</p>");
                        je.setText(source);
                        System.out.println(source);
                        JTextArea j=new JTextArea();
                        je.setText(source);
                                    je.setText(source);
                                    je.selectAll();
                                    je.copy();
                                    j.paste();
                                    return j.getText();
                    } catch (Exception e) {}
                }
                return "";
        }
}

No comments:

Post a Comment