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 lt, String str) {

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 lt : lt1) {

for (String str1 : lt) {

if (str.equalsIgnoreCase(str1)) {

num++;

break;

}

}

}

return Math.log(lt1.size() / num);

}

public double frequencyDec(List lt, List> lt1, String str) {

return frequency(lt, str) * idf(lt1, str);

}

public static void main(String[] args) {

List lt2 = Arrays.asList("Yo", "Hello", "Bro", "Sissy", "sit", "Nte");

List lt3 = Arrays.asList("vit", "te", "at", "Sissy", "pro", "quo");

List lt4 = Arrays.asList("Has", "persius", "diss", "dis", "simulation");

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!