コード例 #1
0
  @SuppressWarnings("deprecation")
  @Test
  public void testUserUserRecommenderEngineCreate() {
    Recommender rec = engine.createRecommender();

    assertThat(rec.getItemScorer(), instanceOf(UserUserItemScorer.class));
    assertThat(rec.getItemRecommender(), instanceOf(TopNItemRecommender.class));
    RatingPredictor pred = rec.getRatingPredictor();
    assertThat(pred, instanceOf(SimpleRatingPredictor.class));
    assertThat(((SimpleRatingPredictor) pred).getScorer(), sameInstance(rec.getItemScorer()));
  }
コード例 #2
0
  @Test
  public void testSnapshot() throws RecommenderBuildException {
    List<Rating> rs = new ArrayList<Rating>();
    rs.add(Ratings.make(1, 5, 2));
    rs.add(Ratings.make(1, 7, 4));
    rs.add(Ratings.make(8, 4, 5));
    rs.add(Ratings.make(8, 5, 4));

    EventDAO dao = EventCollectionDAO.create(rs);

    LenskitConfiguration config = new LenskitConfiguration();
    config.bind(EventDAO.class).to(dao);
    config.bind(ItemScorer.class).to(UserUserItemScorer.class);
    config.bind(NeighborFinder.class).to(SnapshotNeighborFinder.class);

    LenskitRecommenderEngine engine = LenskitRecommenderEngine.build(config);
    Recommender rec = engine.createRecommender();
    assertThat(rec.getItemScorer(), instanceOf(UserUserItemScorer.class));
    assertThat(rec.getItemRecommender(), instanceOf(TopNItemRecommender.class));
    RatingPredictor pred = rec.getRatingPredictor();
    assertThat(pred, instanceOf(SimpleRatingPredictor.class));

    Recommender rec2 = engine.createRecommender();
    assertThat(rec2.getItemScorer(), not(sameInstance(rec.getItemScorer())));
  }
コード例 #3
0
  public static String userbasecrec(String files)
      throws FileNotFoundException, TasteException, IOException, OptionException {

    // DataModel model = new FileDataModel(new File("datasets/movieRatings.dat"));

    File ratingsFile = new File(files);
    DataModel model = new FileDataModel(ratingsFile);

    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(3, similarity, model);
    Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
    List<RecommendedItem> recommendations = recommender.recommend(1, 1);

    String ls = "";
    for (RecommendedItem recommendation : recommendations) {
      System.out.println(recommendation);
      ls = recommendation + "";
    }
    return ls;
  }
コード例 #4
0
  public static HashMap<String, Keyword_Format> setupPreprocesses(PropertiesFile propertyfile)
      throws Exception {
    // TODO Auto-generated method stub

    PropertiesFile filelocations = propertyfile;
    // Preprocessing Started
    System.out.println("Preprocessing Started.");

    // Step 1: Read csv file to generate list of documents
    // Read_generateCorpus.readCSV_getCORPUS(filelocations);

    System.out.println("Step: 1 generate corpus done.");

    // Step 2: Append Concepts
    // AppendConcepts.appendConcept(filelocations);
    System.out.println("Step: 2 Appending concepts done.");

    // Step 3: Stem all the Files
    try {
      // Stem_All_Files_under_Dir.stem_all_files_in_directory(filelocations);
    } catch (Throwable e) {
      e.printStackTrace();
    }

    System.out.println("Step: 3 Stemming done.");

    // Step 4: Filter into separate question & answers
    // Potential place to store in db
    // FilterStemmed.filter_docs(filelocations);
    System.out.println("Step: 4 Filtering done.");

    // Generate concepts from text

    // Step 5: Create Index Code
    // CallIndexFiles_Code.setupIndex(filelocations);
    System.out.println("Step: 5 Indexing (Code) done.");

    // Step 6: Create Index Text
    // CallIndexFiles_Text.setupIndex(filelocations);
    System.out.println("Step: 6 Indexing (Text) done.");

    // Pre-calculate document Norm: Code

    IndexReader t =
        IndexReader.open(
            FSDirectory.open(
                new File(
                    Preprocessing.class
                        .getClassLoader()
                        .getResource(filelocations.getBaseUrl() + filelocations.getIndexC())
                        .toURI())));
    Recommender.precalculate_doc_norm(t, "code");
    System.out.println("Code document norm calculation complete");

    // Pre-calculate Document Norm: Text
    IndexReader s =
        IndexReader.open(
            FSDirectory.open(
                new File(
                    Preprocessing.class
                        .getClassLoader()
                        .getResource(filelocations.getBaseUrl() + filelocations.getIndexT())
                        .toURI())));
    Recommender.precalculate_doc_norm(s, "text");
    System.out.println("Text document norm calculation complete");

    // Generate Keywords for each document
    HashMap<String, Keyword_Format> toController =
        KeywordExtract.GetConceptsForDocuments(filelocations);
    System.out.println("Concepts Extracted from Documents");

    // Preprocessing Completed.
    System.out.println("Preprocessing completed. ");

    return toController;
  }
コード例 #5
0
ファイル: KibitzServer.java プロジェクト: qqliu/kibitz
  @Override
  public List<Recommender> getRecommenders(String username) {
    try {
      THttpClient transport = new THttpClient("http://datahub.csail.mit.edu/service");
      TBinaryProtocol protocol = new TBinaryProtocol(transport);
      DataHub.Client client = new DataHub.Client(protocol);

      ConnectionParams params = new ConnectionParams();
      params.setApp_id(DatahubDataModel.getKibitzAppName());
      params.setApp_token(DatahubDataModel.getKibitzAppId());
      params.setRepo_base(DatahubDataModel.getDefaultDatahubUsername());
      Connection connection = client.open_connection(params);

      List<Recommender> recommenders = new ArrayList<Recommender>();

      ResultSet res =
          client.execute_sql(
              connection,
              "SELECT database,username,ratings_table,overall_ratings,ratings_column FROM kibitz_users.recommenders WHERE username = '******';",
              null);
      HashMap<String, Integer> colToIndex = DatahubDataModel.getFieldNames(res);
      for (Tuple t : res.getTuples()) {
        List<ByteBuffer> cells = t.getCells();
        Recommender recommender = new Recommender();
        String database = new String(cells.get(colToIndex.get("database")).array());
        recommender.setUsername(new String(cells.get(colToIndex.get("username")).array()));
        recommender.setRepoName(database);
        recommender.setHomepage("default");
        recommender.setRecommenderName(
            new String(cells.get(colToIndex.get("ratings_table")).array()).split("\\.")[1]);
        if (Boolean.parseBoolean(new String(cells.get(colToIndex.get("overall_ratings")).array())))
          recommender.setRatingsColumn(
              new String(cells.get(colToIndex.get("ratings_column")).array()));
        ScriptEngineManager mgr = new ScriptEngineManager();
        ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");

        File file =
            new File(
                DatahubDataModel.WEBSERVER_DIR + username + "/" + database + "/js/initiate.js");
        Reader reader = new FileReader(file);
        jsEngine.eval(reader);

        recommender.setClientKey(jsEngine.get("client_key").toString());
        recommender.setTitle(jsEngine.get("title").toString());
        recommender.setDescription(jsEngine.get("description").toString());
        recommender.setVideo(jsEngine.get("video").toString());
        recommender.setImage(jsEngine.get("image").toString());
        recommender.setPrimaryKey(jsEngine.get("primary_key").toString());

        List<String> displayItems = new ArrayList<String>();

        int varsLength = Integer.parseInt(jsEngine.eval("display_items.length;").toString());
        for (int i = 0; i < varsLength; i++) {
          displayItems.add((String) jsEngine.eval("display_items[" + i + "];"));
        }

        recommender.setDisplayItems(displayItems);

        HashMap<String, String> itemMap =
            new HashMap<String, String>((Map<String, String>) jsEngine.get("item_types"));
        recommender.setItemTypes(itemMap);
        recommender.setNumRecs((int) Double.parseDouble(jsEngine.get("num_recs").toString()));
        recommender.setMaxRatingVal(
            (int) Double.parseDouble(jsEngine.get("maxRatingVal").toString()));

        recommenders.add(recommender);
      }

      return recommenders;
    } catch (ScriptException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (DBException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (TException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }