Search in sources :

Example 46 with org.haiku.haikudepotserver.dataobjects.auto._User

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);
}
Also used : structures._User(structures._User) InvalidFormatException(opennlp.tools.util.InvalidFormatException)

Example 47 with org.haiku.haikudepotserver.dataobjects.auto._User

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();
    }
}
Also used : structures._User(structures._User)

Example 48 with org.haiku.haikudepotserver.dataobjects.auto._User

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();
    }
}
Also used : structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 49 with org.haiku.haikudepotserver.dataobjects.auto._User

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);
}
Also used : structures._User(structures._User)

Example 50 with org.haiku.haikudepotserver.dataobjects.auto._User

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);
        }
    }
}
Also used : structures._User(structures._User)

Aggregations

structures._User (structures._User)56 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)15 File (java.io.File)10 IOException (java.io.IOException)10 structures._Review (structures._Review)10 ArrayList (java.util.ArrayList)6 PrintWriter (java.io.PrintWriter)5 BufferedReader (java.io.BufferedReader)4 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)3 ObjectContext (org.apache.cayenne.ObjectContext)3 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)3 User (org.haiku.haikudepotserver.dataobjects.User)3 org.haiku.haikudepotserver.dataobjects.auto._User (org.haiku.haikudepotserver.dataobjects.auto._User)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 InvalidFormatException (opennlp.tools.util.InvalidFormatException)2 structures._SparseFeature (structures._SparseFeature)2 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1