### Question:
Similarity extends AbstractALSResource { @GET @Path("{itemID : .+}") @Produces({MediaType.TEXT_PLAIN, "text/csv", MediaType.APPLICATION_JSON}) public List<IDValue> get( @PathParam("itemID") List<PathSegment> pathSegmentsList, @DefaultValue("10") @QueryParam("howMany") int howMany, @DefaultValue("0") @QueryParam("offset") int offset, @QueryParam("rescorerParams") List<String> rescorerParams) throws OryxServingException { check(!pathSegmentsList.isEmpty(), "Need at least 1 item to determine similarity"); int howManyOffset = checkHowManyOffset(howMany, offset); ALSServingModel alsServingModel = getALSServingModel(); float[][] itemFeatureVectors = new float[pathSegmentsList.size()][]; Collection<String> knownItems = new HashSet<>(); for (int i = 0; i < itemFeatureVectors.length; i++) { String itemID = pathSegmentsList.get(i).getPath(); float[] itemVector = alsServingModel.getItemVector(itemID); checkExists(itemVector != null, itemID); itemFeatureVectors[i] = itemVector; knownItems.add(itemID); } Predicate<String> allowedFn = v -> !knownItems.contains(v); ToDoubleObjDoubleBiFunction<String> rescoreFn = null; RescorerProvider rescorerProvider = getALSServingModel().getRescorerProvider(); if (rescorerProvider != null) { Rescorer rescorer = rescorerProvider.getMostSimilarItemsRescorer(rescorerParams); if (rescorer != null) { allowedFn = allowedFn.and(id -> !rescorer.isFiltered(id)); rescoreFn = rescorer::rescore; } } Stream<Pair<String,Double>> topIDCosines = alsServingModel.topN( new CosineAverageFunction(itemFeatureVectors), rescoreFn, howManyOffset, allowedFn); return toIDValueResponse(topIDCosines, howMany, offset); }  @GET @Path("{itemID : .+}") @Produces({MediaType.TEXT_PLAIN, "text/csv", MediaType.APPLICATION_JSON}) List<IDValue> get(
      @PathParam("itemID") List<PathSegment> pathSegmentsList,
      @DefaultValue("10") @QueryParam("howMany") int howMany,
      @DefaultValue("0") @QueryParam("offset") int offset,
      @QueryParam("rescorerParams") List<String> rescorerParams);  }### Answer:
@Test(expected = NotFoundException.class) public void testNoArg() { target("/similarity").request().get(String.class); }
@Test public void testSimilarItems() { List<IDValue> recs = target("similarity/I0/I4/I6").request() .accept(MediaType.APPLICATION_JSON_TYPE).get(LIST_ID_VALUE_TYPE); testTopByValue(6, recs, false); Assert.assertEquals("I5", recs.get(1).getID()); Assert.assertEquals(0.9125432970065859, recs.get(2).getValue(), DOUBLE_EPSILON); }
@Test public void testSimilarityCSV() { String response = target("/similarity/I0/I4/I6").request().get(String.class); testCSVTopByScore(6, response); }
@Test public void testRescorer() { List<IDValue> recs = target("similarity/I0/I4/I6") .queryParam("rescorerParams", "foo").request() .accept(MediaType.APPLICATION_JSON_TYPE).get(LIST_ID_VALUE_TYPE); testTopByValue(4, recs, false); Assert.assertEquals("I5", recs.get(1).getID()); Assert.assertEquals(2.0 * 0.9125432970065859, recs.get(2).getValue(), DOUBLE_EPSILON); }