141 lines
4.7 KiB
Java
Executable File
141 lines
4.7 KiB
Java
Executable File
package ISL;
|
|
|
|
import Fichero.*;
|
|
import java.util.ArrayList;
|
|
import java.util.Scanner;
|
|
|
|
public class Principal {
|
|
|
|
private static Coleccion MiColeccion;
|
|
private static ISL MiMatriz;
|
|
private static ArrayList<Resultado> LResultados;
|
|
|
|
public static void main(String[] args) {
|
|
Scanner consola = new Scanner(System.in);
|
|
// System.out.print("Entre el num de la pregunta (1-35): ");
|
|
// int num_cons = consola.nextInt();
|
|
|
|
|
|
|
|
for (int cons = 1; cons <= 19; cons++) {
|
|
MiColeccion = new Coleccion();
|
|
LResultados = new ArrayList<>();
|
|
MiColeccion.ConvertirFicheroStopword();
|
|
MiColeccion.ConvertirFicheroRelevancia();
|
|
MiColeccion.ConvertirFicheroDocumetos();
|
|
|
|
System.out.println("Consulta : " + cons);
|
|
System.out.println();
|
|
|
|
MiColeccion.setNum_consulta(cons);
|
|
MiColeccion.ConvertirConsulta();
|
|
MiColeccion.Total_terminos_Doc_Cons();
|
|
|
|
double[][] matriz_txd = MiColeccion.Matriz_frecuencia_term(); //
|
|
|
|
int filas;
|
|
filas = matriz_txd.length;
|
|
MiMatriz = new ISL(matriz_txd, filas, 551);
|
|
|
|
MiMatriz.Calcular_peso();
|
|
|
|
MiMatriz.MatrizU();
|
|
MiMatriz.MatrizS();
|
|
MiMatriz.MatrizV();
|
|
|
|
int k = 20;
|
|
MiMatriz.MatrizUk(k);
|
|
MiMatriz.MatrizSk(k);
|
|
MiMatriz.MatrizVk(k);
|
|
|
|
MiMatriz.TransformarVectorConsulta();
|
|
MiMatriz.Distancia();
|
|
|
|
Lista_Resultado_Ordenado();
|
|
Calcular_Doc_Rel_Recup();
|
|
|
|
//----PAra calcular Presicion Exhaustividad y Medida F
|
|
|
|
float doc_relev_recup = 0;
|
|
float doc_recup = LResultados.size();
|
|
int pos = MiColeccion.getNum_consulta() - 1;
|
|
Relevancia MisDocsRel = MiColeccion.getLRelevancia().get(pos);
|
|
float doc_relev = MisDocsRel.getLista_doc().size();
|
|
|
|
for (int i = 0; i < doc_recup; i++) {
|
|
|
|
for (int j = 0; j < MisDocsRel.getLista_doc().size(); j++) {
|
|
|
|
if (LResultados.get(i).getDoc().getIdentificador().equals(MisDocsRel.getLista_doc().get(j))) {
|
|
doc_relev_recup++;
|
|
}
|
|
|
|
}
|
|
}
|
|
System.out.println("doc relevantes: " + doc_relev);
|
|
System.out.println("doc relevantes recuperados: " + doc_relev_recup);
|
|
System.out.println("doc recuperados: " + doc_recup);
|
|
|
|
int B = 1;
|
|
|
|
float exhaustividad = (doc_relev_recup) / (doc_relev);
|
|
float precision = doc_relev_recup / doc_recup;
|
|
|
|
double medida_F = ((Math.pow(B, 2) + 1) * precision * exhaustividad) / ((Math.pow(B, 2) * precision) + exhaustividad);
|
|
|
|
System.out.println("Precision: " + precision);
|
|
System.out.println("Cobertura: " + exhaustividad);
|
|
System.out.println("Medida-F: " + medida_F);
|
|
|
|
System.out.println();
|
|
System.out.println("-------------------------------------------------------");
|
|
System.out.println();
|
|
|
|
}
|
|
}
|
|
|
|
public static void Lista_Resultado_Ordenado() {
|
|
|
|
LResultados = new ArrayList<>();
|
|
|
|
for (int i = 0; i < MiColeccion.getLDocumentos().size(); i++) {
|
|
|
|
if (MiMatriz.getDistancia(i) > 0.5) { //Se recuperan los que la distancia sea > 0 (umbral)
|
|
Resultado unResult = new Resultado(MiColeccion.getLDocumentos(i), MiMatriz.getDistancia(i));
|
|
LResultados.add(unResult);
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < LResultados.size() - 1; j++) { // ordena los resultados de mayor a menor
|
|
for (int k = j + 1; k < LResultados.size(); k++) {
|
|
|
|
if (LResultados.get(j).getSimilitud() < LResultados.get(k).getSimilitud()) {
|
|
Resultado resul_temp1 = LResultados.get(j);
|
|
Resultado resul_temp2 = LResultados.get(k);
|
|
LResultados.set(j, resul_temp2);
|
|
LResultados.set(k, resul_temp1);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//Mostrar_Result();
|
|
}
|
|
|
|
public static void Mostrar_Result() {
|
|
|
|
for (int k = 0; k < LResultados.size(); k++) {
|
|
System.out.print(LResultados.get(k).getDoc().getIdentificador() + ": ");
|
|
System.out.println();
|
|
System.out.print(LResultados.get(k).getSimilitud());
|
|
System.out.println();
|
|
System.out.println();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public static void Calcular_Doc_Rel_Recup() {
|
|
}
|
|
}
|