Search in sources :

Example 36 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 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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) BufferedReader(java.io.BufferedReader) structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 37 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 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 : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) structures._User(structures._User)

Example 38 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 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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 39 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 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);
}
Also used : structures._Review(structures._Review) ArrayList(java.util.ArrayList) structures._User(structures._User) HashSet(java.util.HashSet)

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

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];
}
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