I have two CSV files: "userfeatures" and "itemfeatures".
I should compare each line of userfeatures with each line of itemfeatures to find the matches (intersections) with each line. For example, the first line in the userfeature file is:
005c2e08","Action","nm0000148","dir_ nm0764316","India"
Now, I need to find the intersection of this line (whish is related to user-1) with every line of the 2nd file "itemfeatures". The second file has the same structure, So for instance, the first comparison will be with the first line of "itemfeatures" that is:
"tt0306047","Comedy","nm0267506,nm0000221,nm0356021","dir_ nm0001878","USA,Canada"
Here is what I've tried so far:
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader userfeatures = new BufferedReader(new FileReader("userfeatures.csv"));
BufferedReader itemfeatures = new BufferedReader(new FileReader("itemfeatures.csv"));
ArrayList<String> userlines = new ArrayList<>();
ArrayList<String> itemlines = new ArrayList<>();
String Uline = null;
String Iline = null;
while ((Uline = userfeatures.readLine()) != null) {
for (int i=1; i< userlines.size(); i++){
userlines.add(Uline);
intersect(Uline, Iline).size();
}
}
// System.out.println(Uline);
userfeatures.close();
itemfeatures.close();
}
static ArrayList<String> intersect(String Uline, String Iline) {
ArrayList<String> result = new ArrayList<String>();
result.retainAll(Iline);
return result;
}
}
It seems I cannot use retainAll for the type "String", so I was wondering how could I fix this issue? I searched here a lot, but all I found was about finding intersection of arrays except this one. (but also this post was different with my case, since it compared each characters in a string while I need to compare word by word).