
org.reco4j.recommender.ItemFullScanUserRecommender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reco4j-core Show documentation
Show all versions of reco4j-core Show documentation
Reco4j is an open source project aims at developing a recommendation framework based on graph data sources. We choose graph databases for several reasons. They are NoSQL databases, so "schemaless". This means that it is possible to extend the basic data structure with intermediate information, i.e. similarity value between item and so on. Moreover, since every information is expressed with properties, nodes and relations, the recommendation process can be customized to work on every graph.
Reco4j can be used on every graph where "user" and "item" is represented by node and the preferences are modelled as relationship between them.
Current implementation leverage on Neo4j as first graph database integrated in our framework.
The newest version!
/*
* ItemFullScanUserRecommender.java
*
* Copyright (C) 2013 Alessandro Negro
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.reco4j.recommender;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.reco4j.graph.IEdgeType;
import org.reco4j.graph.INode;
import org.reco4j.model.Rating;
import org.reco4j.util.Utility;
/**
*
* @author Luigi Giuri < luigi.giuri at reco4j.org >
*/
public class ItemFullScanUserRecommender
implements IUserRecommender
{
private int recoNumber;
private IPredictor predictor;
protected IEdgeType rankEdgeType;
private Collection items;
public ItemFullScanUserRecommender(int recoNumber, IPredictor predictor, IEdgeType rankEdgeType, Collection items)
{
this.recoNumber = recoNumber;
this.predictor = predictor;
this.rankEdgeType = rankEdgeType;
this.items = items;
}
@Override
public List userRecommend(INode user)
{
return userRecommend(user, items, recoNumber);
}
@Override
public List userRecommend(INode user, Collection itemSet, int limit)
{
ArrayList recommendations = new ArrayList();
for (INode item : itemSet) // learningDataSet.getNodesByType(getConfig().getItemType()))
{
if (item.isConnected(user, rankEdgeType))
continue;
double estimatedRating = predictor.predictRating(user, item);
Utility.orderedInsert(recommendations, estimatedRating, item, limit);
}
return recommendations;
}
@Override
public List recommendInterestedUsers(Collection userSet, INode item, int limit)
{
ArrayList recommendations = new ArrayList();
// ArrayList unrated = new ArrayList();
for (INode user : userSet)
{
// if (user.isConnected(item, rankEdgeType))
// continue;
double estimatedRating = predictor.predictRating(user, item);
if (estimatedRating > 0.0)
Utility.orderedInsert(recommendations, estimatedRating, item, user, limit);
// else
// unrated.add(new Rating(user, item, estimatedRating, null));
}
// while (unrated.size() > 0 && recommendations.size() < limit)
// recommendations.add(unrated.remove(0));
return recommendations;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy