Pages

Sunday, April 11, 2010

update fyp

/*************************************************************************
* Compilation: javac Tokenizer.java In.java
* Execution: java Tokenizer
*
* Takes a string as input and tokenizes it into an array of substrings
* See also java.util.StringTokenizer.
* read and write to the text file
* using a specified delimiter character.
* check the availablelity of the words in database
* check the structure due to the malay language rule
*
*
*************************************************************************/
//import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
import java.net.*;
import java.sql.*;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;

import java.awt.Container;
import java.awt.FileDialog;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.awt.event.ActionEvent
//import java.io.File;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class guiTokenizer extends javax.swing.JFrame {

Connection connection = null;

String str;
int num, n;


public guiTokenizer()
{ initComponents();
}




public void cmd(){

// jTextField1.setText("Edited file. xls");
PrintWriter outStream=null;
boolean check=true;
//Tokenizer q = new Tokenizer();

String fileName=jTextField1.getText();
try{
//database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection( "jdbc:odbc:database" );
//file
FileInputStream file = new FileInputStream(fileName);//input: text file with delimeter
outStream = new PrintWriter(new FileOutputStream("C:/fyp/edited.txt"));//output: sentence eleminate the delimeter
DataInputStream in = new DataInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(in));


//array
String[] arrayToken;
String[] checktrueNp;
String[] checktrueVp;

//declare stack
Stack currentStack= new Stack();
Stack copyStack = new Stack();
Stack toCompleteStack = new Stack();
Stack toCompleteStackSentence = new Stack();
Stack tempStack =new Stack ();
Stack backUpToCompleteStack = new Stack();
Stack backUpToCompleteStackSentence= new Stack();
Stack currentStackSentence= new Stack();
Stack partOfSpeech= new Stack();
Stack partOfSpeech2= new Stack();
//stack for frasa nama,frasa kerja, frasa adjectif, frasa sendi
Stack Np= new Stack();
Stack Vp= new Stack();
Stack Pp= new Stack();
Stack Ap= new Stack();
Stack Pv= new Stack();
Stack Pv2= new Stack();


//insert element in pharase
//Np
// stack frasa nama= bil/penjbil/gelaran/kata nama/penentu/pent
Np.push("Pent");
Np.push("penentu");
Np.push("Kata nama");
Np.push("Kata nama");
Np.push("gelaran");
Np.push("penjodoh bilangan");
Np.push("bil");
String[] arrayNp=new String[]{"bil","penjodoh bilangan","gelaran","Kata nama","penentu","Pent"};
String[] arrayNpCheck=new String[arrayNp.length];
//Vp
//stack frasa kerja= kata bantu/[katakerja(obj|akomp)]ket
Vp.push("Ket");
Vp.push("Akomp");
Vp.push("kata nama");
Vp.push("Kata kerja");
Vp.push("kata bantu");
String[] arrayVp=new String[]{"kata bantu","Kata kerja","Obj"};
String[] arrayVpCheck=new String[arrayVp.length];
//Pp
// stack frasa sendi=kata bantu +kata sendi+kata nama arah+FN+(akomp|ket)*/
Pp.push("ket");
Pp.push("Akomp");
Pp.push("Fn");
Pp.push("Kata nama arah");
Pp.push("Kata sendi");
Pp.push("kata Bantu");
String[] arrayPp=new String[]{"kata Bantu","Kata sendi","Kata nama arah","Fn","Akomp","ket"};
//Ap
//stack frasa adjectiv= kata bantu(kata penguat)+adj+(ket)+(akomp)
// Ap.push("Akomp");
Ap.push("ket");
Ap.push("adjectif");
Ap.push("kata penguat");
Ap.push("kata bantu");
String[] arrayAp=new String[]{"kata bantu","kata penguat","adjectif","ket","Akomp"};


//pasive
Pv.push("obj");
Pv.push("penyambung");
Pv.push("kata kerja");
String[] arrayPasive=new String[]{"kata kerja","penyambung","kata nama"};
String[] arrayPasivepCheck=new String[arrayPasive.length];

//pasive2
Pv2.push("kata kerja");
Pv2.push("kata nama");


// String texta=jTextArea1.getText();
//System.out.println(texta);
/* String cmd=null;
cmd(cmd);
System.out.println(cmd);
if(cmd=="Yes"){
System.out.println(cmd);}
else
{ System.out.println("...........");}*/

String s = br.readLine();
char delimiter = '.';//delimeter

// calculate number of delimiter characters
int N = 0;
while (s != null){

for (int i = 0; i < tokens =" new" right =" 0," left =" 0;" i =" 0;" left =" right;" i =" 0;" st =" new" notoken="st.countTokens();" pos =" new" arraytoken="new" addtoken=" new" count="0;" str="st.nextToken();" temp=" toCompleteStack.pop();" count="0;" stmt =" con.createStatement();" countarray="0;" position="tempStack.pop();" rs =" stmt.executeQuery" word =" rs.getString(1);" tokenpos=" rs.getString(2);" check="true;" count="="0)" attpos="null" arraytoken="new" temp="partOfSpeech.pop();" token="0;" try="" counttrue="0;" getcurrentnp="0;" getcurrentvp="0;" backnp="0;" countwhile="0;" counttruetoken="0;" checkstruc="true;" int="" indexnp="0;" checktruenp="new" checktruevp="new" notoken="" wordinpos="partOfSpeech2.pop();" all="" current="" boolean="" check="" begin="" string="" np="" checknp="false;" counttoken="0;"><=(noToken-2)){ if( arrayToken[countToken+1].equalsIgnoreCase(np2)) { outStream.println((countToken+1)+": "+arrayToken[countToken+1]+" " +arrayToken[countToken+1].equalsIgnoreCase(np2)); } else { indexNp=countToken+1; //check VP String vp1= Vp.pop(); String vp2= Vp.pop(); Vp.push("Kata kerja"); Vp.push("kata bantu"); String pv1= Pv.pop(); String pv2= Pv.pop(); String pv3= Pv2.pop(); //outStream.println("another structure (VP) "+indexNp); Pv.push("penyambung"); Pv.push("kata kerja"); Pv2.push("kata nama"); // outStream.println("another structure (VP) "+indexNp); // outStream.println("String pv3= Pv2.pop();"+pv3); boolean checkPasivePenyambung=false; //outStream.println(arrayToken[indexNp].equalsIgnoreCase(vp2)+vp2); // //if (indexNp<(noToken-2)){ //checkPasivePenyambung=arrayToken[indexNp+1].equalsIgnoreCase(pv2); // } // outStream.println(checkPasivePenyambung+"tr"); if((arrayToken[indexNp].equalsIgnoreCase("kata bantu"))||(arrayToken[indexNp].equalsIgnoreCase("kata kerja")))//&&checkPasivePenyambung==false) { outStream.println("VP true "+arrayToken[indexNp]); while(noToken != indexNp) { while(!Vp.empty()) { String vp=Vp.pop(); if(arrayToken[indexNp].equalsIgnoreCase(vp)&&(indexNp<=(noToken-2)){ if( arrayToken[indexNp+1].equalsIgnoreCase(vp2)) { outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" " +arrayToken[indexNp+1].equalsIgnoreCase(vp2)+" " +vp2); } } } } indexNp++; } } //vp pasive else if (arrayToken[indexNp].equalsIgnoreCase(pv1)||arrayToken[indexNp].equalsIgnoreCase(pv3)) { //pv 1 outStream.println("Pv true "+arrayToken[indexNp+1]); if (arrayToken[indexNp].equalsIgnoreCase(pv1)) { outStream.println("Pv1 true"); outStream.println("Pv1 true"); while(noToken != indexNp) { while(!Pv.empty()) { String pv11=Pv.pop(); if(arrayToken[indexNp].equalsIgnoreCase(pv11)&&(indexNp<=(noToken-2)){ if( arrayToken[indexNp+1].equalsIgnoreCase(vp12)) { outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" " +arrayToken[indexNp+1].equalsIgnoreCase(vp12)); } } } } indexNp++; } } else if(arrayToken[indexNp].equalsIgnoreCase(pv3)) { outStream.println("Pv2 true"+ arrayToken[indexNp]+pv3); while(noToken != indexNp) { while(!Pv2.empty()) { String pv21=Pv2.pop(); if(arrayToken[indexNp].equalsIgnoreCase(pv21)&&(indexNp<=(noToken-2)){ if( arrayToken[indexNp+1].equalsIgnoreCase(pv22)) { outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" " +arrayToken[indexNp+1].equalsIgnoreCase(pv22)+" " +pv22); } } } else {outStream.println("False ");} } indexNp++; } //Pv2.push("kata kerja"); //Pv2.push("kata nama"); } } // else //{outStream.println("Another structure "); } backNp++; outStream.println("BAck to Np"); //Vp.push("Ket"); // Vp.push("Akomp"); Vp.push("obj"); Vp.push("Kata kerja"); Vp.push("kata bantu"); /* (arrayToken[indexNp].equalsIgnoreCase(Pp.pop())&&!Pp.empty()) { outStream.println("stack empty PP:"+!Pp.empty()); } else if (arrayToken[indexNp].equalsIgnoreCase(Ap.pop())&&!Ap.empty()) { outStream.println("stack empty AP:"+!Ap.empty()); } else {outStream.println("check Np back At :"+ indexNp);}*/ } } } //end if else if (checkNp==false&&(countToken1){outStream.println("Sentence false ");}
else {outStream.println("Sentence True");}







outStream.println("___________________________________________________________");
outStream.println("___________________________________________________________");
outStream.println("");

// System.out.println(arrayToken[countToken]);
}//close for




}//close main while


}// close try



catch(FileNotFoundException fnf)
{System.out.println("File Not Found");
System.out.println(fnf.getMessage());}

catch(IOException io)
{ System.out.println(io.getMessage()); }

catch(Exception a)
{ }
outStream.close();


}
//Open File Analysis
protected void openOutput()
{
String directoryFileOutDetails="C:/fyp/";
String fileNameFileOutDetails="edited.txt";
setFile(directoryFileOutDetails,fileNameFileOutDetails);
}

//browse
protected void onBrowseNative() {
FileDialog fileDialog = new FileDialog(this, "Open/Save");
fileDialog.show();
if (fileDialog.getFile() != null) {
String directory = fileDialog.getDirectory();
if (!directory.endsWith(File.separator)) {
directory += File.separator;
}
String file = fileDialog.getFile();
jTextField1.setText(directory + file);
setFile(directory,file);
//engine(directory,file);
}
}


public void setFile(String directory, String filename) {
if ((filename == null) || (filename.length() == 0)) return;
File f;
FileReader in = null;
// Read and display the file contents. Since we're reading text, we
// use a FileReader instead of a FileInputStream.
try {
f = new File(directory, filename); // Create a file object
in = new FileReader(f); // And a char stream to read it
char[] buffer = new char[4096]; // Read 4K characters at a time
int len; // How many chars read each time
jTextArea1.setText(""); // Clear the text area
while((len = in.read(buffer)) != -1) { // Read a batch of chars
String s = new String(buffer, 0, len); // Convert to a string
jTextArea1.append(s); // And display them
}
this.setTitle("FileViewer: " + filename); // Set the window title
jTextArea1.setCaretPosition(0); // Go to start of file
}
// Display messages if something goes wrong
catch (IOException e) {
jTextArea1.setText(e.getClass().getName() + ": " + e.getMessage());
this.setTitle("FileViewer: " + filename + ": I/O Exception");
}
// Always be sure to close the input stream!
finally { try { if (in!=null) in.close(); } catch (IOException e) {} }
}

// jbuuton analyze




/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
public void initComponents() {



jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Malay Grammar Checker Application");

jTextField1.setText("browse_file");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// file = jTextField1.getText();

}
});

jButton1.setText("Browse");

jButton2.setText("Analyze");

jButton3.setText("Open File Analysis");

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);


jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
onBrowseNative();
}
});
//button analyze
jButton2 .addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent arg0){
cmd();
}
});

jButton3 .addActionListener(new java.awt.event.ActionListener(){
public void actionPerformed(ActionEvent arg0){
openOutput();
}
});





javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(402, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addGap(28, 28, 28))
.addGroup(layout.createSequentialGroup()
.addGap(60, 60, 60)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3))
.addGap(19, 19, 19))
);
pack();
}//



/**
* @param args the command line arguments
*/
public static void main(String args[])throws ClassNotFoundException{
guiTokenizer a=new guiTokenizer();


//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Connection con = DriverManager.getConnection( "jdbc:odbc:database" );


Frame f = new FileViewer((args.length == 1)?args[0]:null);




java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new guiTokenizer().setVisible(true);

}

});


}



// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

String file;

}

Saturday, April 3, 2010

my fyp (code)

/*************************************************************************
* Compilation: javac Tokenizer.java In.java
* Execution: java Tokenizer
*
* Takes a string as input and tokenizes it into an array of substrings
* See also java.util.StringTokenizer.
* read and write to the text file
* using a specified delimiter character.
* check the availablelity of the words in database
* check the structure due to the malay language rule
*
*
*************************************************************************/
import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
import java.net.*;
import java.sql.*;


public class Tokenizer {


//database
public static final String DRIVER_NAME ="sun.jdbc.odbc.JdbcOdbcDriver";
public static final String DATABASE_URL = "jdbc:odbc:database";


String str;
int num, n;


public static void main (String[] args) throws ClassNotFoundException, SQLException{
PrintWriter outStream=null;
Class.forName(DRIVER_NAME);
Connection con = null;
boolean check=true;
//Tokenizer q = new Tokenizer();

try{
//database
//kosmo denggi 7 kawasan panas
FileInputStream file = new FileInputStream("C:/fyp/test.txt");//input: text file with delimeter
outStream = new PrintWriter(new FileOutputStream("C:/fyp/edited.txt"));//output: sentence eleminate the delimeter
DataInputStream in = new DataInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(in));


//array
String[] arrayToken;
String[] checktrueNp;
String[] checktrueVp;

//declare stack
Stack currentStack= new Stack();
Stack copyStack = new Stack();
Stack toCompleteStack = new Stack();
Stack toCompleteStackSentence = new Stack();
Stack tempStack =new Stack ();
Stack backUpToCompleteStack = new Stack();
Stack backUpToCompleteStackSentence= new Stack();
Stack currentStackSentence= new Stack();
Stack partOfSpeech= new Stack();
Stack partOfSpeech2= new Stack();
//stack for frasa nama,frasa kerja, frasa adjectif, frasa sendi
Stack Np= new Stack();
Stack Vp= new Stack();
Stack Pp= new Stack();
Stack Ap= new Stack();
Stack Pv= new Stack();
Stack Pv2= new Stack();


//insert element in pharase
//Np
// stack frasa nama= bil/penjbil/gelaran/kata nama/penentu/pent
Np.push("Pent");
Np.push("penentu");
Np.push("Kata nama");
Np.push("Kata nama");
Np.push("gelaran");
Np.push("penjodoh bilangan");
Np.push("bil");
String[] arrayNp=new String[]{"bil","penjodoh bilangan","gelaran","Kata nama","penentu","Pent"};
String[] arrayNpCheck=new String[arrayNp.length];
//Vp
//stack frasa kerja= kata bantu/[katakerja(obj|akomp)]ket
Vp.push("Ket");
Vp.push("Akomp");
Vp.push("kata nama");
Vp.push("Kata kerja");
Vp.push("kata bantu");
String[] arrayVp=new String[]{"kata bantu","Kata kerja","Obj"};
String[] arrayVpCheck=new String[arrayVp.length];
//Pp
// stack frasa sendi=kata bantu +kata sendi+kata nama arah+FN+(akomp|ket)*/
Pp.push("ket");
Pp.push("Akomp");
Pp.push("Fn");
Pp.push("Kata nama arah");
Pp.push("Kata sendi");
Pp.push("kata Bantu");
String[] arrayPp=new String[]{"kata Bantu","Kata sendi","Kata nama arah","Fn","Akomp","ket"};
//Ap
//stack frasa adjectiv= kata bantu(kata penguat)+adj+(ket)+(akomp)
// Ap.push("Akomp");
Ap.push("ket");
Ap.push("adjectif");
Ap.push("kata penguat");
Ap.push("kata bantu");
String[] arrayAp=new String[]{"kata bantu","kata penguat","adjectif","ket","Akomp"};


//pasive
Pv.push("obj");
Pv.push("penyambung");
Pv.push("kata kerja");
String[] arrayPasive=new String[]{"kata kerja","penyambung","kata nama"};
String[] arrayPasivepCheck=new String[arrayPasive.length];

//pasive2
Pv2.push("kata kerja");
Pv2.push("kata nama");

String s = br.readLine();
char delimiter = '.';//delimeter

// calculate number of delimiter characters
int N = 0;
while (s != null){

for (int i = 0; i < s.length(); i++)
if (s.charAt(i) == delimiter) N++;
String[] tokens = new String[N+1];

// parse N+1 tokens and store in an array
int right = 0, left = 0;
for (int i = 0; i < N; i++) {
while(s.charAt(right) != delimiter)
right++;
tokens[i] = s.substring(left, right);
right++;
left = right;
}
tokens[N] = s.substring(right, s.length());
int noToken;
// print results for testing
for (int i = 0; i < tokens.length-1; i++)
{//open for
outStream.println(tokens[i]);// tranform paragraph to sentence
String str;
StringTokenizer st = new StringTokenizer(tokens[i]);
noToken=st.countTokens();
outStream.println("number of token: "+noToken+" in sentense "+ (i+1));
//String[] pos = new String[noToken];
arrayToken=new String[noToken];
// String[] addToken= new String[st.countTokens()];
// int count=0;




while (st.hasMoreTokens())
{//open while
str=st.nextToken();
//insert token in stack
//System.out.print(str + " ");
toCompleteStack.push(str);// transform sentence to word


}//close while
//toCompleteStack.push("stop");

// System.out.print("Retrieved elements from the stack : ");


while (!toCompleteStack.empty()){
//pop the sentence from stack stored temp
String temp= toCompleteStack.pop();
//System.out.println(temp);
tempStack.push(temp);
}

// check in database the availablelity and the part of speeecg (POS)
String word ;
String tokenPos ;
int count=0;
String position;


con = DriverManager.getConnection(DATABASE_URL);
Statement stmt = con.createStatement();
ResultSet rs;
int countArray=0;
while(!tempStack.empty()){
position=tempStack.pop();
rs = stmt.executeQuery ("select * from [Sheet1$]");
while (rs.next())
{
word = rs.getString(1);
tokenPos= rs.getString(2);
//outStream.println(position+" "+position.equalsIgnoreCase(word));
if(position.equalsIgnoreCase(word))
{
outStream.println(position+" Ada "+tokenPos);
//check=true;
partOfSpeech.push(tokenPos);//store POS in Stack
// pos[countArray]=tokenPos;

arrayToken[countArray]=tokenPos;
count++;
break;
}
else
{
//partOfSpeech.push("null");
}

}
rs.close();
//insert none of POS if the word not available in the dBase
if(count==0)
{ String attPos="null";
partOfSpeech.push(attPos);
//pos[countArray]=attPos;
arrayToken[countArray]=attPos;
// arrayToken=new String[noToken];
// arrayToken[]
}
// countToken++;
countArray++;
}
//inthe right order


// pop the PartOf Speech in the word containt in the sentences.

stmt.close();


while(!partOfSpeech.empty())
{String temp=partOfSpeech.pop();
partOfSpeech2.push(temp);}


/* show an array of POS
for(int token=0; token outStream.print("Try "+arrayToken[token]);*/

int countToken=0;
int countTrue=0;
int getCurrentNp=0;
int getCurrentVp=0;
int backNp=0;
int countWhile=0;
int countTrueToken=0;
boolean checkStruc=true;
int indexNp=0;

checktrueNp=new String[noToken];
checktrueVp=new String[noToken];
while(noToken != countToken)

{ String wordInPos=partOfSpeech2.pop();
// outStream.println("Check "+ wordInPos+" all "+noToken+" current "+countToken);
boolean checkNp= false;

outStream.println();
//1:::: NP check
//(NP)+np begin
while(!Np.empty()){
String np=Np.pop();
checkNp=arrayToken[countToken].equalsIgnoreCase(np);
if( arrayToken[countToken].equalsIgnoreCase(np))//&&(countToken {
outStream.println(countToken+": "+arrayToken[countToken]+" "
+arrayToken[countToken].equalsIgnoreCase(np));

String np2=Np.pop();
if (countToken<=(noToken-2)){
if( arrayToken[countToken+1].equalsIgnoreCase(np2))
{
outStream.println((countToken+1)+": "+arrayToken[countToken+1]+" "
+arrayToken[countToken+1].equalsIgnoreCase(np2));
}


else
{


indexNp=countToken+1;
//check VP
String vp1= Vp.pop();
String vp2= Vp.pop();
Vp.push("Kata kerja");
Vp.push("kata bantu");


String pv1= Pv.pop();
String pv2= Pv.pop();
Pv.push("penyambung");
Pv.push("kata kerja");
String pv3= Pv2.pop();
Pv2.push("kata nama");
outStream.println("another structure (VP) "+indexNp);
// outStream.println("String pv3= Pv2.pop();"+pv3);
boolean checkPasivePenyambung=false;



//outStream.println(arrayToken[indexNp].equalsIgnoreCase(vp2)+vp2);
//
//checkPasivePenyambung= arrayToken[indexNp+1].equalsIgnoreCase(pv2);
// outStream.println(checkPasivePenyambung+"tr");
if((arrayToken[indexNp].equalsIgnoreCase("kata bantu"))||(arrayToken[indexNp].equalsIgnoreCase("kata kerja")))//&&checkPasivePenyambung==false)
{
outStream.println("VP true "+arrayToken[indexNp]);
while(noToken != indexNp)
{

while(!Vp.empty())
{
String vp=Vp.pop();
if(arrayToken[indexNp].equalsIgnoreCase(vp)&&(indexNp {
outStream.println(indexNp+": "+arrayToken[indexNp]+" "+arrayToken[indexNp]+" "
+arrayToken[indexNp].equalsIgnoreCase(vp)+" "+vp);

vp2=Vp.pop();

if( arrayToken[indexNp+1].equalsIgnoreCase(vp2))
{
outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" "
+arrayToken[indexNp+1].equalsIgnoreCase(vp2)+" " +vp2);
}

}


}

indexNp++;

}


}
//vp pasive

else if (arrayToken[indexNp].equalsIgnoreCase(pv1)||arrayToken[indexNp].equalsIgnoreCase(pv3))
{
//pv 1
outStream.println("Pv true "+arrayToken[indexNp+1]);
if (arrayToken[indexNp].equalsIgnoreCase(pv1))
{
outStream.println("Pv1 true");
outStream.println("Pv1 true");
while(noToken != indexNp)
{

while(!Pv.empty())
{
String pv11=Pv.pop();
if(arrayToken[indexNp].equalsIgnoreCase(pv11)&&(indexNp {
outStream.println(indexNp+": "+arrayToken[indexNp]+" "+arrayToken[indexNp]+" "
+arrayToken[indexNp].equalsIgnoreCase(pv11));

String vp12=Pv.pop();

if( arrayToken[indexNp+1].equalsIgnoreCase(vp12))
{
outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" "
+arrayToken[indexNp+1].equalsIgnoreCase(vp12));
}

}


}

indexNp++;

}

}

else if(arrayToken[indexNp].equalsIgnoreCase(pv3))
{
outStream.println("Pv2 true"+ arrayToken[indexNp]+pv3);
while(noToken != indexNp)
{

while(!Pv2.empty())
{
String pv21=Pv2.pop();
if(arrayToken[indexNp].equalsIgnoreCase(pv21)&&(indexNp {
outStream.println(indexNp+": "+arrayToken[indexNp]+" "+arrayToken[indexNp]+" "
+arrayToken[indexNp].equalsIgnoreCase(pv21)+" "+pv21);

String pv22=Pv2.pop();

if( arrayToken[indexNp+1].equalsIgnoreCase(pv22))
{
outStream.println((indexNp+1)+": "+arrayToken[indexNp+1]+" "+arrayToken[indexNp+1]+" "
+arrayToken[indexNp+1].equalsIgnoreCase(pv22)+" " +pv22);
}

}
else
{outStream.println("False ");}


}

indexNp++;

}
//Pv2.push("kata kerja");
//Pv2.push("kata nama");
}


}
// else
//{outStream.println("Another structure "); }

backNp++;
outStream.println("BAck to Np");



//Vp.push("Ket");
// Vp.push("Akomp");
Vp.push("obj");
Vp.push("Kata kerja");
Vp.push("kata bantu");
/* (arrayToken[indexNp].equalsIgnoreCase(Pp.pop())&&!Pp.empty())
{
outStream.println("stack empty PP:"+!Pp.empty());
}
else if (arrayToken[indexNp].equalsIgnoreCase(Ap.pop())&&!Ap.empty())
{
outStream.println("stack empty AP:"+!Ap.empty());
}
else
{outStream.println("check Np back At :"+ indexNp);}*/

}
}
} //end if

else if (checkNp==false&&(countToken {
//outStream.println(countToken+": "+"false");
}


} //while checkNp
// outStream.println("backNP"+backNp);

countToken++;


Np.push("Pent");
Np.push("penentu");
Np.push("Kata nama");
Np.push("gelaran");
Np.push("penjodoh bilangan");
Np.push("bil");
}//end while NP
outStream.println("BAck to Np"+backNp);
if(backNp==0){outStream.println("Sentence false no NP");}
else if (backNp>1){outStream.println("Sentence false ");}
else {outStream.println("Sentence True");}

//(NP)+np begin
/*
/vp

while(indexNp {
while(!Vp.empty())
{
String vp=Vp.pop();

if (arrayToken[indexNp].equalsIgnoreCase(vp)&& (indexNp {
outStream.println((indexNp)+": "+arrayToken[ indexNp]+" "
+arrayToken[ indexNp].equalsIgnoreCase(vp));


String vp2=Vp.pop();
if( arrayToken[indexNp+1].equalsIgnoreCase(vp2))
{
outStream.println((indexNp+1)+": "+arrayToken[ indexNp+1]+" "
+arrayToken[ indexNp+1].equalsIgnoreCase(vp2));
}

}
else
{
outStream.println(arrayToken[indexNp]+"....."+"index: "+indexNp + "Pop vp"+vp);
}

}
indexNp++;

}










if(arrayToken[countToken+(inNp)].equalsIgnoreCase(arrayNp[checkNp+(inNp)])&&(checkNp<(checkNp+inNp)))
{
outStream.println((countToken+inNp)+": "+arrayToken[countToken +(inNp)]
+" "+arrayToken[countToken+inNp].equalsIgnoreCase(arrayNp[checkNp+inNp])
+" aray Np ke:"+(checkNp+inNp));
outStream.println();

}
// else if (arrayToken[countToken+(inNp)].equalsIgnoreCase(arrayNp[checkNp+(inNp)])&&(checkNp>(checkNp+inNp)))
// {outStream.println("sentence false");}
else
//Np+(Np) last
{ outStream.println("check another struc"+arrayToken[countToken+(inNp)]);


for(int checkNpIn=0;checkNpIn {

if(arrayToken[countToken+inNp].equalsIgnoreCase(arrayNp[checkNpIn]))
{
outStream.println((countToken+inNp) +": "+arrayToken[countToken+(inNp)]
+" "+arrayToken[countToken+(inNp)].equalsIgnoreCase(arrayNp[checkNpIn])
+" "+checkNpIn);
outStream.println("Np is true");


}
//else
//{outStream.println((countToken+inNp)+" Np is false "+checkNpIn);}
//outStream.println(" ");
}


}*/


























/* //check the index for the next check
// int getCurrentVp=0;
int countTrueNp=1;
for(int checkNp=0;checkNp {
if((checktrueNp[checkNp].equalsIgnoreCase("True")&&checktrueNp[checkNp+1].equalsIgnoreCase("False")))
indexNp=checkNp+1;
//else if(checktrueNp[checkNp].equalsIgnoreCase("True")&&checktrueNp[checkNp+1].equalsIgnoreCase("True"))
//{}
else if(checktrueNp[checkNp].equalsIgnoreCase("True"))
countTrueNp++;
}


if(countTrueNp==noToken)
{outStream.println(" Np+Np sentences is true");}

else if(checktrueNp[0].equalsIgnoreCase("False")){outStream.println(" sentence no NP: 'False' ");}

//2:::::Vp pasive sentence
else if(countTrueNp>0 && countTrueNp
outStream.println(" Index NP " +indexNp);
outStream.println("");
while(indexNp {

outStream.println("Check "+ arrayToken[indexNp]+" all "+noToken+" current "+indexNp);

for(int checkVp=0;checkVp {
if( arrayToken[indexNp].equalsIgnoreCase(arrayPasive[checkVp]))
{
outStream.println(arrayToken[indexNp].equalsIgnoreCase(arrayPasive[checkVp]));
countTrueToken++;

checktrueVp[indexNp-1]="True";
arrayVpCheck[checkVp]="True";
outStream.println(indexNp);
getCurrentVp++;
break;

}

else
{ outStream.println("FalseVp");
arrayVpCheck[checkVp]="False";
checktrueVp[indexNp-1]="False";}
}

indexNp++;

}//end while NP

//check the index for the next check

int countTrueVp=2;
for(int checkVp=0;checkVp {
if((checktrueVp[checkVp].equalsIgnoreCase("True")&&checktrueVp[checkVp+1].equalsIgnoreCase("False")))
indexVp=checkVp+1;
else if(checktrueVp[checkVp].equalsIgnoreCase("True"))
countTrueVp++;
}

if(countTrueVp==noToken)
{outStream.println(" Np+Vp |negetive|sentences is true");}


//3: sentences NP + Vp normal
else if(countTrueVp >0 && countTrueVp {outStream.println(" Index VP " +(indexVp+1));}


} */


// for(int checkNp=0;checkNp // outStream.println("Try "+ arrayNpCheck[checkNp]);



// get the index for the next check





outStream.println("___________________________________________________________");
outStream.println("___________________________________________________________");
outStream.println("");

// System.out.println(arrayToken[countToken]);
}//close for




}//close main while


}// close try


catch(FileNotFoundException fnf)
{System.out.println("File Not Found");
System.out.println(fnf.getMessage());}

catch(IOException io)
{ System.out.println(io.getMessage()); }

catch(Exception a)
{ }
outStream.close();

if (con != null)
con.close();

}
}