use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLinkPredAnalyzer method loadTestUserDir.
// Load users' test reviews.
public void loadTestUserDir(String folder) {
// construct the training user map first
for (_User u : m_users) {
if (!m_userMap.containsKey(u.getUserID()))
m_userMap.put(u.getUserID(), u);
else
System.err.println("[error] The user already exists in map!!");
}
if (folder == null || folder.isEmpty())
return;
File dir = new File(folder);
final File[] files = dir.listFiles();
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < m_numberOfCores; ++i) {
threads.add((new Thread() {
int core;
@Override
public void run() {
try {
for (int j = 0; j + core < files.length; j += m_numberOfCores) {
File f = files[j + core];
// && f.getAbsolutePath().endsWith("txt")
if (f.isFile()) {
// load the user
loadTestUserReview(f.getAbsolutePath(), core);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private Thread initialize(int core) {
this.core = core;
return this;
}
}).initialize(i));
threads.get(i).start();
}
for (int i = 0; i < m_numberOfCores; ++i) {
try {
threads.get(i).join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// process sub-directories
int count = 0;
for (File f : files) if (f.isDirectory())
loadUserDir(f.getAbsolutePath());
else
count++;
System.out.format("%d users are loaded from %s...\n", count, folder);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLinkPredAnalyzer method buildTrainFriendship.
public void buildTrainFriendship(String filename) {
try {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
analyzerOneLineNetwork(m_trainMap, line);
}
reader.close();
System.out.format("%d users have friends!", m_trainMap.size());
// map friends to users.
int count = 0;
for (_User u : m_users) {
if (m_trainMap.containsKey(u.getUserID())) {
count++;
u.setFriends(m_trainMap.get(u.getUserID()));
}
}
System.out.format("%d users' 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 MultiThreadedLMAnalyzer method saveUsers.
public void saveUsers(String filename) {
try {
PrintWriter writer = new PrintWriter(new File(filename));
for (_User u : m_users) writer.write(u.getUserID() + "\n");
writer.close();
System.out.println(m_users.size() + " users are saved!");
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method calcDocStat4LightMediumHeavy.
public void calcDocStat4LightMediumHeavy(int k1, int k2) {
int light = 0, medium = 0, heavy = 0, max = 0;
for (_User user : m_users) {
int reviewSize = user.getReviews().size();
max = Math.max(max, reviewSize);
if (reviewSize > k2) {
heavy++;
} else if (reviewSize > k1) {
medium++;
} else
light++;
}
System.out.format("[Stat]Dos-Light: %d, Medium: %d, Heavy: %d, max: %d.\n", light, medium, heavy, max);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method removeSymmetricEdges.
public void removeSymmetricEdges(HashSet<String> uids) {
for (String uid : uids) {
_User ui = m_users.get(m_userIDIndex.get(uid));
if (ui.getFriends() == null)
System.out.println("The user does not have any friends!!");
for (String frd : ui.getFriends()) {
_User uj = m_users.get(m_userIDIndex.get(frd));
uj.removeOneFriend(uid);
}
}
}
Aggregations