Search in sources :

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

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class MultiThreadedUserAnalyzer method checkFriendSize.

public void checkFriendSize() {
    int train = 0, test = 0;
    for (_User u : m_users) {
        if (u.getFriendSize() != 0)
            train++;
        if (u.getTestFriendSize() != 0)
            test++;
    }
    System.out.format("[Check]%d users have train friends, %d users have test friends.\n", train, test);
}
Also used : structures._User(structures._User)

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

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class MultiThreadedUserAnalyzer 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 : ArrayList(java.util.ArrayList) structures._User(structures._User) File(java.io.File) InvalidFormatException(opennlp.tools.util.InvalidFormatException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 23 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 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;
        while ((line = reader.readLine()) != null) {
            analyzerOneLineNetwork(nonFriendMap, line);
        }
        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();
    }
}
Also used : structures._User(structures._User)

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

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

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class CLinAdaptWithMMB method loadUsers.

@Override
public void loadUsers(ArrayList<_User> userList) {
    m_userList = new ArrayList<_AdaptStruct>();
    // Init each user.
    for (_User user : userList) {
        m_userList.add(new _MMBAdaptStruct(user, m_dim));
    }
    m_pWeights = new double[m_gWeights.length];
    m_indicator = new _HDPThetaStar[m_userList.size()][m_userList.size()];
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) 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