Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.recommenders.rival.split.parser;
 
 import java.io.File;
A parser based on the format of Movielens files

Author(s):
Alejandro
public class MovielensParser implements Parser {

    
The column index for the user id in the file.
    public static final int USER_TOK = 0;
    
The column index for the item id in the file.
    public static final int ITEM_TOK = 1;
    
The column index for the rating in the file.
    public static final int RATING_TOK = 2;
    
The column index for the time in the file.
    public static final int TIME_TOK = 3;
    @Override
    public DataModel<LongLongparseData(File fthrows IOException {
        DataModel<LongLongdataset = new DataModel<LongLong>();
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line = null;
        while ((line = br.readLine()) != null) {
            parseLine(linedataset);
        }
        br.close();
        return dataset;
    }

    
A method that parses a line from the file.

Parameters:
line the line to be parsed
dataset the dataset where the information parsed from the line will be stored into.
    private void parseLine(String lineDataModel<LongLongdataset) {
        String[] toks = line.contains("::") ? line.split("::") : line.split("\t");
        // user
        long userId = Long.parseLong(toks[]);
        // item
        long itemId = Long.parseLong(toks[]);
        // timestamp
        long timestamp = Long.parseLong(toks[]);
        // preference
        double preference = Double.parseDouble(toks[]);
        //////
        // update information
        //////
        dataset.addPreference(userIditemIdpreference);
        dataset.addTimestamp(userIditemIdtimestamp);
    }
New to GrepCode? Check out our FAQ X