List of usage examples for org.apache.mahout.cf.taste.common TasteException TasteException
public TasteException(Throwable cause)
From source file:chinapub.cf.recommander.servlet.ItemBasedRecommanderSingleton.java
License:Apache License
private ItemBasedRecommanderSingleton(String recommenderClassName) throws TasteException { if (recommenderClassName == null) { throw new IllegalArgumentException("Recommender class name is null"); }/* w w w.j a va 2s .c o m*/ try { recommender = Class.forName(recommenderClassName).asSubclass(Recommender.class).newInstance(); } catch (ClassNotFoundException cnfe) { throw new TasteException(cnfe); } catch (InstantiationException ie) { throw new TasteException(ie); } catch (IllegalAccessException iae) { throw new TasteException(iae); } }
From source file:chinapub.cf.recommander.servlet.SlopeOneRecommanderSingleton.java
License:Apache License
private SlopeOneRecommanderSingleton(String recommenderClassName) throws TasteException { if (recommenderClassName == null) { throw new IllegalArgumentException("Recommender class name is null"); }/*from www . j a v a 2s . c om*/ try { recommender = Class.forName(recommenderClassName).asSubclass(Recommender.class).newInstance(); } catch (ClassNotFoundException cnfe) { throw new TasteException(cnfe); } catch (InstantiationException ie) { throw new TasteException(ie); } catch (IllegalAccessException iae) { throw new TasteException(iae); } }
From source file:chinapub.cf.recommander.servlet.UserBasedRecommanderSingleton.java
License:Apache License
private UserBasedRecommanderSingleton(String recommenderClassName) throws TasteException { if (recommenderClassName == null) { throw new IllegalArgumentException("Recommender class name is null"); }//from ww w . jav a 2s . co m try { recommender = Class.forName(recommenderClassName).asSubclass(Recommender.class).newInstance(); } catch (ClassNotFoundException cnfe) { throw new TasteException(cnfe); } catch (InstantiationException ie) { throw new TasteException(ie); } catch (IllegalAccessException iae) { throw new TasteException(iae); } }
From source file:com.ibm.taste.example.movie.servlet.MovieRecommenderSingleton.java
License:Apache License
private MovieRecommenderSingleton(String recommenderClassName) throws TasteException { if (recommenderClassName == null) { throw new IllegalArgumentException("Recommender class name is null"); }/* w w w. ja v a 2s . c om*/ try { recommender = Class.forName(recommenderClassName).asSubclass(Recommender.class).newInstance(); } catch (ClassNotFoundException cnfe) { throw new TasteException(cnfe); } catch (InstantiationException ie) { throw new TasteException(ie); } catch (IllegalAccessException iae) { throw new TasteException(iae); } }
From source file:com.staticvillage.recommender.PlaceRecommender.java
License:Apache License
@Override public List<RecommendedItem> recommend(long placeId, int howMany) throws TasteException { if (indexer == null || geoPoint == null) return delegate.recommend(placeId, howMany); LocalRescorer rescorer = null;// w ww.j a va 2 s.co m try { rescorer = new LocalRescorer(indexer, geoPoint); } catch (IndexerException e) { e.printStackTrace(); throw new TasteException("Error occurred configuring rescorer"); } return recommend(placeId, howMany, rescorer); }
From source file:com.yelp.recommend.RestaurantRecommender.java
License:Apache License
public RestaurantRecommender(DataModel dataModel, String filename) throws TasteException { // Include the newly written Similarity class ItemSimilarity similarity;//w ww . ja va 2s . c o m try { similarity = new HybridRestaurantSimilarity(dataModel, filename); } catch (IOException ioe) { throw new TasteException(ioe); } recommender = new GenericItemBasedRecommender(dataModel, similarity); }
From source file:edu.uci.ics.sourcerer.ml.db.AbstractJDBCUserSimilarity.java
License:Open Source License
@Override public double userSimilarity(long userID1, long userID2) throws TasteException { if (userID1 == userID2) { return 1.0; }/*from w ww. j ava 2s .c o m*/ // Order as smaller - larger if (userID1 > userID2) { long temp = userID1; userID1 = userID2; userID2 = temp; } Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = dataSource.getConnection(); stmt = conn.prepareStatement(getUserUserSimilaritySQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchDirection(ResultSet.FETCH_FORWARD); stmt.setFetchSize(getFetchSize()); stmt.setLong(1, userID1); stmt.setLong(2, userID2); log.debug("Executing SQL query: {}", getUserUserSimilaritySQL); rs = stmt.executeQuery(); if (rs.next()) { return rs.getDouble(1); } else { throw new NoSuchItemException(); } } catch (SQLException sqle) { log.warn("Exception while retrieving user", sqle); throw new TasteException(sqle); } finally { IOUtils.quietClose(rs, stmt, conn); } }
From source file:lib.eval.AbstractRecommenderEvaluator.java
License:Apache License
protected static void execute(Collection<Callable<Void>> callables, AtomicInteger noEstimateCounter) throws TasteException { callables = wrapWithStatsCallables(callables, noEstimateCounter); int numProcessors = Runtime.getRuntime().availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(numProcessors); log.info("Starting timing of {} tasks in {} threads", callables.size(), numProcessors); try {/*from ww w. j ava 2 s. com*/ List<Future<Void>> futures = executor.invokeAll(callables); // Go look for exceptions here, really for (Future<Void> future : futures) { future.get(); } } catch (InterruptedException ie) { throw new TasteException(ie); } catch (ExecutionException ee) { throw new TasteException(ee.getCause()); } executor.shutdown(); }
From source file:net.myrrix.client.ClientRecommender.java
License:Apache License
private void doSetOrRemove(String path, long unnormalizedID, float value, boolean set) throws TasteException { boolean sendValue = value != 1.0f; Map<String, String> requestProperties; byte[] bytes; if (sendValue) { requestProperties = Maps.newHashMapWithExpectedSize(2); bytes = Float.toString(value).getBytes(Charsets.UTF_8); requestProperties.put(HttpHeaders.CONTENT_TYPE, MediaType.PLAIN_TEXT_UTF_8.toString()); requestProperties.put(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length)); } else {/*from w w w. ja v a 2 s . c o m*/ requestProperties = null; bytes = null; } TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(unnormalizedID)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, path, set ? "POST" : "DELETE", sendValue, false, requestProperties); if (sendValue) { OutputStream out = connection.getOutputStream(); out.write(bytes); out.close(); } // Should not be able to return Not Available status if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } return; } catch (TasteException te) { log.info("Can't access {} at {}: ({})", path, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", path, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }
From source file:net.myrrix.client.ClientRecommender.java
License:Apache License
@Override public float[] estimatePreferences(long userID, long... itemIDs) throws TasteException { StringBuilder urlPath = new StringBuilder(); urlPath.append("/estimate/"); urlPath.append(userID);//ww w .j ava2 s .co m for (long itemID : itemIDs) { urlPath.append('/').append(itemID); } TasteException savedException = null; for (HostAndPort replica : choosePartitionAndReplicas(userID)) { HttpURLConnection connection = null; try { connection = buildConnectionToReplica(replica, urlPath.toString(), "GET"); switch (connection.getResponseCode()) { case HttpURLConnection.HTTP_OK: BufferedReader reader = IOUtils.bufferStream(connection.getInputStream()); try { float[] result = new float[itemIDs.length]; for (int i = 0; i < itemIDs.length; i++) { result[i] = LangUtils.parseFloat(reader.readLine()); } return result; } finally { Closeables.close(reader, true); } case HttpURLConnection.HTTP_UNAVAILABLE: throw new NotReadyException(); default: throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage()); } } catch (TasteException te) { log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString()); savedException = te; } catch (IOException ioe) { log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString()); savedException = new TasteException(ioe); } finally { if (connection != null) { connection.disconnect(); } } } throw savedException; }