@Test
  public void testScoreSeriesEpisodeCounts() {

    ResultDescription desc = desc();
    assertThat(
        scorer.scoreSortedSeriesSizes(list(1, 2, 3, 4), list(1, 2, 3, 4), "candidate", desc),
        is(Score.ONE));
    assertThat(
        scorer.scoreSortedSeriesSizes(list(1, 2, 3, 4, 5), list(1, 2, 3, 4), "candidate", desc),
        is(Score.ONE));
    assertThat(
        scorer.scoreSortedSeriesSizes(list(1, 2, 3, 4), list(1, 3, 4), "candidate", desc),
        is(Score.ONE));
    assertThat(
        scorer.scoreSortedSeriesSizes(list(1, 2, 3, 6), list(1, 3, 5), "candidate", desc),
        is(Score.ONE));

    assertThat(
        scorer.scoreSortedSeriesSizes(list(6, 6), list(24, 24), "candidate", desc),
        is(Score.nullScore()));
    assertThat(
        scorer.scoreSortedSeriesSizes(list(6, 6), list(6, 24, 24), "candidate", desc),
        is(Score.nullScore()));
    assertThat(
        scorer.scoreSortedSeriesSizes(list(2, 3, 4), list(3, 4, 6, 7), "candidate", desc),
        is(Score.nullScore()));
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testScoresNullWhenFlatContainerWithChildCountsOutOfRange() {

    ScoredCandidates<Container> score =
        scorer.score(
            brandWithChildren(5), ImmutableSet.<Container>of(brandWithChildren(7)), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
    verify(contentResolver, never()).findByCanonicalUris((Iterable<String>) any());
  }
Пример #3
0
 /**
  * Calculates a score representing the similarity of the candidate's title compared to the
  * subject's title.
  *
  * @param subject - subject content
  * @param candidate - candidate content
  * @return score representing how closely candidate's title matches subject's title.
  */
 public Score score(Content subject, Content candidate, ResultDescription desc) {
   if (subject.getTitle() == null || candidate.getTitle() == null) {
     return Score.NULL_SCORE;
   }
   String subjectTitle = sanitize(subject.getTitle());
   String contentTitle = sanitize(candidate.getTitle());
   double score = score(subjectTitle, contentTitle);
   desc.appendText(
       "%s vs. %s (%s): %s", subjectTitle, contentTitle, candidate.getCanonicalUri(), score);
   return Score.valueOf(score);
 }
  @Test
  @SuppressWarnings("unchecked")
  public void testScoresNullWhenFlatSubjectHasNoEpisodes() {

    Brand subject = brandWithChildren(0);
    Brand candidate = brandWithChildren(1);

    ScoredCandidates<Container> score = scorer.score(subject, ImmutableSet.of(candidate), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
    verify(contentResolver, never()).findByCanonicalUris((Iterable<String>) any());
  }
  @Test
  public void testScoresNullWhenSeriesContainerWithSeriesCountsOutOfRange() {

    final Brand subject = brandWithSeries(5);

    when(contentResolver.findByCanonicalUris(
            ImmutableList.copyOf(Iterables.transform(subject.getSeriesRefs(), SeriesRef.TO_URI))))
        .thenReturn(ResolvedContent.builder().putAll(series(5)).build());

    ScoredCandidates<Container> score =
        scorer.score(subject, ImmutableSet.<Container>of(brandWithSeries(7)), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testScoresNullWhenCandidateHasNoSeries() {

    Brand subject = brandWithSeries(1);
    Brand candidate = brandWithSeries(0);

    when(contentResolver.findByCanonicalUris(
            ImmutableList.copyOf(Iterables.transform(subject.getSeriesRefs(), SeriesRef.TO_URI))))
        .thenReturn(ResolvedContent.builder().putAll(series(1)).build());

    ScoredCandidates<Container> score = scorer.score(subject, ImmutableSet.of(candidate), desc());

    assertThat(Iterables.getOnlyElement(score.candidates().values()), is(Score.nullScore()));
    verify(contentResolver).findByCanonicalUris((Iterable<String>) any());
  }
 private Score score(int count, int children) {
   double basicScore = (double) count / children;
   return Score.valueOf(Math.min(1.0, basicScore));
 }