//
// 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
{
	String inJapanese[];
	
	public MorphemeSample()
	{
		setModuleID(10002);						// Set your module ID after you have got it
		setCategoryID(2);
		pairingVisualizationID = new int[]{1};
		setToolType(2);
	}

//	public void initializePanel(){}
	
	public void initializeData()
	{
		inJapanese = fileReadArray();
	}
	
	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))
			{
//				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=0;i<3;i++)
					if(speech[0].equals(inJapanese[i]))
					{
						bw.write(m.surface+"	"+speech[0]);	//TAB
						bw.write(System.getProperty("line.separator"));						
					}
			}
						
			bw.write(System.getProperty("line.separator"));
			bw.flush();
			
		}
		catch(Exception e){
			System.out.println("writing ERROR in MorphemeSample.java");
		}		

		return sw.toString();	
	}	
}
