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


Java FileIO.exist方法代码示例

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


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

示例1: buildModel

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected Map<String, Double>[] buildModel(Rating testRating)
{
	try
	{
		String u = testRating.getUserId();
		String file = trustDir + u + ".txt";
		if (!FileIO.exist(file)) return null;

		/* read trust information from trust file */
		Map<String, Double> tns = FileIO.readAsIDMap(file, " ");
		if (tns == null) return null;
		else return new Map[] { tns };

	} catch (Exception e)
	{
		e.printStackTrace();
	}

	return null;

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

示例2: saveModel

import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected String saveModel() throws Exception {
	// make a folder
	modelFolder = resultFolder + File.separator + "model/";
	FileIO.makeDirectory(modelFolder);

	if (!FileIO.exist(modelFolder + "config"))
		FileIO.copyFile(configPath, modelFolder + "config");

	// save the rating matrix and dao as binary to save space
	String suffix = ".bin";
	if (cf.isOn("save.model.bin")) {
		suffix = ".bin";
		FileIO.serialize(U, modelFolder + "userFactors" + suffix);
		FileIO.serialize(T, modelFolder + "textFactors" + suffix);
		if (V != null)
			FileIO.serialize(V, modelFolder + "visualFactors" + suffix);
	} else {
		suffix = ".txt";
		if (U != null)
			VectorUtil.saveMatrix(U, modelFolder + "userFactors" + suffix);
		if (T != null)
			VectorUtil.saveMatrix(T, modelFolder + "textFactors" + suffix);
		if (V != null)
			VectorUtil.saveMatrix(V, modelFolder + "visualFactors" + suffix);
	}

	suffix = ".txt";
	// save name-id maps
	VectorUtil.saveMap(trainDao.getIdUsers(), modelFolder + "idUsers" + suffix);
	VectorUtil.saveMap(trainDao.getIdItems(), modelFolder + "train_idItems" + suffix);
	VectorUtil.saveMap(testDao.getIdItems(), modelFolder + "test_idItems" + suffix);
	Logs.debug("Learned models are saved to folder \"{}\"", modelFolder);

	return modelFolder;
}
 
开发者ID:kite1988,项目名称:famf,代码行数:36,代码来源:Recommender.java

示例3: loadModel

import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected void loadModel(String dirPath) throws Exception {
	logPW.println(String.format("A recommender model is loaded from %s", dirPath));
	dirPath += File.separator;

	String suffix = ".txt";
	U = VectorUtil.loadMatix(dirPath + "userFactors" + suffix);
	T = VectorUtil.loadMatix(dirPath + "textFactors" + suffix);
	if (FileIO.exist(dirPath + "visualFactors" + suffix))
		V = VectorUtil.loadMatix(dirPath + "visualFactors" + suffix);

	// load vectors
	suffix = ".txt";

}
 
开发者ID:kite1988,项目名称:famf,代码行数:15,代码来源:Recommender.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: load_trusts

import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected void load_trusts() throws Exception {
	if (userTNsMap == null) {
		String trustSet = null;
		if (!params.auto_trust_sets) {
			trustSet = Dataset.DIRECTORY + Dataset.TRUST_SET;
			if (!FileIO.exist(trustSet))
				return;
		} else {
			trustSet = current_trust_dir + Dataset.TRUST_SET;
		}

		switch (Dataset.dataset) {
		case EXTENDED_EPINIONS:
			if (!params.auto_trust_sets) {
				String distrustSet = Dataset.DIRECTORY + Dataset.DISTRUST_SET;
				Logs.debug("Loading distrust data {}", distrustSet);
				userDNsMap = DatasetUtils.loadTrustSet(distrustSet);
				// no break to continue load trust
			}
		case EPINIONS:
		case FILMTRUST:
		case FLIXSTER:
			Logs.debug("Loading trust data {}", trustSet);
			userTNsMap = DatasetUtils.loadTrustSet(trustSet);
			userTrustorsMap = DatasetUtils.loadTrusteeSet(trustSet);
			break;
		default:
			break;
		}

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

示例7: probeITrust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
 * Probe implicit trust from user ratings
 * @throws Exception 
 */
private void probeITrust() throws Exception
{
	trustDir = Dataset.DIRECTORY + trustMetric + "-"
			+ params.TRAIN_SET.substring(0, params.TRAIN_SET.lastIndexOf(".base")) + Systems.FILE_SEPARATOR;

	if (FileIO.exist(trustDir)) return;
	else FileIO.makeDirectory(trustDir);

	switch (trustMetric)
	{
		case "TM1":
			TM1();
			break;
		case "TM2":
			TM2();
			break;
		case "TM3a":
			TM3a();
			break;
		case "TM3b":
			TM3b();
			break;
		case "TM4":
			TM4();
			break;
		case "TM5":
			TM5();
			break;
	}

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

示例8: predict

import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
 * Predict the trusted values for the trustors
 * 
 * @return the path to the prediction results
 */
protected String predict() throws Exception {
	Logs.debug("Predict users' trustworthiness ...");

	// store prediction data to disk
	String path = FileIO.makeDirPath(dirPath, FileIO.getCurrentFolder(), model + "-preds");
	if (FileIO.exist(path))
		FileIO.deleteDirectory(path);
	FileIO.makeDirectory(path);

	Map<String, Float> preds = new HashMap<>();
	for (final String u : testUsers) {

		// predict trustworthiness
		preds.clear();
		for (String v : users) {
			if (u.equals(v))
				continue;

			float tuv = predict(u, v);

			if (tuv > 0)
				preds.put(v, tuv);
		}

		// output trust predictions to save memory
		if (Debug.ON) {
			if (preds.size() > 0) {
				FileIO.writeMap(path + u + ".txt", preds, new MapWriter<String, Float>() {

					@Override
					public String processEntry(String key, Float val) {
						return u + sep + key + sep + val;
					}
				}, false);
			}
		}
	}
	Logs.debug("Done!");

	return path;
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:47,代码来源:TrustModel.java

示例9: evaluate

import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
 * Evalute the performance of our ETAF model
 */
protected void evaluate(String path) throws Exception {

	Map<String, Float> preds = null;
	Map<String, Integer> trustees = null;
	int topN = 20;
	Set<String> trustors = trusts.rowKeySet();

	List<Float> precs5 = new ArrayList<>();
	List<Float> precs10 = new ArrayList<>();
	List<Float> recalls5 = new ArrayList<>();
	List<Float> recalls10 = new ArrayList<>();
	List<Float> aps = new ArrayList<>();
	List<Float> rrs = new ArrayList<>();
	List<Float> aucs = new ArrayList<>();
	List<Float> ndcgs = new ArrayList<>();

	for (String u : trustors) {
		// load preds
		String dataFile = path + u + ".txt";
		if (!FileIO.exist(dataFile))
			continue;
		preds = loadPreds(dataFile);
		// ground truth
		trustees = trusts.row(u);

		List<KeyValPair<String>> sorted = Lists.sortMap(preds, true);
		List<KeyValPair<String>> recomd = sorted.subList(0, sorted.size() > topN ? topN : sorted.size());

		List<String> rankedList = new ArrayList<>();
		for (KeyValPair<String> kv : recomd)
			rankedList.add(kv.getKey());

		List<String> groundTruth = new ArrayList<>(trustees.keySet());
		int num_dropped_items = 0;
		double AUC = Measures.AUC(rankedList, groundTruth, num_dropped_items);
		double AP = Measures.AP(rankedList, groundTruth);
		double nDCG = Measures.nDCG(rankedList, groundTruth);
		double RR = Measures.RR(rankedList, groundTruth);

		List<Integer> ns = Arrays.asList(5, 10);

		Map<Integer, Double> precs = Measures.PrecAt(rankedList, groundTruth, ns);
		Map<Integer, Double> recalls = Measures.RecallAt(rankedList, groundTruth, ns);

		precs5.add(precs.get(5).floatValue());
		precs10.add(precs.get(10).floatValue());
		recalls5.add(recalls.get(5).floatValue());
		recalls10.add(recalls.get(10).floatValue());

		aucs.add((float) AUC);
		aps.add((float) AP);
		rrs.add((float) RR);
		ndcgs.add((float) nDCG);
	}

	float prec5 = (float) Stats.mean(precs5);
	float prec10 = (float) Stats.mean(precs10);
	float recall5 = (float) Stats.mean(recalls5);
	float recall10 = (float) Stats.mean(recalls10);
	float ndcg = (float) Stats.mean(ndcgs);
	// float auc = (float) Stats.mean(aucs);
	float map = (float) Stats.mean(aps);
	float mrr = (float) Stats.mean(rrs);

	Logs.info("{},{},{},{},{},{},{},{},{}", new Object[] { model, prec5, prec10, recall5, recall10, map, ndcg, mrr,
			settings });

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

示例10: 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

示例11: run_products

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_products(String url) throws Exception {
	String[] data = url.split(": ");
	String category = data[0];
	// String link = data[1];

	String dirPath = FileIO.makeDirPath(desktop, domain, category);
	List<String> links = FileIO.readAsList(dirPath + "movies.txt");
	int tk = links.size();
	for (int k = 0; k < tk; k++) {
		String link = links.get(k);
		String[] d = link.split("::");
		String id = d[0];
		String name = d[1];
		String productLink = d[2];
		int idx = productLink.lastIndexOf("/");
		String p1 = productLink.substring(0, idx) + "/Reviews";
		String reviewLink = p1 + productLink.substring(idx);

		// create folder
		String path = FileIO.makeDirectory(dirPath, id);

		// product page
		String html = null;

		String pagePath = path + id + ".html";
		if (!FileIO.exist(pagePath)) {
			html = read_url(productLink);
			FileIO.deleteFile(path + name + ".html");
			FileIO.writeString(pagePath, html);
		}

		// product reviews
		// get first page anyway to identify the maximum pages
		path = FileIO.makeDirectory(path, "Reviews");
		String reviewPath = path + "page_1.html";
		if (FileIO.exist(reviewPath)) {
			html = FileIO.readAsString(reviewPath);
		} else {
			html = read_url(reviewLink);
			FileIO.writeString(reviewPath, html);
		}
		Logs.debug(category + ": " + id + " (" + (k + 1) + "/" + tk + ")"
				+ ": page " + 1);

		Document doc = Jsoup.parse(html);
		Elements nav = doc.select("div#Pagination");

		if (!nav.isEmpty()) {
			int maxPage = 1;

			Elements last = nav.select("li.last");
			if (!last.isEmpty())
				maxPage = Integer.parseInt(last.first().text()); // more
																	// than
																	// 11
																	// pages
			else
				maxPage = Integer.parseInt(nav.select("li").last().text()); // less
																			// or
																			// equal
																			// 11
																			// pages

			for (int i = 2; i <= maxPage; i++) {
				String filePath = path + "page_" + i + ".html";
				if (FileIO.exist(filePath))
					continue;

				reviewLink = reviewLink + "/Start/" + ((i - 1) * 15);
				html = read_url(reviewLink);
				FileIO.writeString(filePath, html);

				Logs.debug(category + ": " + id + " (" + (k + 1) + "/" + tk
						+ ")" + ": page " + i + "/" + maxPage);
			}
		}
	}

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

示例12: crawl_comments

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void crawl_comments(String url) throws Exception
{
	String html = read_url(url);
	Document doc = Jsoup.parse(html);
	String name = doc.select("div.detail_head_name h1").first().text();
	name = Strings.filterWebString(name, '_');

	String val = doc.select("#detail_nav li a").first().attr("href");
	String id = val.substring(val.lastIndexOf("/") + 1);

	String dirPath = dir + name + "/comments/";
	FileIO.makeDirectory(dirPath);

	// save rating pages
	int max = 1;
	boolean maxSet = false;
	url = url + "/commentlist";

	for (int k = 0; k <= max; k++)
	{
		String page_file = dirPath + "page_" + (k + 1) + ".html";
		Logs.debug(name + " comments with page: " + (k + 1) + "/" + (max + 1));

		String contents = null;
		if (!FileIO.exist(page_file))
		{

			String link = "http://www.gewara.com/ajax/common/qryComment.xhtml?pageNumber="
					+ k
					+ "&relatedid="
					+ id
					+ "&title=&issue=false&hasMarks=true&tag=movie&isPic=true&isVideo=false&pages=true&maxCount=20&userLogo=";

			contents = read_url(link);
			FileIO.writeString(page_file, contents);// new String(contents.getBytes("utf-8"), "utf-8"));
		} else
		{
			contents = FileIO.readAsString(page_file);
		}

		// find the maximum page num;
		if (!maxSet)
		{
			Document doc2 = Jsoup.parse(contents);
			Elements es = doc2.select("div#page a");
			Element e = es.get(es.size() - 2);
			max = Integer.parseInt(e.attr("lang"));
			maxSet = true;
		}

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

示例13: run_reviews

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_reviews(String url) throws Exception
{
	url = url.trim();
	String html = read_url(url);
	Document doc = Jsoup.parse(html);
	String name = doc.select("span[property=v:itemreviewed]").text();
	name = Strings.filterWebString(name, '_');

	String dirPath = dir + name + "/reviews/";
	FileIO.makeDirectory(dirPath);

	// save rating pages
	int k = 0;
	url = url + "reviews";
	String link = url;
	while (true)
	{
		k++;
		String page = null;
		String path = dirPath + "page_" + k + ".html";
		if (!FileIO.exist(path))
		{
			page = read_url(link);
			FileIO.writeString(path, page);
			Logs.debug(name + " reviews with page: " + k);
		} else
		{
			page = FileIO.readAsString(path);
		}

		// find the next page link;
		Document doc2 = Jsoup.parse(page);
		Elements es = doc2.select("div#paginator a.next");
		if (es == null || es.size() == 0)
		{
			break;
		} else
		{
			link = url + es.first().attr("href");
		}
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:43,代码来源:DoubanCrawler.java

示例14: run_comments

import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_comments(String url) throws Exception
{
	url = url.trim();
	String html = read_url(url);
	Document doc = Jsoup.parse(html);
	String name = doc.select("span[property=v:itemreviewed]").text();
	name = Strings.filterWebString(name, '_');

	String dirPath = dir + name + "/comments/";
	FileIO.makeDirectory(dirPath);

	// save rating pages
	int k = 0;
	url = url + "comments";
	String link = url;
	while (true)
	{
		k++;
		String page_file = dirPath + "page_" + k + ".html";

		String contents = null;
		if (!FileIO.exist(page_file))
		{
			contents = read_url(link);
			FileIO.writeString(page_file, contents);
			Logs.debug(name + " comments with page: " + k);
		} else
		{
			contents = FileIO.readAsString(page_file);
		}

		// find the next page link;
		Document doc2 = Jsoup.parse(contents);
		Elements es = doc2.select("div#paginator a.next");
		if (es == null || es.size() == 0)
		{
			break;
		} else
		{
			link = url + es.first().attr("href");
		}
	}
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:44,代码来源:DoubanCrawler.java


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