NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;


public class MusicAnalyser {
static class StringPair{
private String string1;
private String string2;

public StringPair(String s1, String s2){
string1 = s1;
string2 = s2;
}

public String getString1() {
return string1;
}

public String getString2() {
return string2;
}

@Override
public int hashCode() {
return string1.hashCode() + string2.hashCode();
}

@Override
public boolean equals(Object obj) {
if(obj instanceof StringPair){
StringPair other = (StringPair)obj;
return (string1.equals(other.string1)&&string2.equals(other.string2))||(string1.equals(other.string2)&&string2.equals(other.string1));
}else{
return super.equals(obj);
}
}
}

public static final int SIZE = 50;

public static void main(String[] args) throws IOException {
Map<String, List<Integer>> artistIndex = new HashMap<String, List<Integer>>();

BufferedReader br = new BufferedReader(new FileReader("Artist_lists_small.txt"));
try {
String line = br.readLine();
Integer lineIndex = 1;
System.out.println("Indexing .. ");
while (line != null) { // making map artist_name -> [line_where_appear1, ..., line_where_appear_n]
String[] artists = line.split(",");
for(String artist : artists){
if(artistIndex.get(artist) == null){
artistIndex.put(artist, new ArrayList<Integer>());
}
artistIndex.get(artist).add(lineIndex);
}
line = br.readLine();
}

int artistId = 1;
int totalArtists = artistIndex.keySet().size();

Set<StringPair> result = new LinkedHashSet<StringPair>();
for(String artist1 : artistIndex.keySet()){ // searching for artists which have line number list intersections bigger than 50
System.out.println("Searching : " + (artistId*100.0f/totalArtists) + "% for " + artist1);
artistId++;

for(String artist2 : artistIndex.keySet()){
if(!artist1.equals(artist2)){ // ignoring same entries
int intercetionSize = 0;
List<Integer> artist1Indexes = artistIndex.get(artist1);
List<Integer> artist2Indexes = new LinkedList<Integer>(artistIndex.get(artist2));

artist2Indexes.retainAll(artist1Indexes);
if(artist2Indexes.size() > SIZE){
result.add(new StringPair(artist1, artist2));
break;
}
}
}
}
System.out.println("Total artists : " + artistIndex.keySet().size());
System.out.println("Matched artists : " + result.size());

System.out.println("Result with intercection size " + SIZE + " :");
} finally {
br.close();
}
}

}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.