package com.tzld.piaoquan.recommend.server.service.score4recall.model4recall;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class VideoTagModel4RecallMap extends AbstractModel {
    private static final Logger LOGGER = LoggerFactory.getLogger(VideoTagModel4RecallMap.class);
    public Map<String, List<Long>> map = new HashMap<>();

    @Override
    public boolean loadFromStream(InputStreamReader in) throws IOException {
        BufferedReader input = new BufferedReader(in);
        String line;
        while ((line = input.readLine()) != null) {
            String[] items = line.split("\t");
            if (items.length < 2) {
                continue;
            }
            String videoIds = items[1].trim();
            try {
                String[] videoIdArr = videoIds.split(",");
                List<Long> videoIdList = new ArrayList<>();
                for (String videoId : videoIdArr) {
                    videoIdList.add(Long.parseLong(videoId));
                }
                map.put(items[0], videoIdList);
            } catch (Exception e) {
                LOGGER.error(String.format("VideoTagModel4RecallMap is wrong with parse %s: ", line), e);
            }
        }
        input.close();
        in.close();
        return true;
    }
}
