in graphjet-core/src/main/java/com/twitter/graphjet/algorithms/counting/tweet/TopSecondDegreeByCountTweetMetadataRecsGenerator.java [92:172]
public static List<RecommendationInfo> generateTweetMetadataRecs(
TopSecondDegreeByCountRequestForTweet request,
List<NodeInfo> nodeInfoList,
RecommendationType recommendationType
) {
Int2ObjectMap<TweetMetadataRecommendationInfo> visitedMetadata = null;
List<RecommendationInfo> results = new ArrayList<>();
for (NodeInfo nodeInfo : nodeInfoList) {
// Remove unfavorited edges, and discard the nodeInfo if it no longer has social proofs
boolean isNodeModified = NodeInfoHelper.removeUnfavoritedSocialProofs(nodeInfo);
if (isNodeModified && !NodeInfoHelper.nodeInfoHasValidSocialProofs(nodeInfo)) {
continue;
}
int[] metadata = nodeInfo.getNodeMetadata(recommendationType.getValue());
if (metadata == null) {
continue;
}
if (visitedMetadata == null) {
visitedMetadata = new Int2ObjectOpenHashMap<>();
}
for (int j = 0; j < metadata.length; j++) {
TweetMetadataRecommendationInfo recommendationInfo =
visitedMetadata.get(metadata[j]);
if (recommendationInfo == null) {
recommendationInfo = new TweetMetadataRecommendationInfo(
metadata[j],
RecommendationType.at(recommendationType.getValue()),
0,
new HashMap<Byte, Map<Long, LongList>>()
);
}
recommendationInfo.addToWeight(nodeInfo.getWeight());
addToSocialProof(
nodeInfo,
recommendationInfo,
request.getMaxUserSocialProofSize(),
request.getMaxTweetSocialProofSize()
);
visitedMetadata.put(metadata[j], recommendationInfo);
}
}
if (visitedMetadata != null) {
int maxNumResults = GeneratorHelper.getMaxNumResults(request, recommendationType);
int minUserSocialProofSize = GeneratorHelper.getMinUserSocialProofSize(request, recommendationType);
List<TweetMetadataRecommendationInfo> filtered = null;
for (Int2ObjectMap.Entry<TweetMetadataRecommendationInfo> entry
: visitedMetadata.int2ObjectEntrySet()) {
// handling one specific rule related to metadata recommendations.
if (isLessThanMinUserSocialProofSize(
entry.getValue().getSocialProof(),
minUserSocialProofSize)) {
continue;
}
if (filtered == null) {
filtered = new ArrayList<>();
}
filtered.add(entry.getValue());
}
if (filtered != null) {
// sort the list of TweetMetadataRecommendationInfo in ascending order
// according to their weights
Collections.sort(filtered);
int toIndex = Math.min(maxNumResults, filtered.size());
for (int j = 0; j < toIndex; j++) {
results.add(filtered.get(j));
}
}
}
return results;
}