【发布时间】:2015-05-11 21:56:14
【问题描述】:
我使用 Dico 类来存储术语的权重和出现的文档 ID
public class Dico
{
private String m_term; // term
private double m_weight; // weight of term
private int m_Id_doc; // id of doc that contain term
public Dico(int Id_Doc,String Term,double tf_ief )
{
this.m_Id_doc = Id_Doc;
this.m_term = Term;
this.m_weight = tf_ief;
}
public String getTerm()
{
return this.m_term;
}
public double getWeight()
{
return this.m_weight;
}
public void setWeight(double weight)
{
this.m_weight= weight;
}
public int getDocId()
{
return this.m_Id_doc;
}
}
我使用这种方法从Map<String,Double> 和List<Dico> 计算最终重量:
public List<Dico> merge_list_map(List<Dico> list,Map<String,Double> map)
{
// in map each term is unique but in list i have redundancy
List<Dico> list_term_weight = new ArrayList <>();
for (Map.Entry<String,Double> entrySet : map.entrySet())
{
String key = entrySet.getKey();
Double value = entrySet.getValue();
for(Dico dic : list)
{
String term =dic.getTerm();
double weight = dic.getWeight();
if(key.equals(term))
{
double new_weight =weight*value;
list_term_weight.add(new Dico(dic.getDocId(), term, new_weight));
}
}
}
return list_term_weight;
}
我在地图中有 36736 个元素,在列表中有 1053914 个元素,目前这个程序需要大量时间来编译:BUILD SUCCESSFUL(总时间:17 分 15 秒)。
我怎样才能只从列表中获取与地图中的术语相同的术语?
【问题讨论】:
-
使用两张地图,而不是一张地图和一张列表。
-
如何初始化地图?您是否拥有列表中的所有术语,或者它是一个子集?
-
您在谈论 编译 时间和 BUILD SUCCESSFUL,即使您的问题显然是 运行时间 问题。你能确认一下吗?
-
是的,因为下一步是使用该术语对具有 SOM 神经元网络的节点进行分类
标签: java optimization arraylist hashmap