//
// Mining module for TETDM 
// TwiceWords 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.TwiceWords;

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 TwiceWords extends MiningModule
{	
	//hi-light for textDisplay Color
	int attr[];
	int twiceSentenceCount;
	
	public TwiceWords()
	{
		setModuleID(31);
		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:
				findTwiceWordsSentences();
                setDataBoolean(0, true);// for TextDisplayColor
				setDataIntegerArray(0, attr);
                setDataInteger(1, twiceSentenceCount);
				break;
				
			case 1:
				findTwiceWordsSentences();
				setDataInteger(1, twiceSentenceCount);
				break;
                
            case 2:
                findTwiceWordsSentences();
                setDataBooleanArray(0, focusSentences);
                break;
		}
	}
    
	void findTwiceWordsSentences()
	{
        initializeFocusSentences();
        
		twiceSentenceCount = 0;
		
		attr = new int[text.sentenceNumber];
        for(int i=0;i<text.sentenceNumber;i++)
			attr[i] = 10;
		
        for(int i=0;i<text.sentenceNumber;i++)
        {
            if(checkTwiceWords(i) > 1)
				attr[i] = 1;
            else if(checkTwiceWords(i) == 1)
                attr[i] = 5;

			if(attr[i] < 10)
            {
				twiceSentenceCount++;
                focusSentences[i] = true;
            }
        }
        
        setFocusSentences(inJapanese[0],"Twice Words");
	}
    
    int checkTwiceWords(int n)
    {
        int twiceCount = 0;
        
        int idList[] = new int[text.keywordNumber];
        for(int i=0;i<text.keywordNumber;i++)
            idList[i] = 0;
        
        for(int i=0;i<text.sentence[n].keywordNumber;i++)
            idList[text.sentence[n].keywordIDList[i]]++;

        for(int i=0;i<text.keywordNumber;i++)
            if(idList[i] > 1)
                twiceCount++;
        
        return twiceCount;
    }
    
    /*
	void findTwiceWordsSentences()
	{
		twiceCount = 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)
				twiceCount++;
        }
		disposeProcessingPop();

	} */
}
