//
// Mining module for TETDM 
// MorphemeSample.java Version 0.30
// This program is provided under the license.
// You Should read the README file.
//

package module.MiningModules.MorphemeSample;

import source.*;
import source.TextData.*;
//import source.Utility.*;

import java.io.*;

import net.reduls.igo.Tagger;
import net.reduls.igo.Morpheme;


public class MorphemeSample extends MiningModule
{
	public MorphemeSample()
	{
		setModuleID(10002);						// Set your module ID after you have got it
		setCategoryID(8);
		pairingVisualizationID = new int[]{1};
		setToolType(2);
	}

//	public void initializePanel(){}
	
	public void initializeData(){}
	
	public void miningOperations(int optionNumber)
	{
		switch(optionNumber)
		{
			case 0:
                resetData();
				setDataString(MyMethod());
				break;
		}
	}

	String MyMethod()
	{
		StringWriter sw = new StringWriter();			//For words
		BufferedWriter bw = new BufferedWriter(sw);			

		try{		
		
			final String dicDir = text.control.sp1.dictionaryPath+"/ipadic";
			final Tagger tagger = new Tagger(dicDir);
			
			System.out.println("dicDir="+dicDir);
			
			for(Morpheme m : tagger.parse(text.originalText))
			{
				/*
                 for(int i=0;i<(m.start - lastStart) - lastLength;i++)    //If invisible words are included
                 {
                 String unvisibleWord = text.originalText.substring(lastStart+lastLength+i, lastStart+lastLength+i+1);
                 
                 if(unvisibleWord.equals(System.getProperty("line.separator")))
                 bw.write("EOS");
                 else
                 bw.write(inJapanese[0]+"\t"+"SPACE/TAB,*,*,*,*,*,X,*,*");
                 
                 bw.write(System.getProperty("line.separator"));
                 }
                 lastLength = m.surface.length();
                 lastStart = m.start;
				*/
				
//				System.out.println(m.surface+"	"+m.feature); //TAB
				
//				bw.write(m.surface+"	"+m.feature);	//TAB
//				bw.write(System.getProperty("line.separator"));
	
				String speech[] = m.feature.split(",");
				for(int i=2;i<5;i++)
					if(speech[0].equals(inJapanese[i]))
					{
						bw.write(m.surface+"	"+speech[0]);	//TAB
						bw.write(System.getProperty("line.separator"));						
					}
			}
			
			bw.write("EOS");						
			bw.write(System.getProperty("line.separator"));	//need
			
			bw.flush();
			bw.close();			
			
		}
		catch(Exception e){
			System.out.println("writing ERROR in MorphemeSample.java");
		}		

		return sw.toString();	
	}	
}
