Question: I have this Java code that uses TF-IDF Algorithm. Is there any way to edit it so it takes an arbitrary dataset (Larger dataset) found
I have this Java code that uses TF-IDF Algorithm. Is there any way to edit it so it takes an arbitrary dataset (Larger dataset) found anywhere of anything and displays the results?
Also shows: Return Pos., Name/Document#, Sum Fw,d, and Sum wd
*****Current code only shows Name and Sum wd
Example:
| Return Pos. | Name/Document # | Sum Fw,d | Sum wd |
| 1 | 64 | 139 | 1.83 |
| 2 | 879 | 136 | 4.52 |
| 3 | 710 | 87 | 0.24 |
Main.java
import java.util.Arrays;
import java.util.List;
public class Main {
public double frequency(List
double res = 0;
for (String str1 : lt) {
if (str.equalsIgnoreCase(str1))
res++;
}
return res / lt.size();
}
public double idf(List> lt1, String str) {
double num = 0;
for (List
for (String str1 : lt) {
if (str.equalsIgnoreCase(str1)) {
num++;
break;
}
}
}
return Math.log(lt1.size() / num);
}
public double frequencyDec(List> lt1, String str) {
return frequency(lt, str) * idf(lt1, str);
}
public static void main(String[] args) {
List
List
List
List> lt5 = Arrays.asList(lt2, lt3, lt4);
Main m = new Main();
double freq1 = m.frequencyDec(lt2, lt5, "Sissy");
System.out.println("TF-IDF (Sissy) = " + freq1);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
