public List<fsp_Clanci_SelectById_Result> GetTopArticles(int userId)
{
List<Korisnici> usersInClaster = GenerateUserCluster(userId);
//Dodati aktivnog korisnika u klaster
usersInClaster.Add(DAKorisnici.GetByID(userId));
//Učitati kolekciju pregledanih članaka sličnih korisnika koje aktivni korisnik nije već ocijenio, pregledao
List<ItemProfile> articles = new List<ItemProfile>();
List<ItemProfile> activeUserArticles = new List<ItemProfile>();
foreach (Korisnici item in usersInClaster)
{
List<fsp_Clanci_SelectUserCollection_Result> initArticles = Connection.dm.fsp_Clanci_SelectUserCollection(item.KorisnikID, 3).ToList();
foreach (fsp_Clanci_SelectUserCollection_Result a in initArticles)
{
ItemProfile ip = new ItemProfile(a.ClanakID, DAClanci.SelectTags(a.ClanakID));
articles.Add(ip);
if (item.KorisnikID == userId)
activeUserArticles.Add(ip);
}
}
//articles = articles.Distinct().ToList();
//Filtrirati tagove i proračunati "tag weight" za preostale
CompleteItemProfile(articles);
//Ukloniti pregledane članke aktivnog korisnika i kopirati "tag weight"
for (int i = 0; i < articles.Count; i++)
{
if (activeUserArticles.Contains(articles[i]))
{
articles.RemoveAt(i);
i--;
}
}
//Učitati kolekciju članaka aktivnog korisnika i ponoviti postupak za određivanja "tag weight"
//Formirati matricu sličnih članaka i primijeniti treshold 0.3
List<fsp_Clanci_SelectById_Result> recommendations = new List<fsp_Clanci_SelectById_Result>();
foreach (ItemProfile activeItem in activeUserArticles)
{
foreach (ItemProfile otherItem in articles)
{
double sim = CalculateCosineSimilarity(activeItem.ItemTags, otherItem.ItemTags);
if (sim > 0.3)
{
//Provjeriti da li je članak već preporučen (sličan nekom od prethodnih)
bool exist = false;
foreach (fsp_Clanci_SelectById_Result item in recommendations)
{
if (item.ClanakID == otherItem.ID)
{
exist = true;
break;
}
}
if (!exist)
recommendations.Add(DAClanci.SelectById(otherItem.ID));
}
}
}
return recommendations.OrderByDescending(x=>x.ProsjecnaOcjena).ToList();
}