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


Java FileIO.writeMap方法代码示例

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


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

示例1: getAllUsers

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

	String dir = Systems.getDesktop() + "dvd.ciao.co.uk\\";
	String userFile = dir + "users.txt";
	Map<String, String> userMap = new HashMap<>();
	for (String url : urls) {
		// each category
		String[] data = url.split(": ");
		String category = data[0];
		String dirPath = FileIO.makeDirPath(dir, category);

		// users
		String userPath = dirPath + "users.txt";
		List<String> users = FileIO.readAsList(userPath);
		for (String line : users) {
			String[] d = line.split(",");
			userMap.put(d[0], d[1]);
		}
	}

	FileIO.writeMap(userFile, userMap);
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:25,代码来源:CiaoParser.java

示例2: saveTrust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
/**
 * save the computed implicit trust to disk
 * 
 * @param u active user u
 * @param tns u's trusted neighbors
 * @throws Exception
 */
private void saveTrust(final String u, Map<String, Double> tns) throws Exception
{
	if (tns.size() > 0)
	{
		String trustFile = trustDir + u + ".txt";

		FileIO.writeMap(trustFile, tns, new MapWriter<String, Double>() {

			@Override
			public String processEntry(String key, Double val)
			{
				return key + " " + val;
			}
		}, false);

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

示例3: probeTTTnScores

import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected void probeTTTnScores() throws Exception
{
	int horizon = params.TRUST_PROPERGATION_LENGTH;
	FileIO.makeDirectory(trustDirPath);
	Logs.debug("Building TT{} Data to: {}", horizon, trustDirPath);

	for (String user : testUserRatingsMap.keySet())
	{
		File file = new File(trustDirPath + user + ".txt");
		if (file.exists()) continue;

		Map<String, Double> trustScores = TidalTrust.runAlgorithm(userTrusteesMap, userTrustorsMap,
				userTrustRatingsMap, user, horizon);
		if (trustScores != null && trustScores.size() > 0) FileIO.writeMap(file.getPath(), trustScores);
	}
	Logs.debug("Done!");
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:18,代码来源:TTx_mt.java

示例4: probeMTTnScores

import happy.coding.io.FileIO; //导入方法依赖的package包/类
protected void probeMTTnScores() throws Exception
{
	int horizon = params.TRUST_PROPERGATION_LENGTH;
	Logs.debug("Building MT{} Data to: {} ...", horizon, trustDirPath);

	for (String user : testUserRatingsMap.keySet())
	{
		File userFile = new File(trustDirPath + user + ".txt");
		if (userFile.exists()) continue;

		Map<String, Double> trustScores = MoleTrust.runAlgorithm(userTNsMap, user, horizon);
		if (trustScores.size() > 0) FileIO.writeMap(userFile.getPath(), trustScores);
	}
	Logs.debug("Done!");
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:16,代码来源:MTx_mt.java

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

示例6: resampleTrust

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@Test
public void resampleTrust() throws Exception
{
	ConfigParams.defaultInstance();
	String trustSet = Dataset.DIRECTORY + Dataset.TRUST_SET;
	Map<String, Map<String, Double>> userTNsMap = DatasetUtils.loadTrustSet(trustSet);
	Map<String, Map<String, Double>> tnsMap = new HashMap<>();

	int size = 5;
	for (String user : userTNsMap.keySet())
	{
		Map<String, Double> tns = userTNsMap.get(user);

		if (tns != null && tns.size() > size)
		{
			tnsMap.put(user, tns);
		}
	}

	// print out
	String dir = Systems.getDesktop();
	String path = dir + Dataset.TRUST_SET;
	FileIO.writeMap(path, tnsMap, new MapWriter<String, Map<String, Double>>() {

		@Override
		public String processEntry(String key, Map<String, Double> val)
		{
			StringBuilder sb = new StringBuilder();

			int i = 0;
			for (Entry<String, Double> en : val.entrySet())
			{
				i++;
				String line = key + " " + en.getKey() + " " + en.getValue();
				if (i < val.size()) line += "\n";
				sb.append(line);
			}

			return sb.toString();
		}
	}, false);
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:43,代码来源:DatasetUtils.java

示例7: resampleRatings

import happy.coding.io.FileIO; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void resampleRatings() throws Exception
{
	ConfigParams.defaultInstance();
	String trustSet = Dataset.DIRECTORY + "\\Resample-5\\" + Dataset.TRUST_SET;
	String ratingSet = Dataset.DIRECTORY + Dataset.RATING_SET;

	Map<String, Map<String, Double>> userTNsMap = DatasetUtils.loadTrustSet(trustSet);
	Map<String, Map<String, Rating>> userRatingsMap = Dataset.loadTrainSet(ratingSet)[0];
	Map<String, Map<String, Rating>> ursMap = new HashMap<>();

	for (String user : userTNsMap.keySet())
	{
		if (userRatingsMap.containsKey(user))
		{
			Map<String, Rating> rs = userRatingsMap.get(user);

			ursMap.put(user, rs);
		}
	}

	// print out
	String path = Dataset.DIRECTORY + "\\Resample-5\\" + Dataset.RATING_SET;
	FileIO.writeMap(path, ursMap, new MapWriter<String, Map<String, Rating>>() {

		@Override
		public String processEntry(String key, Map<String, Rating> val)
		{
			StringBuilder sb = new StringBuilder();

			int i = 0;
			for (Entry<String, Rating> en : val.entrySet())
			{
				i++;
				Rating r = en.getValue();
				String line = r.getUserId() + " " + r.getItemId() + " " + r.getRating();
				if (i < val.size()) line += "\n";
				sb.append(line);
			}

			return sb.toString();
		}
	}, false);
}
 
开发者ID:466152112,项目名称:HappyResearch,代码行数:46,代码来源:DatasetUtils.java


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