//
// Mining module for TETDM 
// SimilarSentence.java Version 0.58
// Copyright(C) 2014 System Interface Laboratory All RIGHTS RESERVED.
// This program is provided under the license.
// You Should read the README file.
//

package module.MiningModules.SimilarSentence;

import source.*;
import source.TextData.*;

import java.io.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import java.util.*;

public class SimilarSentence extends MiningModule
{	
	//hi-light for textDisplay Color
	int attr[];
	int similarCount;
	
	public SimilarSentence()
	{
		setModuleID(30);
		setCategoryID(3);
		setUseMode(0);
		pairingVisualizationID = new int[]{2};
		setToolType(2);		
	}
    
	public void initializePanel(){}

    public void initializeData(){}
	
    public void miningOperations(int optionNumber)
	{
	    switch(optionNumber)
		{
			case 0:
				if(text.sentenceNumber <= text.sentenceRelationLimit)
				{
					findSimilarSentences();
                    setDataBoolean(0, true);// for TextDisplayColor
					setDataIntegerArray(0, attr);
                    setDataInteger(1, similarCount);
				}
                else
                {
                    initializeFocusSentences();
                    setFocusSentences(inJapanese[0], "Similar");
                }
				break;
				
			case 1:
				if(text.sentenceNumber <= text.sentenceRelationLimit)
				{				
					findSimilarSentences();
					setDataInteger(1, similarCount);
				}
                break;
		}
	}
    
	void findSimilarSentences()
	{
        initializeFocusSentences();
        
		similarCount = 0;
		
		attr = new int[text.sentenceNumber];
        for(int i=0;i<text.sentenceNumber;i++)
			attr[i] = 10;		
        
		createProcessingPop();
		
        for(int i=0;i<text.sentenceNumber;i++)
        {
			setProcessingPercent((int)(i*100/text.sentenceNumber));				
				
			for(int j=0;j<text.sentenceNumber;j++)
			{
				if(i == j)
					continue;
				
				if(text.sentenceRelation.cos[i][j] >= 0.75 && text.sentenceRelation.coFrequency[i][j] >= 5)
				{
					attr[i] = 1;
					break;
				}
				else if(text.sentenceRelation.cos[i][j] >= 0.60 && text.sentenceRelation.coFrequency[i][j] >= 4)
					attr[i] = 5;
			}
			if(attr[i] < 10)
            {
				similarCount++;
                focusSentences[i] = true;
            }
        }
        
        setFocusSentences(inJapanese[0], "Similar");
        
		disposeProcessingPop();

	} 
}
