/*
* Copyright [2016-2018] [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 org.scify.jedai.utilities;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.List;

import org.scify.jedai.datamodel.EquivalenceCluster;
import org.scify.jedai.datamodel.EntityProfile;
import gnu.trove.iterator.TIntIterator;

/**
 *
 * @author gap2
 */
public class PrintToFile {

    public static void toCSV(List<EntityProfile> profiles, List<EquivalenceCluster> entityClusters, String filename) throws FileNotFoundException {
        final PrintWriter pw = new PrintWriter(new File(filename));
        final StringBuilder sb = new StringBuilder();

        sb.append("cluster_id,dataset,entity_url\n");
        int counter = 0;
        for (EquivalenceCluster eqc : entityClusters) {
            if (eqc.getEntityIdsD1().isEmpty()) {
                continue;
            }
            counter++;
            for (TIntIterator iterator = eqc.getEntityIdsD1().iterator(); iterator.hasNext();) {
                sb.append(counter).append(",").append(1).append(",")
                .append(profiles.get(iterator.next()).getEntityUrl()).append("\n");
            }
            if (eqc.getEntityIdsD2().isEmpty()) {
                continue;
            }
            for (TIntIterator iterator = eqc.getEntityIdsD2().iterator(); iterator.hasNext();) {
                sb.append(counter).append(",").append(2).append(",")
                .append(profiles.get(iterator.next()).getEntityUrl()).append("\n");
            }
        }
        pw.write(sb.toString());
        pw.close();
    }
}

@@ -604,19 +604,20 @@
 icense.%0A
+ 
 */%0A
-
 package 
@@ -644,16 +644,56 @@
 ities;%0A%0A
+import com.esotericsoftware.minlog.Log;%0A
 import j
@@ -1049,16 +1049,50 @@
 profiles
+D1, List%3CEntityProfile%3E profilesD2
 , List%3CE
@@ -1719,32 +1719,40 @@
                 
+        
 .append(profiles
@@ -1743,32 +1743,34 @@
 .append(profiles
+D1
 .get(iterator.ne
@@ -1901,32 +1901,186 @@
 ;%0A            %7D%0A
+            if (profilesD2 == null) %7B%0A                Log.error(%22The entity profiles of Dataset 2 are missing!%22);%0A                continue;%0A            %7D%0A
             for 
@@ -2237,32 +2237,40 @@
                 
+        
 .append(profiles
@@ -2269,16 +2269,18 @@
 profiles
+D2
 .get(ite
@@ -2329,32 +2329,33 @@
 ;%0A            %7D%0A
+%0A
         %7D%0A      

Update PrintToFile so as to accommodate Clean-Clean ER, too.