📄 amqueryexpand.java
字号:
package searchingEngine.queryExpansion;
import java.io.*;
import java.util.*;
import searchingEngine.dataPreprocessing.invertedFile.TermNode;
import searchingEngine.utilites.dataConverter.RawConverter;
import searchingEngine.utilites.sorting.*;
public class AMQueryExpand
{
static final double threshould = 0.5;
static final int topXterms = 2;
LinkedList<TermNode> termList;
AssociationMartix am;
static{
try{
// get association matrix
termList = (LinkedList<TermNode>)RawConverter.loadObject("combined0.dat");
am = new AssociationMartix(termList.size());
am.generateAssoMat(termList,IS_METRIC);
System.out.println("AssociationMartix:");
RawConverter.saveObject(am,"am0.dat");
} catch(Exception ex){ ex.printStackTrace(); }
}
public String[] getAssociatedTerm(String term, boolean topRankMethod)
{
if(topRankMethod) return topRanking(term);
else return thresholding(term);
}
private String[] topRanking(String term)
{
int termIndex = Collections.binarySearch(termList, term);
Hashtable resultValue = new Hashtable();
double Sij;
for(int i=0; i<termList.size(); i++)
{
if(i<termIndex) Sij = am.getValueAt(termIndex, i);
else if(i>termIndex) Sij = am.getValueAt(i, termIndex);
else Sij = -1;
if(Sij>0)
resultValue.put(termList.get(i).term, Sij);
}
String[] result = new String[topXterms];
double[] topValues = new double[topXterms];
for(int i=0; i<topXterms; i++)
topValues[i] = 0;
for(Enumeration e=resultValue.keys(); e.hasMoreElements(); )
{
String term = (String)e.nextElement();
double value = ((Float)resultValue.get(term)).doubleValue();
for(int i=0; i<topXterms; i++)
{
if(value>topValues[i])
{
for(j=topXterms-1; j>i; j--)
topValues[j] = topValues[j-1];
topValues[i] = value;
result[i] = term;
break;
}
}
}
return (result!=null?result:new String[0]);
}
private String[] thresholding(String term)
{
int termIndex = Collections.binarySearch(termList, term);
Vector result = new Vector();
double Sij;
for(int i=0; i<termList.size(); i++)
{
if(i<termIndex) Sij = am.getValueAt(termIndex, i);
else if(i>termIndex) Sij = am.getValueAt(i, termIndex);
else Sij = -1;
if(Sij>0 && Sij>threshould)
result.add(termList.get(i).term);
}
return (result!=null?(String[])result.toArray(new String[0]):new String[0]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -