Example usage for org.apache.mahout.cf.taste.common NoSuchItemException NoSuchItemException

List of usage examples for org.apache.mahout.cf.taste.common NoSuchItemException NoSuchItemException

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.common NoSuchItemException NoSuchItemException.

Prototype

public NoSuchItemException() 

Source Link

Usage

From source file:alto.plugin.webradio.recommender.MongoDBDataModel.java

License:Apache License

private void checkData(String userID, Iterable<List<String>> items, boolean add)
        throws NoSuchUserException, NoSuchItemException {
    Preconditions.checkNotNull(userID);//from   w w  w . j  a v  a  2  s  . com
    Preconditions.checkNotNull(items);
    Preconditions.checkArgument(!userID.isEmpty(), "userID is empty");
    for (List<String> item : items) {
        Preconditions.checkNotNull(item.get(0));
        Preconditions.checkArgument(!item.get(0).isEmpty(), "item is empty");
    }
    if (userIsObject && !ID_PATTERN.matcher(userID).matches()) {
        throw new IllegalArgumentException();
    }
    for (List<String> item : items) {
        if (itemIsObject && !ID_PATTERN.matcher(item.get(0)).matches()) {
            throw new IllegalArgumentException();
        }
    }
    if (!add && !isIDInModel(userID)) {
        throw new NoSuchUserException();
    }
    for (List<String> item : items) {
        if (!add && !isIDInModel(item.get(0))) {
            throw new NoSuchItemException();
        }
    }
}

From source file:com.paradigma.recommender.db.MongoDBDataModel.java

License:Apache License

private void checkData(String userID, Iterable<List<String>> items, boolean add)
        throws NoSuchUserException, NoSuchItemException {
    Preconditions.checkNotNull(userID);/*  w ww .  ja v a 2  s  .  c o m*/
    Preconditions.checkNotNull(items);
    Preconditions.checkArgument(userID.length() > 0);
    for (List<String> item : items) {
        Preconditions.checkNotNull(item.get(0));
        Preconditions.checkArgument(item.get(0).length() > 0);
    }
    if (userIsObject && !ID_PATTERN.matcher(userID).matches()) {
        throw new IllegalArgumentException();
    }
    for (List<String> item : items) {
        if (itemIsObject && !ID_PATTERN.matcher(item.get(0)).matches()) {
            throw new IllegalArgumentException();
        }
    }
    if (!add && !isIDInModel(userID)) {
        throw new NoSuchUserException();
    }
    for (List<String> item : items) {
        if (!add && !isIDInModel(item.get(0))) {
            throw new NoSuchItemException();
        }
    }
}

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;
    }// w ww.  jav a  2 s  .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);
    }
}