Here you can find the source of saveFormedClustersToFile(Vector
Parameter | Description |
---|---|
names | The list of entity names in order as read from the file that was clustered. |
clusters | The list of clusters of entity IDs |
filename | The path to the file to save in. |
public static void saveFormedClustersToFile(Vector<String> names, Collection<Set<Integer>> clusters, String filename)
//package com.java2s; //License from project: Apache License import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; import java.util.Set; import java.util.Vector; public class Main { /**/*from ww w . j a va 2s .c om*/ * Takes a list of clusters (a cluster is a set of integers), and maps the integer * IDs to the given list of string entity names. Saves the string names to file. * @param names The list of entity names in order as read from the file * that was clustered. * @param clusters The list of clusters of entity IDs * @param filename The path to the file to save in. */ public static void saveFormedClustersToFile(Vector<String> names, Collection<Set<Integer>> clusters, String filename) { try { BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); for (Set<Integer> cluster : clusters) { boolean first = true; for (Integer nameID : cluster) { if (!first) writer.write(", "); writer.write(names.get(nameID)); first = false; } writer.write("\n"); } } catch (IOException ex) { ex.printStackTrace(); } } /** * Takes a list of clusters (a cluster is a set of integers), and maps the integer * IDs to the given list of string entity names. Saves the string names to file. * @param names The list of entity names in order as read from the file * that was clustered. * @param clusters The list of clusters of entity IDs * @param filename The path to the file to save in. */ public static void saveFormedClustersToFile(Vector<String> names, Set<Integer>[] clusters, String filename) { try { BufferedWriter writer = new BufferedWriter(new FileWriter(filename)); for (Set<Integer> cluster : clusters) { boolean first = true; for (Integer nameID : cluster) { if (!first) writer.write(", "); writer.write(names.get(nameID)); first = false; } writer.write("\n"); } } catch (IOException ex) { ex.printStackTrace(); } } }