/*
* 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 gnu.trove.iterator.TIntIterator;

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

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

        int counter = 0;
        for (EquivalenceCluster eqc : entityClusters) {
            if (eqc.getEntityIdsD1().isEmpty()) {
                continue;
            }
            counter++;
            sb.append("\nEquivalence cluster : ").append(counter).append("\n").append("Dataset 1 : ");;
            for (TIntIterator iterator = eqc.getEntityIdsD1().iterator(); iterator.hasNext();) {
                sb.append(iterator.next());
                sb.append(',');
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append('\n');
            if (eqc.getEntityIdsD2().isEmpty()) {
                continue;
            }
            sb.append("Dataset 2 : ");
//            sb.deleteCharAt(sb.length() - 1);
            for (TIntIterator iterator = eqc.getEntityIdsD2().iterator(); iterator.hasNext();) {
                sb.append(iterator.next());
                sb.append(',');
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append('\n');
        }
        pw.write(sb.toString());
        pw.close();
    }
}

@@ -803,24 +803,72 @@
 nceCluster;%0A
+import org.scify.jedai.datamodel.EntityProfile;%0A
 import gnu.t
@@ -980,16 +980,46 @@
 d toCSV(
+List%3CEntityProfile%3E profiles, 
 List%3CEqu
@@ -1222,16 +1222,70 @@
 der();%0A%0A
+        sb.append(%22cluster_id,dataset,entity_url%5Cn%22);%0A
         
@@ -1474,112 +1474,8 @@
 ++;%0A
-            sb.append(%22%5CnEquivalence cluster : %22).append(counter).append(%22%5Cn%22).append(%22Dataset 1 : %22);;%0A
     
@@ -1597,52 +1597,46 @@
 end(
-iterator.next());%0A                sb
+counter).append(%22,%22).append(1)
 .append(
 ',')
@@ -1623,37 +1623,36 @@
 ppend(1).append(
-',');
+%22,%22)
 %0A            %7D%0A 
@@ -1640,38 +1640,32 @@
 ,%22)%0A        
-    %7D%0A
         
     sb.delet
@@ -1656,74 +1656,89 @@
     
-    sb.deleteCharAt(sb.length() - 1);%0A            sb.append('%5Cn');
+.append(profiles.get(iterator.next()).getEntityUrl()).append(%22%5Cn%22);%0A            %7D
 %0A   
@@ -1828,95 +1828,8 @@
   %7D%0A
-            sb.append(%22Dataset 2 : %22);%0A//            sb.deleteCharAt(sb.length() - 1);%0A
     
@@ -1951,52 +1951,46 @@
 end(
-iterator.next());%0A                sb
+counter).append(%22,%22).append(2)
 .append(
 ',')
@@ -1989,13 +1989,12 @@
 end(
-',');
+%22,%22)
 %0A   
@@ -2006,84 +2006,93 @@
     
-%7D%0A            sb.deleteCharAt(sb.length() - 1);%0A            sb.append('%5Cn');
+    .append(profiles.get(iterator.next()).getEntityUrl()).append(%22%5Cn%22);%0A            %7D
 %0A   

patch for issue 7: update PrintToFile class to output entity urls