public static List generateTweetRecs()

in graphjet-core/src/main/java/com/twitter/graphjet/algorithms/counting/tweet/TopSecondDegreeByCountTweetRecsGenerator.java [52:91]


  public static List<RecommendationInfo> generateTweetRecs(
    TopSecondDegreeByCountRequestForTweet request,
    List<NodeInfo> nodeInfoList) {
    int maxNumResults = GeneratorHelper.getMaxNumResults(request, RecommendationType.TWEET);
    int minUserSocialProofSize = GeneratorHelper.getMinUserSocialProofSize(request, RecommendationType.TWEET);
    byte[] validSocialProofs = request.getSocialProofTypes();

    PriorityQueue<NodeInfo> topResults = new PriorityQueue<>(maxNumResults);

    // handling specific rules of tweet recommendations
    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;
      }

      // do not return if size of each social proof or size of each social proof union
      // is less than minUserSocialProofSize.
      if (isLessThanMinUserSocialProofSize(nodeInfo.getSocialProofs(), validSocialProofs, minUserSocialProofSize) &&
        isLessThanMinUserSocialProofSizeCombined(
          nodeInfo.getSocialProofs(), minUserSocialProofSize, request.getSocialProofTypeUnions())) {
        continue;
      }
      GeneratorHelper.addResultToPriorityQueue(topResults, nodeInfo, maxNumResults);
    }

    List<RecommendationInfo> outputResults = Lists.newArrayListWithCapacity(topResults.size());
    while (!topResults.isEmpty()) {
      NodeInfo nodeInfo = topResults.poll();
      outputResults.add(
        new TweetRecommendationInfo(
          TWEET_ID_MASK.restore(nodeInfo.getNodeId()),
          nodeInfo.getWeight(),
          GeneratorHelper.pickTopSocialProofs(nodeInfo.getSocialProofs())));
    }
    Collections.reverse(outputResults);

    return outputResults;
  }