当前位置: 首页>>代码示例>>Java>>正文


Java FileIO.writeList方法代码示例

本文整理汇总了Java中happy.coding.io.FileIO.writeList方法的典型用法代码示例。如果您正苦于以下问题:Java FileIO.writeList方法的具体用法?Java FileIO.writeList怎么用?Java FileIO.writeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在happy.coding.io.FileIO的用法示例。


在下文中一共展示了FileIO.writeList方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run_home_page

import happy.coding.io.FileIO; //导入方法依赖的package包/类
private void run_home_page() throws Exception {
	String url = "http://dvd.ciao.co.uk/";
	String html = read_url(url);
	FileIO.writeString(dir + "dvd.ciao.html", html);

	Document doc = Jsoup.parse(html);
	Element categories = doc.getElementById("category_tree_table");
	Elements cs = categories.select("dl");

	List<String> cls = new ArrayList<>();
	for (Element c : cs) {
		Element cat = c.select("dt").first().select("a").first();
		String category = cat.text();
		String link = cat.attr("href");

		cls.add(category + ": " + link);
	}

	FileIO.writeList(dir + "dvd.ciao.txt", cls);
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:21,代码来源:CiaoCrawler.java

示例2: ratings

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@Test
public void ratings() throws Exception {
	String dirPath = "D:\\Research\\Datasets\\Ciao\\";
	String dest = dirPath + "formatted\\" + "ratings.txt";

	FileIO.deleteFile(dest);

	BufferedReader br = FileIO.getReader(dirPath
			+ "rating_with_timestamp.txt");
	String line = null;
	List<String> lines = new ArrayList<>();
	while ((line = br.readLine()) != null) {
		String[] data = line.trim().split("  ");

		int user = (int) Double.parseDouble(data[0]);
		int item = (int) Double.parseDouble(data[1]);
		double rate = Double.parseDouble(data[3]);

		line = user + " " + item + " " + rate;
		lines.add(line);

		if (lines.size() >= 1000) {
			FileIO.writeList(dest, lines, true);
			lines.clear();
		}
	}

	if (lines.size() > 0)
		FileIO.writeList(dest, lines, true);

	br.close();
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:33,代码来源:CiaoTest.java

示例3: trust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@Test
public void trust() throws Exception {
	String dirPath = "D:\\Research\\Datasets\\Ciao\\";
	String dest = dirPath + "formatted\\" + "trust.txt";

	FileIO.deleteFile(dest);

	BufferedReader br = FileIO.getReader(dirPath + "trust.txt");
	String line = null;
	List<String> lines = new ArrayList<>();
	while ((line = br.readLine()) != null) {
		String[] data = line.trim().split("  ");

		int trustor = (int) Double.parseDouble(data[0]);
		int trustee = (int) Double.parseDouble(data[1]);

		line = trustor + " " + trustee + " " + 1.0;
		lines.add(line);

		if (lines.size() >= 1000) {
			FileIO.writeList(dest, lines, true);
			lines.clear();
		}
	}

	if (lines.size() > 0)
		FileIO.writeList(dest, lines, true);

	br.close();
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:31,代码来源:CiaoTest.java

示例4: run_category_reviews

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_category_reviews(String url) throws Exception {
	String[] data = url.split(": ");
	String category = data[0];
	String catPath = FileIO.makeDirPath(desktop, domain, category);
	File Dir = new File(catPath);
	File[] prodDirs = Dir.listFiles();
	int tk = prodDirs.length;
	String movie_reviews = catPath + "movie-review-ratings.txt";
	FileIO.deleteFile(movie_reviews);

	for (int k = 0; k < tk; k++) {
		File prodDir = prodDirs[k];
		// for each product
		String productID = prodDir.getName();
		if (productID.equals("webPages"))
			continue;
		if (!prodDir.isDirectory())
			continue;

		String prodPath = FileIO.makeDirPath(catPath, productID);
		String dvdPath = prodPath + "review-ratings.txt";
		if (!FileIO.exist(dvdPath))
			continue; // no review ratings

		// read review ratings from each product, and remove the duplicated
		// review ratings
		Set<String> review_ratings = FileIO.readAsSet(dvdPath);
		FileIO.writeList(movie_reviews, review_ratings, null, true);
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:31,代码来源:CiaoCrawler.java

示例5: run_category_ratings

import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
 * Concate all the dvd ratings about the products in a specific category
 * 
 * @param url
 * @throws Exception
 */
public void run_category_ratings(String url) throws Exception {
	String[] data = url.split(": ");
	String category = data[0];

	String catPath = FileIO.makeDirPath(desktop, domain, category);
	File Dir = new File(catPath);
	File[] prodDirs = Dir.listFiles();
	int tk = prodDirs.length;

	String ratingFile = catPath + "movie-ratings.txt";
	FileIO.deleteFile(ratingFile);

	for (int k = 0; k < tk; k++) {
		File prodDir = prodDirs[k];
		// for each product
		String productID = prodDir.getName();
		if (productID.equals("webPages"))
			continue;
		if (!prodDir.isDirectory())
			continue;

		Logs.debug("{}: {} ({}/{})", new Object[] { category, productID,
				(k + 1), tk });

		String prodPath = FileIO.makeDirPath(catPath, productID);
		String dvdPath = prodPath + "dvd-ratings.txt";
		if (!FileIO.exist(dvdPath))
			continue;

		List<String> dvd_ratings = FileIO.readAsList(dvdPath);

		FileIO.writeList(ratingFile, dvd_ratings, null, true);
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:41,代码来源:CiaoCrawler.java

示例6: getAllRatings

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void getAllRatings() throws Exception {
	String filePath = FileIO.getResource("dvd.ciao.txt");
	List<String> urls = FileIO.readAsList(filePath);

	String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
	String ratingFile = dir + "ratings.txt";
	String reviewFile = dir + "review-ratings.txt";
	FileIO.deleteFile(ratingFile);
	FileIO.deleteFile(reviewFile);

	for (String url : urls) {
		// each category
		String[] data = url.split(": ");
		String category = data[0];
		String dirPath = FileIO.makeDirPath(dir, category);

		// ratings
		String ratingPath = dirPath + "ratings.txt";
		List<String> ratings = FileIO.readAsList(ratingPath);

		FileIO.writeList(ratingFile, ratings, null, true);

		// reviews
		String reviewPath = dirPath + "review-ratings.txt";
		List<String> reviews = FileIO.readAsList(reviewPath);

		FileIO.writeList(reviewFile, reviews, null, true);
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:30,代码来源:CiaoParser.java

示例7: convertEpinionsTrust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void convertEpinionsTrust() throws Exception
{
	String dirPath = "D:\\Java\\eclipse\\workspace\\CF-RS\\dataset\\Extended Epinions\\";
	String source = dirPath + "rating.txt";

	String ids = dirPath + "itemId-mappings.txt";
	String target = dirPath + "ratings.txt";

	BufferedReader br = new BufferedReader(new FileReader(new File(source)));
	String line = null;
	Map<String, String> idMap = FileIO.readAsMap(ids);
	// Map<String, Integer> idMap = new HashMap<String, Integer>();
	List<String> lines = new ArrayList<>();

	while ((line = br.readLine()) != null)
	{
		String[] data = line.split(Dataset.REGMX);
		String userId = data[0];
		String itemId = data[1];
		String rating = data[2];

		String iId = idMap.get(itemId);

		String content = userId + Dataset.REGMX + iId + Dataset.REGMX + rating;
		lines.add(content);
		if (lines.size() == 1000)
		{
			FileIO.writeList(target, lines, null, true);
			lines.clear();
		}

	}
	if (lines.size() > 0) FileIO.writeList(target, lines, null, true);

	br.close();

}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:38,代码来源:DatasetUtils.java

示例8: samplingNetflix

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@Test
public void samplingNetflix() throws Exception
{
	ConfigParams.defaultInstance();

	String source = Dataset.DIRECTORY + Dataset.RATING_SET;
	String dest = Dataset.DIRECTORY + "Sample" + Systems.FILE_SEPARATOR + Dataset.RATING_SET;
	FileIO.deleteFile(dest);

	BufferedReader br = new BufferedReader(new FileReader(new File(source)));
	String line = null;
	List<String> lines = new ArrayList<>(3000);
	int numUser = 1000;
	while ((line = br.readLine()) != null)
	{
		String[] data = line.split(" ");
		int userId = Integer.parseInt(data[0]);

		if (userId > numUser) continue;
		lines.add(line);

		if (lines.size() > 1024)
		{
			FileIO.writeList(dest, lines, null, true);
			lines.clear();
		}
	}
	br.close();

	if (lines.size() > 0) FileIO.writeList(dest, lines, null, true);
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:32,代码来源:DatasetUtils.java

示例9: run_dvd_ratings

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_dvd_ratings(String url) throws Exception {
	String[] data = url.split(": ");
	String category = data[0];
	String category_url = data[1];
	category_url = category_url.substring(0, category_url.lastIndexOf('_'));
	String categoryID = category_url.substring(category_url
			.lastIndexOf('_') + 1);

	String catPath = FileIO.makeDirPath(desktop, domain, category);
	File Dir = new File(catPath);
	File[] prodDirs = Dir.listFiles();
	int tk = prodDirs.length;
	for (int k = 0; k < tk; k++) {
		File prodDir = prodDirs[k];
		// for each product
		String productID = prodDir.getName();
		if (productID.equals("webPages"))
			continue;
		if (!prodDir.isDirectory())
			continue;

		String prodPath = FileIO.makeDirPath(catPath, productID);
		String reviewPath = FileIO
				.makeDirPath(prodPath, "Detailed_Reviews");
		String dvdPath = prodPath + "dvd-ratings.txt";
		FileIO.deleteFile(dvdPath);

		File reviewDir = new File(reviewPath);
		File[] reviewDirs = reviewDir.listFiles();
		List<String> reviews = new ArrayList<>();
		for (int i = 0; i < reviewDirs.length; i++) {
			// for each review
			File reviewFile = reviewDirs[i];
			String reviewID = reviewFile.getName();
			Logs.debug("{}: {} ({}/{}): {} ({}/{})", category, productID,
					(k + 1), tk, reviewID, (i + 1), reviewDirs.length);

			String dirPath = FileIO.makeDirPath(reviewPath, reviewID);
			String ratingPath = dirPath + reviewID + ".html";
			if (!FileIO.exist(ratingPath))
				continue; // review page is not existing
			String html = FileIO.readAsString(ratingPath);
			Document doc = Jsoup.parse(html);
			Element div = doc.select("div#OH_BingUserInfo").first();
			if (div == null)
				continue; // no user review exists

			// user-info
			Element a = div.select("p.m-reer-usertab.clearfix a.black")
					.first();
			String raw = a.attr("onmousedown");
			raw = raw.substring(raw.indexOf("(") + 1, raw.lastIndexOf(")"));
			String userUrl = raw.replace(",", "").replace("'", "");
			String userID = userUrl.substring(userUrl.lastIndexOf('_') + 1);

			// user-rating value
			Element r = div.select(
					"p.m-reer-usertab.clearfix img.ratingStars").first();
			String rating = r.attr("alt");

			// user-rating date
			div = doc.select("div#OH_BingUserOpinion").first();
			Element date = div
					.select("div.m-reer-opheader.reviewTitle span.m-reer-ddwrap span[property]")
					.first();
			String datetime = date.attr("content");

			// content
			String review = userID + "," + productID + "," + categoryID
					+ "," + reviewID + "," + rating + "," + datetime + ","
					+ userUrl;
			reviews.add(review);
		}
		FileIO.writeList(dvdPath, reviews);
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:77,代码来源:CiaoCrawler.java

示例10: parseCategoryPages

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void parseCategoryPages() throws Exception {
	String filePath = FileIO.getResource("dvd.ciao.txt");
	List<String> urls = FileIO.readAsList(filePath);

	String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
	for (String url : urls) {
		// each category
		String[] data = url.split(": ");
		String category = data[0];
		String dirCate = FileIO.makeDirPath(dir, category);
		String dirPath = FileIO.makeDirPath(dir, category, "webPages");

		// clear
		FileIO.deleteFile(dirCate + "movies.txt");

		File dirs = new File(dirPath);
		for (File f : dirs.listFiles()) {
			// each web page
			String html = FileIO.readAsString(dirPath + f.getName());
			Document doc = Jsoup.parse(html);

			Logs.debug(category + ": " + f.getName());

			List<String> movies = new ArrayList<>();
			Elements products = doc.select("td.prodInfo");
			for (Element product : products) {
				// each product
				Element prod = product.select("p.prodName").first();
				String name = prod.text();
				String link = prod.select("a").first().attr("href");
				String id = link.substring(link.lastIndexOf("_") + 1);

				// number of user reviews
				prod = product.select("p.prodRating").first();
				String cnt = prod.select(".userReviewsCount").text()
						.replace("(", "").replace(")", "");
				int count = 0;
				if (!cnt.isEmpty())
					count = Integer.parseInt(cnt);

				// do not consider movies without any reviews
				if (count > 0) {
					String movie = id + "::" + name + "::" + link;
					movies.add(movie);
				}
			}

			FileIO.writeList(dirCate + "movies.txt", movies, null, true);
		}
	}

}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:53,代码来源:CiaoParser.java

示例11: getAllTrust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void getAllTrust() throws Exception {

		Map<String, String> users = new HashMap<>();
		List<String> userLines = FileIO.readAsList(FileIO
				.getResource("users.txt"));
		for (String line : userLines) {
			String[] data = line.split(",");
			users.put(data[1], data[0]);
		}

		String usersPath = FileIO.makeDirPath(desktop, domain,
				"users.ciao.co.uk");
		FileIO.deleteFile(usersPath + "trust.txt");

		File dir = new File(usersPath);
		File[] files = dir.listFiles();

		for (int i = 0, n = files.length; i < n; i++) {
			// for each user
			File userFile = files[i];
			final String userID = userFile.getName();

			String html = null;
			Document doc = null;
			List<String> friends = new ArrayList<>();
			File[] pages = userFile.listFiles();
			for (int j = 0, m = pages.length; j < m; j++) {
				// for each trust page
				File file = pages[j];
				String name = file.getName();
				if (name.startsWith("friends")) {
					html = FileIO.readAsString(file.getPath());
					doc = Jsoup.parse(html);
					Element trustTable = doc.select("form table.trust").first();
					Elements trs = trustTable.select("tbody tr");
					for (Element tr : trs) {
						Element td = tr.select("td").get(1);
						Element a = td.select("a").first();
						String link = a.attr("href");
						if (users.containsKey(link)) {
							friends.add(users.get(link));
						}
					}
				}
			}

			FileIO.writeList(usersPath + "trust.txt", friends,
					new Converter<String, String>() {

						@Override
						public String transform(String friend) {
							return userID + "," + friend + ",1";
						}
					}, true);
		}

	}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:58,代码来源:CiaoParser.java

示例12: parseReviewPages

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void parseReviewPages() throws Exception {
	String filePath = FileIO.getResource("dvd.ciao.txt");
	List<String> urls = FileIO.readAsList(filePath);

	String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
	for (String url : urls) {
		// each category
		String[] data = url.split(": ");
		String category = data[0];
		String dirCate = FileIO.makeDirPath(dir, category);

		File dirs = new File(dirCate);
		for (File f : dirs.listFiles()) {
			// each product folder
			if (f.getName().equals("webPages"))
				continue;
			if (!f.isDirectory())
				continue;

			String prodPath = FileIO.makeDirPath(dirCate, f.getName());
			String revwPath = FileIO.makeDirPath(prodPath, "Reviews");

			List<String> reviews = new ArrayList<>();
			File reviewDirs = new File(revwPath);

			for (File rf : reviewDirs.listFiles()) {
				// each review page
				String html = FileIO.readAsString(rf.getPath());
				Document doc = Jsoup.parse(html);

				Elements es = doc.select("div.m-shortReviewSnippet");
				for (Element e : es) {
					Element a = e.select(
							"p.m-shet-review-title a.ReviewTitle").first();
					if (a == null)
						continue; // some reviews do not have specific link
									// to detailed contents

					// url
					String link = a.attr("href");

					int idx = link.lastIndexOf("_");
					String id = link.substring(idx + 1);

					reviews.add(id + "::" + link);
				}
			}

			FileIO.writeList(prodPath + "reviews.txt", reviews, null, false);
		}

	}

}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:55,代码来源:CiaoParser.java


注:本文中的happy.coding.io.FileIO.writeList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。