Ejemplo n.º 1
0
        /// <p>
        /// Like {@link #GenericItemSimilarity(Iterable)}, but will only keep the specified number of similarities
        /// from the given {@link Iterable} of similarities. It will keep those with the highest similarity -- those
        /// that are therefore most important.
        /// </p>
        ///
        /// <p>
        /// Thanks to tsmorton for suggesting this and providing part of the implementation.
        /// </p>
        ///
        /// @param similarities
        ///          set of {@link ItemItemSimilarity}s on which to base this instance
        /// @param maxToKeep
        ///          maximum number of similarities to keep
        public GenericItemSimilarity(IEnumerable <ItemItemSimilarity> similarities, int maxToKeep)
        {
            var keptSimilarities =
                TopItems.GetTopItemItemSimilarities(maxToKeep, similarities.GetEnumerator());

            initSimilarityMaps(keptSimilarities.GetEnumerator());
        }
Ejemplo n.º 2
0
        /// <p>
        /// Like {@link #GenericItemSimilarity(ItemSimilarity, DataModel)} )}, but will only keep the specified
        /// number of similarities from the given {@link DataModel}. It will keep those with the highest similarity
        /// -- those that are therefore most important.
        /// </p>
        ///
        /// <p>
        /// Thanks to tsmorton for suggesting this and providing part of the implementation.
        /// </p>
        ///
        /// @param otherSimilarity
        ///          other {@link ItemSimilarity} to get similarities from
        /// @param dataModel
        ///          data model to get items from
        /// @param maxToKeep
        ///          maximum number of similarities to keep
        /// @throws TasteException
        ///           if an error occurs while accessing the {@link DataModel} items
        public GenericItemSimilarity(IItemSimilarity otherSimilarity,
                                     IDataModel dataModel,
                                     int maxToKeep)
        {
            long[] itemIDs          = GenericUserSimilarity.longIteratorToList(dataModel.GetItemIDs());
            var    it               = new DataModelSimilaritiesIterator(otherSimilarity, itemIDs);
            var    keptSimilarities = TopItems.GetTopItemItemSimilarities(maxToKeep, it);

            initSimilarityMaps(keptSimilarities.GetEnumerator());
        }