//
// 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);		
		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();
					setDataIntegerArray(0, attr);
                    setDataInteger(1, similarCount);
				}
				break;
				
			case 1:
				if(text.sentenceNumber <= text.sentenceRelationLimit)
				{				
					findSimilarSentences();
					setDataInteger(1, similarCount);
				}
		}
	}
    
	void findSimilarSentences()
	{
		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++;
        }
		disposeProcessingPop();

	} 
}