本文整理汇总了Java中happy.coding.io.FileIO.makeDirPath方法的典型用法代码示例。如果您正苦于以下问题:Java FileIO.makeDirPath方法的具体用法?Java FileIO.makeDirPath怎么用?Java FileIO.makeDirPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类happy.coding.io.FileIO
的用法示例。
在下文中一共展示了FileIO.makeDirPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: ReadFolder
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void ReadFolder(String dirPath) throws Exception
{
dirPath = FileIO.makeDirPath(dirPath);
File dir = new File(dirPath);
if (!dir.isDirectory()) throw new Exception(dirPath + " is not a directory");
File[] files = dir.listFiles();
for (File file : files)
{
String results = file.getName() + "\r\n";
results += FileIO.readAsString(file.getPath(), new String[] { "MAE", "MAUE" });
FileIO.writeString(dirPath + "Results.txt", results, true);
}
}
示例7: load_tags
import happy.coding.io.FileIO; //导入方法依赖的package包/类
private void load_tags() throws Exception
{
String file = "movie-tags.csv";
if (itemTags == null)
{
itemTags = new HashMap<>();
String path = FileIO.makeDirPath(Dataset.DIRECTORY, file);
Logs.debug("Load item's tags from {}", Strings.shortStr(path));
tags = new ArrayList<>();
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line = null;
while ((line = br.readLine()) != null)
{
String[] data = line.split(",");
String item = data[0];
String tag = data[1]; //.toLowerCase().replace(" ", "");
if (!tags.contains(tag)) tags.add(tag);
Map<String, Integer> innerMap = null;
if (itemTags.containsKey(item)) innerMap = itemTags.get(item);
else innerMap = new HashMap<>();
int count = 0;
if (innerMap.containsKey(tag)) count = innerMap.get(tag);
count++;
innerMap.put(tag, count);
itemTags.put(item, innerMap);
}
br.close();
}
}
示例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;
}
示例9: main
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Logs.config(FileIO.getResource("log4j.properties"), false);
conf = new Configer("tp.conf");
dataset = conf.getString("dataset");
testView = conf.getString("test.view");
dirPath = FileIO.makeDirPath(conf.getPath("dataset.dir"), dataset);
switch (conf.getString("method")) {
case "ETAF":
ETAF tm = new ETAF();
for (Float alpha : conf.getRange("val.ETAF.alpha")) {
// alpha for trust combination
tm.alpha = alpha.floatValue();
for (Float gamma : conf.getRange("val.ETAF.gamma")) {
// gamma for ability combination
tm.gamma = gamma.floatValue();
tm.isIn = conf.isOn("is.ETAF.in");
if (tm.isIn) {
for (Float eta : conf.getRange("val.ETAF.eta")) {
// eta for integrity combination
tm.eta = eta.floatValue();
Logs.debug("Settings: alpha = {}, gamma = {}, eta = {}, in = {}",
new Object[] { alpha.floatValue(), gamma.floatValue(), eta.floatValue(), tm.isIn });
settings = alpha + sep + gamma + sep + eta + sep + tm.isIn;
tm.execute();
}
} else {
// not to consider integrity at all
tm.eta = 1f;
Logs.debug("Settings: alpha = {}, gamma = {}, in = {}", new Object[] { alpha.floatValue(),
gamma.floatValue(), tm.isIn });
settings = alpha + sep + gamma + sep + tm.isIn;
tm.execute();
}
}
}
break;
case "TAF":
new TAF().execute();
break;
case "EPT":
EPT ept = new EPT();
List<Float> Nmins = conf.getRange("num.EPT.Nmin");
for (Float n : Nmins) {
ept.Nmin = n.intValue();
Logs.debug("Settings: Nmin = {}", ept.Nmin);
settings = "" + ept.Nmin;
ept.execute();
}
break;
default:
break;
}
String destPath = FileIO.makeDirectory(dirPath, "Results");
String dest = destPath + model + "@" + Dates.now() + ".txt";
FileIO.copyFile("results.txt", dest);
if (conf.isOn("is.email.notify")) {
Gmailer notifier = new Gmailer();
notifier.getProps().setProperty("mail.to", "[email protected]");
notifier.getProps().setProperty("mail.subject",
FileIO.getCurrentFolder() + "-" + model + " is finished @ " + Systems.getIP());
notifier.send("Program " + model + " has been finished!", dest);
}
}
示例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);
}
}
示例11: run_user
import happy.coding.io.FileIO; //导入方法依赖的package包/类
public void run_user(String url) throws Exception {
String[] data = url.split(",");
String userID = data[0];
String userUrl = data[1];
String userPath = FileIO.makeDirPath(desktop, domain,
"users.ciao.co.uk");
String html = read_url(userUrl);
// check if user exists now
Document doc = Jsoup.parse(html);
Elements tabs = doc.select("table.tabs");
if (tabs == null || tabs.size() == 0)
return; // no such user profile
userPath = FileIO.makeDirectory(userPath, userID);
FileIO.writeString(userPath + userID + ".html", html);
// trusted neighbors
String link = "http://www.ciao.co.uk/member_view.php/MemberId/"
+ userID + "/TabId/5/subTabId/1";
html = read_url(link);
// find the max pages
doc = Jsoup.parse(html);
Element page = doc
.select("table#comparePricesShowAllTop td.rangepages").first();
if (page == null)
return; // no friends at all
FileIO.writeString(userPath + "friends-1.html", html);
if (page.text().length() <= 1)
return; // no more pages
Element a = page.select("a").last();
int maxPage = Integer.parseInt(a.text());
for (int i = 2; i <= maxPage; i++) {
String nextPage = link + "/Start/" + (i - 1) * 15;
html = read_url(nextPage);
FileIO.writeString(userPath + "friends-" + i + ".html", html);
}
}
示例12: 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);
}
}
}
}
示例13: 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);
}
}
}
示例14: 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);
}
}
示例15: 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);
}
}
}