use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method findUserWithMaxDocSize.
public void findUserWithMaxDocSize() {
int max = -1;
int count = 0;
for (_User u : m_users) {
if (u.getReviewSize() > 1000) {
System.out.println(u.getUserID());
count++;
}
max = Math.max(max, u.getReviewSize());
}
System.out.println("Max doc size: " + max);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class IndividualSVM method loadUsers.
@Override
public void loadUsers(ArrayList<_User> userList) {
m_userList = new ArrayList<_AdaptStruct>();
for (_User user : userList) // new _AdaptStruct(user, Integer.valueOf(user.getUserID()))
m_userList.add(new _AdaptStruct(user));
m_pWeights = new double[m_featureSize + 1];
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class UserAnalyzer method loadUser.
// Load one file as a user here.
public void loadUser(String filename) {
try {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
// UserId is contained in the filename.
String userID = extractUserID(file.getName());
// Skip the first line since it is user name.
reader.readLine();
String productID, source, category;
ArrayList<_Review> reviews = new ArrayList<_Review>();
_Review review;
int ylabel;
long timestamp;
while ((line = reader.readLine()) != null) {
productID = line;
// review content
source = reader.readLine();
// review category
category = reader.readLine();
ylabel = Integer.valueOf(reader.readLine());
timestamp = Long.valueOf(reader.readLine());
// Construct the new review.
if (ylabel != 3) {
ylabel = (ylabel >= 4) ? 1 : 0;
review = new _Review(m_corpus.getCollection().size(), source, ylabel, userID, productID, category, timestamp);
if (// Create the sparse vector for the review.
AnalyzeDoc(review))
reviews.add(review);
}
}
if (reviews.size() > 1) {
// at least one for adaptation and one for testing
allocateReviews(reviews);
// create new user from the file.
m_users.add(new _User(userID, m_classNo, reviews));
} else if (reviews.size() == 1) {
// added by Lin, for those users with fewer than 2 reviews, ignore them.
review = reviews.get(0);
rollBack(Utils.revertSpVct(review.getSparse()), review.getYLabel());
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method writeCVIndex4Docs.
public void writeCVIndex4Docs(String filename, HashSet<String> light, HashSet<String> medium, HashSet<String> heavy) {
try {
int[] stat = new int[4];
PrintWriter writer = new PrintWriter(new File(filename));
for (String uid : m_userIDIndex.keySet()) {
_User user = m_users.get(m_userIDIndex.get(uid));
if (light.contains(uid)) {
writeOneUserReviews(writer, user, 0, stat);
} else if (medium.contains(uid)) {
writeOneUserReviews(writer, user, 1, stat);
} else if (heavy.contains(uid)) {
writeOneUserReviews(writer, user, 2, stat);
} else {
writeOneUserReviews(writer, user, 3, stat);
}
}
writer.close();
System.out.println("[Info]Finish writing cv index! Stat as follow:");
for (int s : stat) System.out.print(s + "\t");
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method sample.
public HashSet<String> sample(ArrayList<String> candidates, int size) {
Random rand = new Random();
HashSet<String> sampledUsers = new HashSet<>();
while (sampledUsers.size() < size) {
int index = rand.nextInt(candidates.size());
_User user = m_users.get(m_userIDIndex.get(candidates.get(index)));
if (user.getFriends() != null) {
sampledUsers.add(candidates.get(index));
}
}
return sampledUsers;
}
Aggregations