/*
* Copyright [2016] [George Papadakis (gpapadis@yahoo.gr)]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package EntityMatching;

import BlockBuilding.*;
import Utilities.DataStructures.AbstractDuplicatePropagation;
import BlockProcessing.IBlockProcessing;
import Utilities.DataStructures.UnilateralDuplicatePropagation;
import DataModel.AbstractBlock;
import DataModel.Comparison;
import DataModel.EntityProfile;
import DataModel.SimilarityPairs;
import DataReader.EntityReader.IEntityReader;
import DataReader.EntityReader.EntitySerializationReader;
import DataReader.GroundTruthReader.GtSerializationReader;
import DataReader.GroundTruthReader.IGroundTruthReader;
import Utilities.Enumerations.BlockBuildingMethod;
import Utilities.TextModels.RepresentationModel;

import java.util.Iterator;
import java.util.List;

/**
 *
 * @author G.A.P. II
 */

public class TestGroupLinkage {
    public static void main(String[] args) {
        String entitiesFilePath = "/home/ethanos/Downloads/JEDAIfiles/cddbTestProfiles";
        String groundTruthFilePath = "/home/ethanos/Downloads/JEDAIfiles/cddbTestDuplicates";
        
        IEntityReader eReader = new EntitySerializationReader(entitiesFilePath);
        List<EntityProfile> profiles = eReader.getEntityProfiles();
        System.out.println("Input Entity Profiles\t:\t" + profiles.size());
        
        IGroundTruthReader gtReader = new GtSerializationReader(groundTruthFilePath);
        final AbstractDuplicatePropagation duplicatePropagation = new UnilateralDuplicatePropagation(gtReader.getDuplicatePairs(eReader.getEntityProfiles()));
        System.out.println("Existing Duplicates\t:\t" + duplicatePropagation.getDuplicates().size());
        
        for (BlockBuildingMethod blbuMethod : BlockBuildingMethod.values()) {

            System.out.println("\n\nCurrent blocking metohd\t:\t" + blbuMethod);
            IBlockBuilding blockBuildingMethod = BlockBuildingMethod.getDefaultConfiguration(blbuMethod);
            List<AbstractBlock> blocks = blockBuildingMethod.getBlocks(profiles, null);
            System.out.println("Original blocks\t:\t" + blocks.size());
            
            IBlockProcessing blockCleaningMethod = BlockBuildingMethod.getDefaultBlockCleaning(blbuMethod);
            if (blockCleaningMethod != null) {
                blocks = blockCleaningMethod.refineBlocks(blocks);
            }
            
            IBlockProcessing comparisonCleaningMethod = BlockBuildingMethod.getDefaultComparisonCleaning(blbuMethod);
            if (comparisonCleaningMethod != null) {
                blocks = comparisonCleaningMethod.refineBlocks(blocks);
            }
            
            for ( AbstractBlock bl : blocks) {
            	Iterator<Comparison> iterator = bl.getComparisonIterator();
                while (iterator.hasNext()) {
                	Comparison currentComparison = iterator.next();
                	System.out.println(currentComparison.getEntityId1()+" "+currentComparison.getEntityId2());
                }
            }
            
            for (RepresentationModel model : RepresentationModel.values()) {

                GroupLinkage gp = new GroupLinkage(model);
                gp.setSimilarityThreshold(0.1);
                SimilarityPairs simPairs = gp.executeComparisons(blocks, profiles);
                System.out.println();
                for (int i = 0; i < simPairs.getNoOfComparisons(); i++) {
                    System.out.println(simPairs.getEntityIds1()[i] + "\t\t" + simPairs.getEntityIds2()[i] + "\t\t" + simPairs.getSimilarities()[i]);
                }
            	
            }
        	
        }
    }
}

@@ -3229,32 +3229,34 @@
 %0D%0A            %0D%0A
+//
             for 
@@ -3283,24 +3283,26 @@
  blocks) %7B%0D%0A
+//
             
@@ -3359,24 +3359,26 @@
 terator();%0D%0A
+//
             
@@ -3407,24 +3407,26 @@
 sNext()) %7B%0D%0A
+//
             
@@ -3475,24 +3475,26 @@
 or.next();%0D%0A
+//
             
@@ -3586,24 +3586,26 @@
 ityId2());%0D%0A
+//
             
@@ -3603,32 +3603,34 @@
              %7D%0D%0A
+//
             %7D%0D%0A 

update test for GroupLinkage