{                                         

        String readPOS;

		readPOS = jTextArea1.getText();

		String []POS;
		POS = readPOS.split("[-.!? ]");

        jTextArea2.append("Part of Speech Result:\n");
        String patternKGN,patternKPF,patternKK,patternKNA,patternKPA,
                patternKPC,patternKPK,patternKS;

		for(int i = 0; i < POS.length; i++)
		{
            try {
                File readKGN = new File("KGNLibrary.txt");
                FileReader outKGN = new FileReader(readKGN);
                char[] buf = new char[(int)readKGN.length()];
                outKGN.read(buf);
                patternKGN = new String(buf);
                StringTokenizer KGNLib = new StringTokenizer(patternKGN);
                while (KGNLib.hasMoreElements())

                if (POS[i].equals(KGNLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KGN" + " | ");
            }

                File readKPF = new File("KPFLibrary.txt");
                FileReader outKPF = new FileReader(readKPF);
                char[] buf1 = new char[(int)readKPF.length()];
                outKPF.read(buf1);
                patternKPF = new String(buf1);
                StringTokenizer KPFLib = new StringTokenizer(patternKPF);
                while (KPFLib.hasMoreElements())

                if (POS[i].equals(KPFLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KPF" + " | ");
            }

                File readKK = new File("KKLibrary.txt");
                FileReader outKK = new FileReader(readKK);
                char[] buf2 = new char[(int)readKK.length()];
                outKK.read(buf2);
                patternKK = new String(buf2);
                StringTokenizer KKLib = new StringTokenizer(patternKK);
                while (KKLib.hasMoreElements())

                if (POS[i].equals(KKLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KK" + " | ");
            }

                File readKNA = new File("KNALibrary.txt");
                FileReader outKNA = new FileReader(readKNA);
                char[] buf3 = new char[(int)readKNA.length()];
                outKNA.read(buf3);
                patternKNA = new String(buf3);
                StringTokenizer KNALib = new StringTokenizer(patternKNA);
                while (KNALib.hasMoreElements())

                if (POS[i].equals(KNALib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KNA" + " | ");
            }

                File readKPA = new File("KPALibrary.txt");
                FileReader outKPA = new FileReader(readKPA);
                char[] buf4 = new char[(int)readKPA.length()];
                outKPA.read(buf4);
                patternKPA = new String(buf4);
                StringTokenizer KPALib = new StringTokenizer(patternKPA);
                while (KPALib.hasMoreElements())

                if (POS[i].equals(KPALib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KPA" + " | ");
            }

                File readKPC = new File("KPCLibrary.txt");
                FileReader outKPC = new FileReader(readKPC);
                char[] buf5 = new char[(int)readKPC.length()];
                outKPC.read(buf5);
                patternKPC = new String(buf5);
                StringTokenizer KPCLib = new StringTokenizer(patternKPC);
                while (KPCLib.hasMoreElements())

                if (POS[i].equals(KPCLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KPC" + " | ");
            }

                File readKPK = new File("KPKLibrary.txt");
                FileReader outKPK = new FileReader(readKPK);
                char[] buf6 = new char[(int)readKPK.length()];
                outKPK.read(buf6);
                patternKPK = new String(buf6);
                StringTokenizer KPKLib = new StringTokenizer(patternKPK);
                while (KPKLib.hasMoreElements())

                if (POS[i].equals(KPKLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KPK" + " | ");
            }

                File readKS = new File("KSLibrary.txt");
                FileReader outKS = new FileReader(readKS);
                char[] buf7 = new char[(int)readKS.length()];
                outKS.read(buf7);
                patternKS = new String(buf7);
                StringTokenizer KSLib = new StringTokenizer(patternKS);
                while (KSLib.hasMoreElements())

                if (POS[i].equals(KSLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KS" + " | ");
            }
 
                File readKNK = new File("KNKLibrary.txt");
                FileReader outKNK = new FileReader(readKNK);
                char[] buf8 = new char[(int)readKNK.length()];
                outKNK.read(buf8);
                patternKS = new String(buf8);
                StringTokenizer KNKLib = new StringTokenizer(patternKS);
                while (KNKLib.hasMoreElements())

                if (POS[i].equals(KNKLib.nextToken()))
            {
                jTextArea2.append(POS[i] + "/KNK" + " | ");
            }
                else if ((!POS[i].equals(KNKLib.nextToken())||(!POS[i].equals(KSLib.nextToken())))
                        ||(!POS[i].equals(KPKLib.nextToken()))||(!POS[i].equals(KPCLib.nextToken()))
                        ||(!POS[i].equals(KPALib.nextToken()))||(!POS[i].equals(KNALib.nextToken()))
                        ||(!POS[i].equals(KKLib.nextToken()))||(!POS[i].equals(KPFLib.nextToken()))
                        ||(!POS[i].equals(KGNLib.nextToken())))
            {
                jTextArea2.append(POS[i] + "/KNK" + " | ");
            }
                }catch (IOException ex) {
    Logger.getLogger(PartOfSpeechView.class.getName()).log(Level.SEVERE, null, ex);}
         }

i wan my output if not same with all data in all text file then will be did jTextArea2.append(POS + "/KNK" + " | "); , my problem is once detect data in text file then will print 2 times.

like "Saya" in data of KPALib.txt" then output will become "Saya/KPA Saya/KNK". i wan it only "Saya/KPA" and dun wan "Saya/KNK". Can anyone help me fix tis?

I would help if your explanation was coherent. Repost it but this time, make sure it makes sense.

I would help if your explanation was coherent. Repost it but this time, make sure it makes sense.

mean that, tat "saya" in any of KGNLib.txt, then the output will be only "saya/KGN". So if "Shell" tis word not in any .txt file tat i declared, then output will be "Shell/KNK".

one thing, is i wan do grammar rules system.

Not trying to be rude, but that still does not make sense to me. Maybe you should try writing a full explanation of what your program does.

I think your last big if test should be all && not || - ie (word not in file 1) AND (word not in file 2) AND ... but I'm not sure. It would help if you used a code=java tag rather than just a code tag so we get proper formatting and line numbers

I think your last big if test should be all && not || - ie (word not in file 1) AND (word not in file 2) AND ... but I'm not sure. It would help if you used a code=java tag rather than just a code tag so we get proper formatting and line numbers

if all become &&.. will error when press the button.. logic problem..

That certainly isn't the only logic problem. Why are you opening and reading the same files over and over for each portion of your split() result?

I'll mention one last time: read up on HashMap.

That certainly isn't the only logic problem. Why are you opening and reading the same files over and over for each portion of your split() result?

I'll mention one last time: read up on HashMap.

ur way abit complicated... got another simply way ??

Map is complicated? What is complicated about a key-value pair look up?

Here is a simple example of using a Map for something like what you are doing.

// simple map for rule patterns to their descriptions
Map<String,String> patternMap = new HashMap<String, String>();
patternMap.put("(?i)\\s*[a-zA-Z]+ing\\s*","Ends with 'ing'");
patternMap.put("(?i)\\s*[a-zA-Z]+ly\\s*","Ends with 'ly'");
patternMap.put("(?i)\\s*th[a-zA-Z]+\\s*","Starts with 'th'");

// now let's run this against some text
String someWords = "The early bird can be found eating the worm over there, Billy.";
for (String s : someWords.split("[ ,\\.]") ){
    for (String pattern : patternMap.keySet()){
        // if we find a match, print it along with its description
        if (s.matches(pattern)){
            System.out.println(s + ": "+patternMap.get(pattern));
        }
    }
}

Here is a simple example of using a Map for something like what you are doing.

// simple map for rule patterns to their descriptions
Map<String,String> patternMap = new HashMap<String, String>();
patternMap.put("(?i)\\s*[a-zA-Z]+ing\\s*","Ends with 'ing'");
patternMap.put("(?i)\\s*[a-zA-Z]+ly\\s*","Ends with 'ly'");
patternMap.put("(?i)\\s*th[a-zA-Z]+\\s*","Starts with 'th'");

// now let's run this against some text
String someWords = "The early bird can be found eating the worm over there, Billy.";
for (String s : someWords.split("[ ,\\.]") ){
    for (String pattern : patternMap.keySet()){
        // if we find a match, print it along with its description
        if (s.matches(pattern)){
            System.out.println(s + ": "+patternMap.get(pattern));
        }
    }
}

i will take time to understand more about Hashmap function.. Thanks ya.. :-)!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.