本文整理汇总了Java中happy.coding.io.FileIO类的典型用法代码示例。如果您正苦于以下问题:Java FileIO类的具体用法?Java FileIO怎么用?Java FileIO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileIO类属于happy.coding.io包,在下文中一共展示了FileIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readVisual
import happy.coding.io.FileIO; //导入依赖的package包/类
public void readVisual(String path) throws IOException {
System.out.println("Loading visual from " + path);
BufferedReader br = FileIO.getReader(path);
String line = null;
while ((line = br.readLine()) != null) {
line = line.trim();
if (!line.isEmpty()) {
String[] items = line.trim().split(",");
String id = items[0];
Integer tid = itemIds.get(id);
if (tid != null) {
Tweet t = tweets[tid];
t.setVisual(items[1].trim().split("\\s+"));
}
}
}
br.close();
}
示例2: testSerialization
import happy.coding.io.FileIO; //导入依赖的package包/类
@Test
public void testSerialization() throws Exception {
String filePath = Systems.getDesktop() + "vec.dat";
DenseVector vec = new DenseVector(11);
for (int i = 10, j = 0; i >= 0; i--, j++)
vec.set(j, i);
FileIO.serialize(vec, filePath);
DenseVector v2 = (DenseVector) FileIO.deserialize(filePath);
Logs.debug(v2.toString());
DenseMatrix mat = new DenseMatrix(3, 4);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 4; j++)
mat.set(i, j, i + j);
Logs.debug(mat);
String matPath = Systems.getDesktop() + "mat.dat";
FileIO.serialize(mat, matPath);
DenseMatrix mat2 = (DenseMatrix) FileIO.deserialize(matPath);
Logs.debug(mat2);
}
示例3: 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);
}
示例4: run_web_pages
import happy.coding.io.FileIO; //导入依赖的package包/类
public void run_web_pages(String url) throws Exception {
String[] data = url.split(": ");
String category = data[0];
String link = data[1];
String dirPath = FileIO.makeDirectory(dir, category, "webPages");
int pageSize = 15;
String html = read_url(link);
FileIO.writeString(dirPath + "page_" + 1 + ".html", html);
Document doc = Jsoup.parse(html);
int maxPage = Integer.parseInt(doc.select(
"div.CWCiaoKievPagination.clearfix li.last").text());
Logs.debug(category + ": progress [" + 1 + "/" + maxPage + "]");
for (int i = 2; i <= maxPage; i++) {
String pageLink = link + "~s" + (i - 1) * pageSize;
String content = read_url(pageLink);
FileIO.writeString(dirPath + "page_" + i + ".html", content);
Logs.debug(category + ": progress [" + i + "/" + maxPage + "]");
}
}
示例5: crawl_web_pages
import happy.coding.io.FileIO; //导入依赖的package包/类
public void crawl_web_pages() throws Exception
{
String filePath = "./src/main/resources/mtime.txt";
List<String> urls = FileIO.readAsList(filePath);
for (String url : urls)
{
String html = URLReader.read(url);
Document doc = Jsoup.parse(html);
String name = doc.select("span[property=v:itemreviewed]").text();
name = Strings.filterWebString(name, '_');
String dirPath = dir + name + "/";
FileIO.makeDirectory(dirPath);
FileIO.writeString(dirPath + name + ".html", html);
}
}
示例6: parse_overall_ratings
import happy.coding.io.FileIO; //导入依赖的package包/类
public void parse_overall_ratings() throws Exception
{
File directory = new File(dir);
File[] dirs = directory.listFiles();
for (File d : dirs)
{
String fname = d.getName();
String file = d.getPath() + "/" + fname + ".html";
Document doc = Jsoup.parse(FileIO.readAsString(file));
MTimeMovie mm = new MTimeMovie();
String name = doc.select("span[property=v:itemreviewed]").text();
mm.setName(name);
String year = doc.select("a.c_666").first().text();
mm.setYear(Integer.parseInt(year));
}
}
示例7: 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);
}
示例8: 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;
}
示例9: predictMissingRating
import happy.coding.io.FileIO; //导入依赖的package包/类
@Override
protected double predictMissingRating(Rating r)
{
String user = r.getUserId();
String item = r.getItemId();
Map<String, String> ratings = null;
try
{
ratings = FileIO.readAsMap(trustDirPath + user + ".txt");
} catch (Exception e)
{
e.printStackTrace();
}
double rating = 0.0;
if (ratings != null && ratings.containsKey(item + ""))
{
rating = Double.parseDouble(ratings.get(item + ""));
}
return rating;
}
示例10: sampleByItems
import happy.coding.io.FileIO; //导入依赖的package包/类
@Test
public void sampleByItems() throws Exception
{
int num_users = 3000;
int num_items = 2000;
ConfigParams.defaultInstance();
String dirPath = Dataset.DIRECTORY + "Sample_" + num_items + "_items/";
FileIO.deleteDirectory(dirPath);
FileIO.makeDirectory(dirPath);
samplingDatasetByItems(num_users, num_items);
String trustPath = Dataset.DIRECTORY + Dataset.TRUST_SET;
retrieveTrustData(dirPath, trustPath);
splitKFoldDataset(dirPath);
Logs.debug("Data sampling is done!");
}
示例11: retrieveTrustData
import happy.coding.io.FileIO; //导入依赖的package包/类
public static void retrieveTrustData(String dirPath, String trustPath) throws Exception
{
ConfigParams.defaultInstance();
String ratingSet = dirPath + Dataset.RATING_SET;
Map<String, Map<String, Rating>> userMap = Dataset.loadRatingSet(ratingSet);
BufferedReader br = new BufferedReader(new FileReader(trustPath));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null)
{
if (line.isEmpty()) continue;
String[] data = line.split(Dataset.REGMX);
String trustor = data[0];
String trustee = data[1];
if (userMap.containsKey(trustor) && userMap.containsKey(trustee)) sb.append(line + "\n");
}
br.close();
String filePath = dirPath + Dataset.TRUST_SET;
FileIO.writeString(filePath, sb.toString());
Logs.debug("Saved the trust sample to: " + filePath);
}
示例12: 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);
}
}
示例13: makeDirPaths
import happy.coding.io.FileIO; //导入依赖的package包/类
protected void makeDirPaths() throws Exception {
int horizon = params.TRUST_PROPERGATION_LENGTH;
String trustDir = (params.TIDALTRUST ? "TT" : "MT") + horizon;
String trustDir2 = params.TIDALTRUST ? "TidalTrust" : "MoleTrust";
String trustDir0 = null;
if (params.auto_trust_sets)
trustDir0 = current_trust_name;
String[] trustDirs = null;
if (params.auto_trust_sets) {
trustDirs = new String[] { Dataset.TEMP_DIRECTORY, trustDir, trustDir0, trustDir2 };
} else {
trustDirs = new String[] { Dataset.TEMP_DIRECTORY, trustDir, trustDir2 };
}
trustDirPath = FileIO.makeDirPath(trustDirs);
FileIO.makeDirectory(trustDirPath);
}
示例14: 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!");
}
示例15: load_proxy
import happy.coding.io.FileIO; //导入依赖的package包/类
protected void load_proxy() throws Exception
{
proxy = new HashMap<>();
String path = FileIO.getResource("proxy.txt");
List<String> lines = FileIO.readAsList(path);
for (String line : lines)
{
String[] data = line.split(":");
String host = data[0];
int port = Integer.parseInt(data[1]);
proxy.put(host, port);
}
hosts = new ArrayList<>(proxy.keySet());
}