示例#1
0
 FeatureIterator find(string name) {
     return feat_map.find(name);
 }
示例#2
0
//计算基于route元路径从id为fromId的ITEM到另一个item的特征值MAP
FeatureMap calFeature(int fromId,const char *route,int length){
    FeatureMap result;
    Item *item1=::getItemPtrbyId(fromId,route[0],NOALLOWNEW);
    if(item1==NULL){
        cout<<"error:NO this Item!"<<endl;
        return result;
    }
    EdgeMap *edgelist1=item1->getToItemE(route[1]);
    int allweight1=item1->getAllWeight(route[1]);
    for(EdgeMap::const_iterator iter1=edgelist1->begin();iter1!=edgelist1->end();++iter1){
        int id2=iter1->first;
        float weight=1;
        if(iter1->second!=NULL){
            if(route[0]=='U'&&route[1]=='U'){
                weight=iter1->second->getCount();
            }else{
                weight=iter1->second->getWeight();
            }
        }
        float feat1=weight/allweight1;
        //cout<<feat1;
        Item * item2=::getItemPtrbyId(id2,route[1],NOALLOWNEW);
        EdgeMap *edgelist2=item2->getToItemE(route[2]);
        int allweight2=item2->getAllWeight(route[2]);

        for(EdgeMap::const_iterator iter2=edgelist2->begin();iter2!=edgelist2->end();++iter2){
            int id3=iter2->first;
            float weight=1;
            if(iter2->second!=NULL){
                if(route[1]=='U'&&route[2]=='U'){
                    weight=iter2->second->getCount();
                }else{
                    weight=iter2->second->getWeight();
                }
            }
            float feat2=weight/allweight2;
            if(length==2){
                if(!::isNeighbor(fromId,route[0],id3,route[2])){
                    //这个节点和原节点没有连接,计算他们之间的元路径特征值
                    float feature=feat1*feat2;
                    FeatureMap::iterator fiter=result.find(id3);
                    if(fiter==result.end()){
                            result.insert(FeatureMap::value_type(id3,feature));
                    }
                    else{
                        fiter->second=feature+fiter->second;
                    }
                }
            }else{
                Item * item3=::getItemPtrbyId(id3,route[2],NOALLOWNEW);
                EdgeMap *edgelist3=item3->getToItemE(route[3]);
                int allweight3=item3->getAllWeight(route[3]);
                for(EdgeMap::const_iterator iter3=edgelist3->begin();iter3!=edgelist3->end();++iter3){
                    int id4=iter3->first;
                    float weight=1;
                    if(iter3->second!=NULL){
                         if(route[2]=='U'&&route[3]=='U'){
                             weight=iter3->second->getCount();
                          }else{
                            weight=iter3->second->getWeight();
                          }
                    }
                    float feat3=weight/allweight3;
                    if(!::isNeighbor(fromId,route[0],id4,route[3])){
                        float feature=feat1*feat2*feat3;
                        FeatureMap::iterator fiter=result.find(id4);
                        if(fiter==result.end()){
                            result.insert(FeatureMap::value_type(id4,feature));
                        }
                        else{
                            fiter->second=feature+fiter->second;
                        }
                    }
                }
            }
         }
    }
    return result;
}