use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method buildNonFriendship.
public void buildNonFriendship(String filename) {
System.out.println("[Info]Non-friendship file is loaded from " + filename);
HashMap<String, String[]> nonFriendMap = new HashMap<String, String[]>();
try {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
String[] users, nonFriends;
while ((line = reader.readLine()) != null) {
users = line.trim().split("\t");
nonFriends = Arrays.copyOfRange(users, 1, users.length);
if (nonFriends.length == 0) {
continue;
}
nonFriendMap.put(users[0], nonFriends);
}
reader.close();
System.out.format("%d users have non-friends!\n", nonFriendMap.size());
// map friends to users.
int count = 0;
for (_User u : m_users) {
if (nonFriendMap.containsKey(u.getUserID())) {
count++;
u.setNonFriends(nonFriendMap.get(u.getUserID()));
}
}
System.out.format("%d users' non-friends are set!\n", count);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method filterFriends.
// filter the friends who are not in the list and return a neat hashmap
public HashMap<String, ArrayList<String>> filterFriends(HashMap<String, String[]> neighborsMap) {
double sum = 0;
HashMap<String, _User> userMap = new HashMap<String, _User>();
for (_User u : m_users) {
userMap.put(u.getUserID(), u);
}
HashMap<String, ArrayList<String>> frdMap = new HashMap<String, ArrayList<String>>();
for (String uid : neighborsMap.keySet()) {
if (!userMap.containsKey(uid)) {
System.out.println("The user does not exist in user set!");
continue;
}
ArrayList<String> frds = new ArrayList<>();
for (String frd : neighborsMap.get(uid)) {
if (!neighborsMap.containsKey(frd))
continue;
if (contains(neighborsMap.get(frd), uid)) {
frds.add(frd);
} else {
System.out.println("asymmetric");
}
}
if (frds.size() > 0) {
frdMap.put(uid, frds);
sum += frds.size();
}
}
System.out.format("%d users' friends are recorded, avg friends: %.2f.\n", frdMap.size(), sum / frdMap.size());
return frdMap;
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method loadTestFriendship.
// load the test user friends, for link prediction only
public void loadTestFriendship(String filename) {
try {
m_testMap.clear();
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
String[] users, friends;
while ((line = reader.readLine()) != null) {
users = line.trim().split("\t");
friends = Arrays.copyOfRange(users, 1, users.length);
if (friends.length == 0) {
continue;
}
m_testMap.put(users[0], friends);
}
reader.close();
// map friends to users.
for (_User u : m_users) {
if (m_testMap.containsKey(u.getUserID()))
u.setTestFriends(m_testMap.get(u.getUserID()));
}
checkFriendSize();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method rmMultipleReviews4OneItem.
public void rmMultipleReviews4OneItem() {
Set<String> items = new HashSet<String>();
ArrayList<Integer> indexes = new ArrayList<Integer>();
int uCount = 0, rCount = 0;
boolean flag = false;
for (_User u : m_users) {
ArrayList<_Review> reviews = u.getReviews();
items.clear();
indexes.clear();
for (int i = 0; i < reviews.size(); i++) {
_Review r = reviews.get(i);
if (items.contains(r.getItemID())) {
indexes.add(i);
rCount++;
flag = true;
} else {
items.add(r.getItemID());
}
}
// record the user number
if (flag) {
uCount++;
flag = false;
}
// remove the reviews.
Collections.sort(indexes, Collections.reverseOrder());
for (int idx : indexes) {
reviews.remove(idx);
}
u.constructTrainTestReviews();
}
System.out.format("%d users have %d duplicate reviews for items.\n", uCount, rCount);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class IndividualSVM method loadSuperUsers.
public void loadSuperUsers(ArrayList<_User> userList) {
m_supUserList = new ArrayList<_AdaptStruct>();
for (_User user : userList) m_supUserList.add(new _AdaptStruct(user));
m_pWeights = new double[m_featureSize + 1];
}
Aggregations