Search in sources :

Example 11 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 findUserWithMaxDocSize.

public void findUserWithMaxDocSize() {
    int max = -1;
    int count = 0;
    for (_User u : m_users) {
        if (u.getReviewSize() > 1000) {
            System.out.println(u.getUserID());
            count++;
        }
        max = Math.max(max, u.getReviewSize());
    }
    System.out.println("Max doc size: " + max);
}
Also used : structures._User(structures._User)

Example 12 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 loadUsers.

@Override
public void loadUsers(ArrayList<_User> userList) {
    m_userList = new ArrayList<_AdaptStruct>();
    for (_User user : userList) // new _AdaptStruct(user, Integer.valueOf(user.getUserID()))
    m_userList.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)

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

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

the class UserAnalyzer method loadUser.

// Load one file as a user here.
public void loadUser(String filename) {
    try {
        File file = new File(filename);
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        String line;
        // UserId is contained in the filename.
        String userID = extractUserID(file.getName());
        // Skip the first line since it is user name.
        reader.readLine();
        String productID, source, category;
        ArrayList<_Review> reviews = new ArrayList<_Review>();
        _Review review;
        int ylabel;
        long timestamp;
        while ((line = reader.readLine()) != null) {
            productID = line;
            // review content
            source = reader.readLine();
            // review category
            category = reader.readLine();
            ylabel = Integer.valueOf(reader.readLine());
            timestamp = Long.valueOf(reader.readLine());
            // Construct the new review.
            if (ylabel != 3) {
                ylabel = (ylabel >= 4) ? 1 : 0;
                review = new _Review(m_corpus.getCollection().size(), source, ylabel, userID, productID, category, timestamp);
                if (// Create the sparse vector for the review.
                AnalyzeDoc(review))
                    reviews.add(review);
            }
        }
        if (reviews.size() > 1) {
            // at least one for adaptation and one for testing
            allocateReviews(reviews);
            // create new user from the file.
            m_users.add(new _User(userID, m_classNo, reviews));
        } else if (reviews.size() == 1) {
            // added by Lin, for those users with fewer than 2 reviews, ignore them.
            review = reviews.get(0);
            rollBack(Utils.revertSpVct(review.getSparse()), review.getYLabel());
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._Review(structures._Review) ArrayList(java.util.ArrayList) structures._User(structures._User)

Example 14 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 writeCVIndex4Docs.

public void writeCVIndex4Docs(String filename, HashSet<String> light, HashSet<String> medium, HashSet<String> heavy) {
    try {
        int[] stat = new int[4];
        PrintWriter writer = new PrintWriter(new File(filename));
        for (String uid : m_userIDIndex.keySet()) {
            _User user = m_users.get(m_userIDIndex.get(uid));
            if (light.contains(uid)) {
                writeOneUserReviews(writer, user, 0, stat);
            } else if (medium.contains(uid)) {
                writeOneUserReviews(writer, user, 1, stat);
            } else if (heavy.contains(uid)) {
                writeOneUserReviews(writer, user, 2, stat);
            } else {
                writeOneUserReviews(writer, user, 3, stat);
            }
        }
        writer.close();
        System.out.println("[Info]Finish writing cv index! Stat as follow:");
        for (int s : stat) System.out.print(s + "\t");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._User(structures._User)

Example 15 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 sample.

public HashSet<String> sample(ArrayList<String> candidates, int size) {
    Random rand = new Random();
    HashSet<String> sampledUsers = new HashSet<>();
    while (sampledUsers.size() < size) {
        int index = rand.nextInt(candidates.size());
        _User user = m_users.get(m_userIDIndex.get(candidates.get(index)));
        if (user.getFriends() != null) {
            sampledUsers.add(candidates.get(index));
        }
    }
    return sampledUsers;
}
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