Last active
March 2, 2016 04:56
-
-
Save mi-yu/b5e9a1746136241211bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
class TeamMaker { | |
public static void main (String args[]) throws IOException { | |
BufferedReader f = new BufferedReader(new FileReader("data.tsv")); // name your file whatever (needs to be tsv) | |
f.readLine(); | |
TreeMap<String,ArrayList<String>> eventsMap = new TreeMap(); | |
String temp; | |
while ((temp = f.readLine()) != null) { | |
String[] line = temp.split("\t"); | |
String name = line[1]+" "+line[2]; // columns for first and last name respectively | |
String[] events = line[7].split(", "); // column with event info | |
for (String s : events) { | |
if (!eventsMap.containsKey(s)) { //checks if first occurence of key | |
eventsMap.put(s, new ArrayList<String>()); | |
} | |
eventsMap.get(s).add(name); // add name to end of ArrayList of specific event | |
} | |
} | |
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("parsed.tsv"))); | |
Set keys = eventsMap.keySet(); | |
for (Object o : keys){ | |
String s = (String)o; | |
out.print(s+"\t"); | |
ArrayList<String> people = eventsMap.get(s); | |
for (String p : people) { | |
out.print(p+"\t"); | |
} | |
out.print("\n"); | |
} | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment