Package net.myrrix.common

Examples of net.myrrix.common.MyrrixRecommender


  protected abstract boolean isUserIDs();

  @Override
  protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MyrrixRecommender recommender = getRecommender();
    try {
      FastIDSet ids = isUserIDs() ? recommender.getAllUserIDs() : recommender.getAllItemIDs();
      outputIDs(request, response, ids);
    } catch (NotReadyException nre) {
      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (TasteException te) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
View Full Code Here


    if (itemIDSet.isEmpty()) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
      return;
    }

    MyrrixRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
      int howMany = getHowMany(request);
      Iterable<RecommendedItem> similar;
      if (rescorerProvider == null) {
        similar = recommender.mostSimilarItems(itemIDSet.toArray(), howMany);
      } else {
        Rescorer<LongPair> rescorer =
            rescorerProvider.getMostSimilarItemsRescorer(recommender, getRescorerParams(request));
        similar = recommender.mostSimilarItems(itemIDSet.toArray(),
                                               howMany,
                                               rescorer);
      }
      output(request, response, similar);
    } catch (NoSuchItemException nsie) {
View Full Code Here

*/
public final class IngestServlet extends AbstractMyrrixServlet {

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    MyrrixRecommender recommender = getRecommender();

    boolean fromBrowserUpload = request.getContentType().startsWith("multipart/form-data");

    Reader reader;
    if (fromBrowserUpload) {

      Collection<Part> parts = request.getParts();
      if (parts == null || parts.isEmpty()) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No form data");
        return;
      }
      Part part = parts.iterator().next();
      String partContentType = part.getContentType();
      InputStream in = part.getInputStream();
      if ("application/zip".equals(partContentType)) {
        in = new ZipInputStream(in);
      } else if ("application/gzip".equals(partContentType)) {
        in = new GZIPInputStream(in);
      } else if ("application/x-gzip".equals(partContentType)) {
        in = new GZIPInputStream(in);
      } else if ("application/bzip2".equals(partContentType)) {
        in = new BZip2CompressorInputStream(in);
      } else if ("application/x-bzip2".equals(partContentType)) {
        in = new BZip2CompressorInputStream(in);
      }
      reader = new InputStreamReader(in, Charsets.UTF_8);

    } else {

      String charEncodingName = request.getCharacterEncoding();
      Charset charEncoding = charEncodingName == null ? Charsets.UTF_8 : Charset.forName(charEncodingName);
      String contentEncoding = request.getHeader(HttpHeaders.CONTENT_ENCODING);
      if (contentEncoding == null) {
        reader = request.getReader();
      } else if ("gzip".equals(contentEncoding)) {
        reader = new InputStreamReader(new GZIPInputStream(request.getInputStream()), charEncoding);
      } else if ("zip".equals(contentEncoding)) {
        reader = new InputStreamReader(new ZipInputStream(request.getInputStream()), charEncoding);
      } else if ("bzip2".equals(contentEncoding)) {
        reader = new InputStreamReader(new BZip2CompressorInputStream(request.getInputStream()), charEncoding);
      } else {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unsupported Content-Encoding");
        return;
      }

    }

    try {
      recommender.ingest(reader);
    } catch (IllegalArgumentException iae) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
      return;
    } catch (NoSuchElementException nsee) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
View Full Code Here

    }

    long[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();
   
    MyrrixRecommender recommender = getRecommender();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
      IDRescorer rescorer = rescorerProvider == null ? null :
          rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request));
      Iterable<RecommendedItem> recommended =
          recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer);
      output(request, response, recommended);
    } catch (NotReadyException nre) {
      response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
View Full Code Here

*/
public final class RefreshServlet extends AbstractMyrrixServlet {

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response) {
    MyrrixRecommender recommender = getRecommender();
    recommender.refresh();
  }
View Full Code Here

    long[] itemIDs = new long[itemIDsList.size()];
    for (int i = 0; i < itemIDs.length; i++) {
      itemIDs[i] = itemIDsList.get(i);
    }

    MyrrixRecommender recommender = getRecommender();
    try {
      float[] estimates = recommender.estimatePreferences(userID, itemIDs);
      Writer out = response.getWriter();
      for (float estimate : estimates) {
        out.write(Float.toString(estimate));
        out.write('\n');
      }
View Full Code Here

    if (pathComponents.hasNext()) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Path too long");
      return;
    }

    MyrrixRecommender recommender = getRecommender();
    try {
      Iterable<RecommendedItem> similar = recommender.recommendedBecause(userID, itemID, getHowMany(request));
      output(request, response, similar);
    } catch (NoSuchUserException nsue) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, nsue.toString());
    } catch (NoSuchItemException nsie) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
View Full Code Here

    } catch (IllegalArgumentException ignored) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad value");
      return;
    }

    MyrrixRecommender recommender = getRecommender();
    try {
      recommender.setItemTag(itemTag, itemID, tagValue);
    } catch (TasteException te) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
      getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
    }
  }
View Full Code Here

TOP

Related Classes of net.myrrix.common.MyrrixRecommender

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.