Example usage for org.apache.mahout.cf.taste.recommender ItemBasedRecommender mostSimilarItems

List of usage examples for org.apache.mahout.cf.taste.recommender ItemBasedRecommender mostSimilarItems

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.recommender ItemBasedRecommender mostSimilarItems.

Prototype

List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany) throws TasteException;

Source Link

Usage

From source file:cf.wikipedia.WikipediaTasteItemRecDemo.java

License:Apache License

public static void main(String[] args)
        throws IOException, TasteException, SAXException, ParserConfigurationException {
    String recsFile = args[0];//  w  ww .  j  av a  2  s .  co  m
    String docIdsTitle = args[1];
    long itemId = Long.parseLong(args[2]);
    Integer numRecs = Integer.parseInt(args[3]);
    //Integer neighbors = Integer.parseInt(args[2]);
    InputSource is = new InputSource(new FileInputStream(docIdsTitle));
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    SAXParser sp = factory.newSAXParser();
    WikiContentHandler handler = new WikiContentHandler();
    //load the ids and titles
    sp.parse(is, handler);

    //create the data model
    FileDataModel dataModel = new FileDataModel(new File(recsFile));
    //Create an ItemSimilarity
    ItemSimilarity itemSimilarity = new LogLikelihoodSimilarity(dataModel);
    //Create an Item Based Recommender
    ItemBasedRecommender recommender = new GenericItemBasedRecommender(dataModel, itemSimilarity);
    //Get the recommendations for the Item
    List<RecommendedItem> simItems = recommender.mostSimilarItems(itemId, numRecs);
    TasteUtils.printRecs(simItems, handler.map);
}