Skip to content

Commit

Permalink
Added field delimiter to saveDataModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
aleSuglia committed Nov 21, 2016
1 parent e7d347f commit e9f996f
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ private DataModelUtils() {
/**
* Method that saves a data model to a file.
*
* @param dm the data model
* @param outfile file where the model will be saved
* @param dm the data model
* @param outfile file where the model will be saved
* @param overwrite flag that indicates if the file should be overwritten
* @param <U> type of users
* @param <I> type of items
* @throws FileNotFoundException when outfile cannot be used.
* @param delimiter field delimiter
* @param <U> type of users
* @param <I> type of items
* @throws FileNotFoundException when outfile cannot be used.
* @throws UnsupportedEncodingException when the requested encoding (UTF-8)
* is not available.
* is not available.
*/
public static <U, I> void saveDataModel(final DataModelIF<U, I> dm, final String outfile, final boolean overwrite)
public static <U, I> void saveDataModel(final DataModelIF<U, I> dm, final String outfile, final boolean overwrite, final String delimiter)
throws FileNotFoundException, UnsupportedEncodingException {
if (new File(outfile).exists() && !overwrite) {
System.out.println("Ignoring " + outfile);
Expand All @@ -59,7 +60,7 @@ public static <U, I> void saveDataModel(final DataModelIF<U, I> dm, final String
for (Entry<I, Double> e : userPrefModel.entrySet()) {
I item = e.getKey();
Double pref = userPrefModel.get(item);
out.println(user + "\t" + item + "\t" + pref + "\t-1");
out.println(user + delimiter + item + delimiter + pref + delimiter);
}
}
out.close();
Expand All @@ -69,16 +70,17 @@ public static <U, I> void saveDataModel(final DataModelIF<U, I> dm, final String
/**
* Method that saves a temporal data model to a file.
*
* @param dm the data model
* @param outfile file where the model will be saved
* @param dm the data model
* @param outfile file where the model will be saved
* @param overwrite flag that indicates if the file should be overwritten
* @param <U> type of users
* @param <I> type of items
* @throws FileNotFoundException when outfile cannot be used.
* @param delimiter field delimiter
* @param <U> type of users
* @param <I> type of items
* @throws FileNotFoundException when outfile cannot be used.
* @throws UnsupportedEncodingException when the requested encoding (UTF-8)
* is not available.
* is not available.
*/
public static <U, I> void saveDataModel(final TemporalDataModelIF<U, I> dm, final String outfile, final boolean overwrite)
public static <U, I> void saveDataModel(final TemporalDataModelIF<U, I> dm, final String outfile, final boolean overwrite, String delimiter)
throws FileNotFoundException, UnsupportedEncodingException {
if (new File(outfile).exists() && !overwrite) {
System.out.println("Ignoring " + outfile);
Expand All @@ -95,10 +97,10 @@ public static <U, I> void saveDataModel(final TemporalDataModelIF<U, I> dm, fina
time = userTimeModel.get(item);
}
if (time == null) {
out.println(user + "\t" + item + "\t" + pref + "\t-1");
out.println(user + delimiter + item + delimiter + pref + delimiter + "-1");
} else {
for (Long t : time) {
out.println(user + "\t" + item + "\t" + pref + "\t" + t);
out.println(user + delimiter + item + delimiter + pref + delimiter + t);
}
}
}
Expand Down

0 comments on commit e9f996f

Please sign in to comment.