Esempio n. 1
0
  public static void main(String[] args)
      throws IOException, TasteException, SAXException, ParserConfigurationException {
    String docIdsTitle = "src/main/resources/docIdsTitles.xml";
    long userId = 2;
    // 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();
    sp.parse(is, handler);

    MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();
    dataSource.setDatabaseName("se");
    dataSource.setUser("root");
    dataSource.setPassword("");
    dataSource.setCachePreparedStatements(true);
    dataSource.setCachePrepStmts(true);
    dataSource.setCacheResultSetMetadata(true);
    dataSource.setAlwaysSendSetIsolation(false);
    dataSource.setElideSetAutoCommits(true);
    // create the data model
    DataModel dataModel = new JDBCDataModelImpl(new ConnectionPoolDataSource(dataSource));
    // Create an ItemSimilarity
    ItemSimilarity itemSimilarity = new LogLikelihoodSimilarity(dataModel);
    // Create an Item Based Recommender
    ItemBasedRecommender recommender = new GenericItemBasedRecommender(dataModel, itemSimilarity);
    // Get the recommendations
    List<RecommendedItem> recommendations = recommender.recommend(userId, 5);
    // TasteUtils.printRecs(recommendations, handler.map);
    for (RecommendedItem recommendedItem : recommendations) {
      System.out.println("User:"******"Movie ID : " + recommendedItem);
    }
  }
  @Override
  public void evaluate() throws Throwable {
    dataSource.setServerName("localhost");
    dataSource.setPassword("root");
    dataSource.setUser("root");
    dataSource.setDatabaseName("Bank");

    try {
      cleanTableAccounts();

      statement.evaluate();
    } finally {
      // dataSource.getPooledConnection().close();
    }
  }