├── .classpath
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── LICENSE
├── README.md
├── lib
├── Jama-1.0.3.jar
├── commons-io-2.3.jar
├── commons-lang3-3.1.jar
├── commons-logging-1.2.jar
├── guava-14.0-rc1.jar
├── httpclient-4.3.1.jar
├── httpcore-4.3.jar
├── httpmime-4.3.1.jar
├── javaml-0.1.5.jar
├── json-simple-1.1.1.jar
├── mallet-deps.jar
├── mallet.jar
├── mysql-connector-java-5.1.36-bin.jar
├── noggit-0.5.jar
├── opencsv-2.3.jar
├── slf4j-api-1.7.6.jar
├── solr-solrj-4.10.1.jar
├── vecmath-1.5.1.jar
├── wstx-asl-3.2.7.jar
└── zookeeper-3.4.6.jar
└── src
├── common
├── Bookmark.java
├── CalculationType.java
├── CooccurenceMatrix.java
├── DBManager.java
├── DoubleMapComparator.java
├── DoubleMapComparatorGeneric.java
├── DoubleMapComparatorKeyString.java
├── Features.java
├── IntMapComparator.java
├── MapUtil.java
├── MemoryThread.java
├── MergeUtil.java
├── PearsonSimilarityCalculator.java
├── PerformanceMeasurement.java
├── PredictionData.java
├── Similarity.java
├── SolrConnector.java
├── TimeUtil.java
└── Utilities.java
├── engine
├── Algorithm.java
├── BaseLevelLearningCollectiveEngine.java
├── BaseLevelLearningEngine.java
├── EngineInterface.java
├── EngineUtils.java
├── EntityRecommenderEngine.java
├── EntityType.java
├── LanguageModelEngine.java
├── MostPopularCollectiveEngine.java
├── ResourceRecommenderEngine.java
├── TagRecommenderEvalEngine.java
├── ThreeLayersCollectiveEngine.java
├── ThreeLayersEngine.java
└── UserRecommenderEngine.java
├── file
├── BookmarkReader.java
├── BookmarkSplitter.java
├── BookmarkWriter.java
├── PredictionFileReader.java
├── PredictionFileWriter.java
├── ResultSerializer.java
├── postprocessing
│ └── CatDescFiltering.java
├── preprocessing
│ ├── BibBookmark.java
│ ├── BibsonomyProcessor.java
│ ├── CiteULikeProcessor.java
│ ├── CoreFiltering.java
│ ├── JKULFMProcessor.java
│ ├── JSONProcessor.java
│ ├── LastFMProcessor.java
│ ├── MovielensProcessor.java
│ ├── PintsProcessor.java
│ └── TensorProcessor.java
└── stemming
│ ├── Among.java
│ ├── EnglishStemmer.java
│ ├── SnowballProgram.java
│ └── SnowballStemmer.java
├── itemrecommendations
├── CFResourceCalculator.java
├── CIRTTCalculator.java
├── HuangApproach.java
├── HuangCalculator.java
├── MPResourceCalculator.java
├── SustainCalculator.java
├── ZhengApproach.java
└── ZhengCalculator.java
├── processing
├── BLLCalculator.java
├── CFTagRecommender.java
├── ContentBasedCalculator.java
├── FolkRankCalculator.java
├── GIRPTMCalculator.java
├── MPCalculator.java
├── MPurCalculator.java
├── MalletCalculator.java
├── MetricsCalculator.java
├── RecencyCalculator.java
├── ThreeLTCalculator.java
├── analyzing
│ ├── ReuseProbValue.java
│ ├── TagReuseProbAnalyzer.java
│ ├── UserTagDistribution.java
│ └── UserTagProperties.java
├── folkrank
│ ├── APRFolkRankResult.java
│ ├── FactPreprocessor.java
│ ├── FactReader.java
│ ├── FactReaderFactPreprocessor.java
│ ├── FactReadingException.java
│ ├── FolkRankAlgorithm.java
│ ├── FolkRankData.java
│ ├── FolkRankParam.java
│ ├── FolkRankPref.java
│ ├── FolkRankResult.java
│ ├── ItemWithWeight.java
│ ├── LeavePostOutFolkRankDataDuplicator.java
│ ├── SeparatedWeightInitializationStrategy.java
│ ├── StandardFolkRankResult.java
│ ├── WeightInitializationStrategy.java
│ └── WikipediaFactReader.java
├── hashtag
│ ├── HashtagRecommendationEngine.java
│ ├── TagRecommendationUtil.java
│ ├── analysis
│ │ ├── ProcessFrequencyRecency.java
│ │ └── ProcessFrequencyRecencySocial.java
│ ├── baseline
│ │ ├── ContentPersonalTemporalCalculator.java
│ │ ├── CosineSimilarityCalculator.java
│ │ ├── HashtagEntropyCalculator.java
│ │ ├── HashtagEntropyCalculatorTest.java
│ │ ├── HashtagUtil.java
│ │ ├── MalletCalculatorTweet.java
│ │ ├── PersonalisedSimilarityCalculator.java
│ │ ├── PersonalisedSimilarityCalculatorTest.java
│ │ ├── PersonalisedTFIDFCalculator.java
│ │ ├── UserTFIDFVectorCalculator.java
│ │ ├── Vector.java
│ │ ├── VectorUtil.java
│ │ └── VectorUtilTest.java
│ ├── social
│ │ ├── RelationItem.java
│ │ ├── SocialBLLCalculator.java
│ │ ├── SocialFrequencyCalculator.java
│ │ ├── SocialHybridCalculator.java
│ │ ├── SocialInitEngine.java
│ │ ├── SocialLinkWeightCalculator.java
│ │ ├── SocialRecencyRecommender.java
│ │ └── SocialStrengthCalculator.java
│ └── solr
│ │ ├── CFSolrHashtagCalculator.java
│ │ ├── SolrHashtagCalculator.java
│ │ └── Tweet.java
└── musicrec
│ ├── ArtistCFRecommender.java
│ ├── BLL_CFRecommender.java
│ └── MusicCFRecommender.java
├── test
└── Pipeline.java
└── userrecommender
├── SpearAlgorithm.java
├── SpearAlgorithmResult.java
├── SpearCalculator.java
├── TestSpearCalculator.java
└── UserActivity.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # idea intellij
2 | .idea
3 | *.iml
4 | /bin/
5 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | TagRecommender
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.8
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.8
13 |
--------------------------------------------------------------------------------
/lib/Jama-1.0.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/Jama-1.0.3.jar
--------------------------------------------------------------------------------
/lib/commons-io-2.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/commons-io-2.3.jar
--------------------------------------------------------------------------------
/lib/commons-lang3-3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/commons-lang3-3.1.jar
--------------------------------------------------------------------------------
/lib/commons-logging-1.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/commons-logging-1.2.jar
--------------------------------------------------------------------------------
/lib/guava-14.0-rc1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/guava-14.0-rc1.jar
--------------------------------------------------------------------------------
/lib/httpclient-4.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/httpclient-4.3.1.jar
--------------------------------------------------------------------------------
/lib/httpcore-4.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/httpcore-4.3.jar
--------------------------------------------------------------------------------
/lib/httpmime-4.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/httpmime-4.3.1.jar
--------------------------------------------------------------------------------
/lib/javaml-0.1.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/javaml-0.1.5.jar
--------------------------------------------------------------------------------
/lib/json-simple-1.1.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/json-simple-1.1.1.jar
--------------------------------------------------------------------------------
/lib/mallet-deps.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/mallet-deps.jar
--------------------------------------------------------------------------------
/lib/mallet.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/mallet.jar
--------------------------------------------------------------------------------
/lib/mysql-connector-java-5.1.36-bin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/mysql-connector-java-5.1.36-bin.jar
--------------------------------------------------------------------------------
/lib/noggit-0.5.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/noggit-0.5.jar
--------------------------------------------------------------------------------
/lib/opencsv-2.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/opencsv-2.3.jar
--------------------------------------------------------------------------------
/lib/slf4j-api-1.7.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/slf4j-api-1.7.6.jar
--------------------------------------------------------------------------------
/lib/solr-solrj-4.10.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/solr-solrj-4.10.1.jar
--------------------------------------------------------------------------------
/lib/vecmath-1.5.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/vecmath-1.5.1.jar
--------------------------------------------------------------------------------
/lib/wstx-asl-3.2.7.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/wstx-asl-3.2.7.jar
--------------------------------------------------------------------------------
/lib/zookeeper-3.4.6.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/learning-layers/TagRec/811793ff097b936d9e6f8fa31cba604281926690/lib/zookeeper-3.4.6.jar
--------------------------------------------------------------------------------
/src/common/CalculationType.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | public enum CalculationType {
24 | NONE, // BLL
25 | USER_TO_RESOURCE, // BLLac
26 | USER_TO_RESOURCE_ONLY, // AC
27 | RESOURCE_TO_USER,
28 | RESOURCE_TO_USER_ONLY,
29 | BOTH,
30 | MUSIC
31 | }
--------------------------------------------------------------------------------
/src/common/DBManager.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import java.sql.Statement;
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | import file.preprocessing.BibBookmark;
12 |
13 | public class DBManager {
14 | private String dbName;
15 | private Connection connect = null;
16 | private Statement statement = null;
17 | private ResultSet resultSet = null;
18 |
19 | public DBManager(String dbname) {
20 | try {
21 | Class.forName("com.mysql.jdbc.Driver");
22 | // Setup the connection with the DB
23 | dbName = dbname;
24 | connect = DriverManager.getConnection("jdbc:mysql://localhost/"
25 | + dbname + "?user=root");
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | }
30 |
31 | public List getBibBookmarks(String tableName, String idFieldName, String urlFieldName) {
32 | List bookmarks = new ArrayList();
33 |
34 | try {
35 | statement = connect.createStatement();
36 | resultSet = statement.executeQuery("select * from " + dbName + "." + tableName);
37 | while (resultSet.next()) {
38 | BibBookmark b = new BibBookmark();
39 | b.id = resultSet.getString(idFieldName);
40 | b.urlHash = resultSet.getString(urlFieldName);
41 | bookmarks.add(b);
42 | }
43 | } catch (SQLException e) {
44 | e.printStackTrace();
45 | }
46 |
47 | return bookmarks;
48 | }
49 |
50 | public void close() {
51 | try {
52 | if (resultSet != null) {
53 | resultSet.close();
54 | }
55 | if (statement != null) {
56 | statement.close();
57 | }
58 | if (connect != null) {
59 | connect.close();
60 | }
61 | } catch (Exception e) {
62 |
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/common/DoubleMapComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | import java.util.Comparator;
24 | import java.util.Map;
25 |
26 | public class DoubleMapComparator implements Comparator {
27 |
28 | private Map map;
29 |
30 | public DoubleMapComparator(Map map) {
31 | this.map = map;
32 | }
33 |
34 | @Override
35 | public int compare(Integer key1, Integer key2) {
36 | Double val1 = this.map.get(key1);
37 | Double val2 = this.map.get(key2);
38 | if (val1 != null && val2 != null) {
39 | return (val1 >= val2 ? - 1 : 1);
40 | }
41 | return 0;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/common/DoubleMapComparatorGeneric.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.util.Comparator;
4 | import java.util.Map;
5 |
6 | public class DoubleMapComparatorGeneric implements Comparator {
7 | private Map map;
8 |
9 | public DoubleMapComparatorGeneric(Map map) {
10 | this.map = map;
11 | }
12 |
13 | @Override
14 | public int compare(T key1, T key2) {
15 | Double val1 = this.map.get(key1);
16 | Double val2 = this.map.get(key2);
17 | if (val1 != null && val2 != null) {
18 | return (val1 >= val2 ? - 1 : 1);
19 | }
20 | return 0;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/common/DoubleMapComparatorKeyString.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | import java.util.Comparator;
24 | import java.util.HashMap;
25 | import java.util.Map;
26 |
27 | public class DoubleMapComparatorKeyString implements Comparator {
28 |
29 | private Map map;
30 |
31 | public DoubleMapComparatorKeyString(Map map) {
32 | this.map = map;
33 | }
34 |
35 | @Override
36 | public int compare(String key1, String key2) {
37 | Double val1 = this.map.get(key1);
38 | Double val2 = this.map.get(key2);
39 | if (val1 != null && val2 != null) {
40 | return (val1 >= val2 ? - 1 : 1);
41 | }
42 | return 0;
43 | }
44 | }
--------------------------------------------------------------------------------
/src/common/Features.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | public enum Features {
24 |
25 | TAGS,
26 | TOPICS,
27 | ENTITIES,
28 | // Zheng
29 | TAG_ENTITIES,
30 | TIME_ENTITIES,
31 | TAG_TIME_ENTITIES
32 | }
33 |
--------------------------------------------------------------------------------
/src/common/IntMapComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 | package common;
21 |
22 | import java.util.Comparator;
23 | import java.util.Map;
24 |
25 | public class IntMapComparator implements Comparator {
26 |
27 | private Map map;
28 |
29 | public IntMapComparator(Map map) {
30 | this.map = map;
31 | }
32 |
33 | @Override
34 | public int compare(Integer key1, Integer key2) {
35 | Integer val1 = this.map.get(key1);
36 | Integer val2 = this.map.get(key2);
37 | if (val1 != null && val2 != null) {
38 | return (val1 >= val2 ? - 1 : 1);
39 | }
40 | return 0;
41 | }
42 | }
--------------------------------------------------------------------------------
/src/common/MapUtil.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.util.*;
4 |
5 | public class MapUtil
6 | {
7 | public static > Map sortByValue( Map map )
8 | {
9 | List> list =
10 | new LinkedList>( map.entrySet() );
11 | Collections.sort( list, new Comparator>()
12 | {
13 | public int compare( Map.Entry o1, Map.Entry o2 )
14 | {
15 | return -(o1.getValue()).compareTo( o2.getValue() );
16 | }
17 | } );
18 |
19 | Map result = new LinkedHashMap();
20 | for (Map.Entry entry : list)
21 | {
22 | result.put( entry.getKey(), entry.getValue() );
23 | }
24 | return result;
25 | }
26 |
27 | public static void normalizeMap(Map map) {
28 | double denom = 0.0;
29 | for (Map.Entry e : map.entrySet()) {
30 | denom += Math.exp(e.getValue());
31 | }
32 | for (Map.Entry e : map.entrySet()) {
33 | e.setValue(Math.exp(e.getValue()) / denom);
34 | }
35 | }
36 |
37 | public static void normalizeMap(Map map, double beta) {
38 | double denom = 0.0;
39 | for (Map.Entry e : map.entrySet()) {
40 | denom += Math.exp(e.getValue());
41 | denom += e.getValue();
42 | }
43 | for (Map.Entry e : map.entrySet()) {
44 | e.setValue(Math.exp(e.getValue()) / denom * beta);
45 | e.setValue(e.getValue() / denom * beta);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/common/MemoryThread.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.util.TimerTask;
4 |
5 | public class MemoryThread extends TimerTask {
6 |
7 | public final static int TIME_SPAN = 5000;
8 |
9 | private long maxMemory = -1;
10 |
11 | public MemoryThread() {
12 | Runtime.getRuntime().gc();
13 | }
14 |
15 | private void trackMaxMemory() {
16 | // Get the Java runtime
17 | Runtime runtime = Runtime.getRuntime();
18 | // Run the garbage collector
19 | //runtime.gc();
20 | // Calculate the used memory
21 | long memory = runtime.totalMemory() - runtime.freeMemory();
22 | if (memory > this.maxMemory) {
23 | this.maxMemory = memory;
24 | }
25 | }
26 |
27 | public void run() {
28 | trackMaxMemory();
29 | }
30 |
31 | public long getMaxMemory() {
32 | trackMaxMemory();
33 | return this.maxMemory;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/common/MergeUtil.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 | import java.util.TreeMap;
6 |
7 | public class MergeUtil {
8 |
9 | public static Map mergeMapsWithThreshold(Map srcMap, Map targetMap, int limit) {
10 | Map resultMap = new LinkedHashMap();
11 | Map sortedTargetMap = MapUtil.sortByValue(targetMap);
12 | double threshold = 0.0;
13 | for (Map.Entry entry : sortedTargetMap.entrySet()) {
14 | threshold = entry.getValue();
15 | break;
16 | }
17 | System.out.println(threshold);
18 |
19 | for (Map.Entry srcEntry : srcMap.entrySet()) {
20 | if (srcEntry.getValue() >= threshold) {
21 | resultMap.put(srcEntry.getKey(), srcEntry.getValue());
22 | } else {
23 | break;
24 | }
25 | }
26 | for (Map.Entry targetEntry: sortedTargetMap.entrySet()) {
27 | if (resultMap.size() < limit) {
28 | if (!resultMap.containsKey(targetEntry.getKey())) {
29 | resultMap.put(targetEntry.getKey(), targetEntry.getValue());
30 | }
31 | } else {
32 | break;
33 | }
34 | }
35 |
36 | return resultMap;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/common/PearsonSimilarityCalculator.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | import java.util.ArrayList;
24 | import java.util.HashMap;
25 | import java.util.List;
26 | import java.util.Map;
27 |
28 | /**
29 | * Calculator for the Pearson similarity between two user ratings
30 | * @author elacic
31 | *
32 | */
33 | public class PearsonSimilarityCalculator {
34 |
35 | /**
36 | * Calculates the Pearson-similarity based on the resource ratings of a user and the resource ratings of his neighbor
37 | * @param userRatings resource ratings of the user
38 | * @param neighborRatings resource ratings of the user's neighbor
39 | * @return the Pearson similarity
40 | */
41 | public static double getPearsonSim(List userRatings, List neighborRatings) {
42 | double differenceSum = 0.0;
43 | double userSquareDifferenceSum = 0.0;
44 | double neighboorSquareDifferenceSum = 0.0;
45 |
46 | Map> coratedItems = new HashMap>();
47 |
48 | double userRatingAverage = calculateAverageAndFillCoratedItems(userRatings, coratedItems);
49 | double neighboorRatingAverage = calculateAverageAndFillCoratedItems(neighborRatings, coratedItems);
50 |
51 | for (Integer resourceId : coratedItems.keySet()) {
52 | List resourceRatings = coratedItems.get(resourceId);
53 |
54 | if (resourceRatings.size() < 2) {
55 | continue;
56 | }
57 |
58 | Double userResourceRating = resourceRatings.get(0);
59 | Double neighboorResourceRating = resourceRatings.get(1);
60 |
61 | differenceSum += (userResourceRating - userRatingAverage) * (neighboorResourceRating - neighboorRatingAverage);
62 |
63 | userSquareDifferenceSum += Math.pow( (userResourceRating - userRatingAverage) , 2);
64 | neighboorSquareDifferenceSum += Math.pow( (neighboorResourceRating - neighboorRatingAverage) , 2);
65 | }
66 |
67 | return differenceSum / (Math.sqrt(userSquareDifferenceSum) * Math.sqrt(neighboorSquareDifferenceSum));
68 | }
69 |
70 | /**
71 | * Calculates the average of a user's ratings and fills the coratedItems map
72 | * @param userRatings
73 | * @param coratedItems
74 | * @return
75 | */
76 | private static double calculateAverageAndFillCoratedItems(List userRatings, Map> coratedItems) {
77 | double ratingSum = 0.0;
78 | for (Bookmark userRating : userRatings) {
79 | double filteredRating = filterRating(userRating.getRating());
80 | ratingSum += filteredRating;
81 |
82 | fillCoratedItems(coratedItems, userRating.getResourceID(), filteredRating);
83 | }
84 | return ratingSum / userRatings.size();
85 | }
86 |
87 | /**
88 | * Fills the mapping on the rating for a resource
89 | * @param coratedItems mapping for resource rating which will be filled
90 | * @param resource resource that is rated
91 | * @param filteredRating rating for the resource
92 | */
93 | private static void fillCoratedItems(Map> coratedItems, Integer resource, double filteredRating) {
94 | List resourceRating = null;
95 |
96 | if (coratedItems.containsKey(resource)) {
97 | resourceRating = coratedItems.get(resource);
98 | } else {
99 | resourceRating = new ArrayList();
100 | }
101 |
102 | resourceRating.add(filteredRating);
103 | coratedItems.put(resource, resourceRating);
104 | }
105 |
106 | /**
107 | * For read only ratings which were set to -1 by convention in the CUL dataset
108 | * @param rating rating to be filtered
109 | * @return filtered rating
110 | */
111 | private static double filterRating(double rating) {
112 | if (rating == -1) {
113 | return 3;
114 | }
115 |
116 | return rating;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/common/PerformanceMeasurement.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | public class PerformanceMeasurement {
4 |
5 | private static final long MEGABYTE = 1024L * 1024L;
6 |
7 | public static String addTimeMeasurement(String performance, boolean clearString, long trainingTime, long testTime, int sampleSize) {
8 | if (clearString) {
9 | performance = "";
10 | }
11 | performance += ("Full training time: " + trainingTime + "\n");
12 | performance += ("Full test time: " + testTime + "\n");
13 | performance += ("Average test time: " + (testTime / (double)sampleSize)) + "\n";
14 | performance += ("Total time: " + (trainingTime + testTime) + "\n");
15 | return performance;
16 | }
17 |
18 | public static String addMemoryMeasurement(String performance, boolean clearString, long memory) {
19 | if (clearString) {
20 | performance = "";
21 | }
22 | performance += ("Memory in bytes: " + memory + "\n");
23 | performance += ("Memory in mBytes: " + bytesToMegabytes(memory) + "\n");
24 | return performance;
25 | }
26 |
27 | public static String addCurrentMemoryMeasurement(String performance, boolean clearString, boolean gc) {
28 | if (clearString) {
29 | performance = "";
30 | }
31 | // Get the Java runtime
32 | Runtime runtime = Runtime.getRuntime();
33 | if (gc) {
34 | // Run the garbage collector
35 | runtime.gc();
36 | }
37 | // Calculate the used memory
38 | long memory = runtime.totalMemory() - runtime.freeMemory();
39 | performance += ("Memory in bytes: " + memory + "\n");
40 | performance += ("Memory in mBytes: " + bytesToMegabytes(memory) + "\n");
41 | return performance;
42 | }
43 |
44 | private static long bytesToMegabytes(long bytes) {
45 | return bytes / MEGABYTE;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/common/Similarity.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package common;
22 |
23 | public enum Similarity {
24 |
25 | JACCARD,
26 | COSINE,
27 | BM25
28 | }
29 |
--------------------------------------------------------------------------------
/src/common/TimeUtil.java:
--------------------------------------------------------------------------------
1 | package common;
2 |
3 | public class TimeUtil {
4 |
5 | public static final int SECOND = 0;
6 | public static final int MINUTE = 1;
7 | public static final int HOUR = 2;
8 | public static final int DAY = 3;
9 | public static final int FIFTEEN_DAYS = 4;
10 | public static final int MONTH = 5;
11 | public static final int WEEK = 6;
12 |
13 | /**
14 | * get duration count for the dataset.
15 | * @param duration
16 | * @param granularityLevel
17 | * @return
18 | */
19 | public static int getDurationAtGranularity(int duration, int granularityLevel){
20 | int time_count = 0;
21 | int secondsInSeconds = 1;
22 | int secondsInMinute = 60;
23 | int secondsInHour = 60 * 60;
24 | int secondsInDay = 24 * 60 * 60;
25 | int secondsInWeek = 7 * 24 * 60 * 60;
26 | int secondsInFifteenDays = 15 * 24 * 60 * 60;
27 | int secondsInMonth = 30 * 24 * 60 * 60;
28 | switch(granularityLevel){
29 | case SECOND:
30 | time_count = duration / secondsInSeconds;
31 | break;
32 | case MINUTE:
33 | time_count = duration / secondsInMinute;
34 | break;
35 | case HOUR:
36 | time_count = duration / secondsInHour;
37 | break;
38 | case DAY:
39 | time_count = duration / secondsInDay;
40 | break;
41 | case FIFTEEN_DAYS:
42 | time_count = duration / secondsInFifteenDays;
43 | break;
44 | case MONTH:
45 | time_count = duration / secondsInMonth;
46 | break;
47 | case WEEK:
48 | time_count = duration / secondsInWeek;
49 | break;
50 | }
51 | return time_count;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/engine/Algorithm.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | public enum Algorithm {
4 | MP,
5 | BLL,
6 | BLLac,
7 | BLLacMPr,
8 | BLLcoll,
9 | MPu,
10 | MPr,
11 | MPur,
12 | THREEL,
13 | THREELT,
14 | THREELTMPr,
15 | THREELcoll,
16 |
17 | RESOURCEMP,
18 | RESOURCECF,
19 | RESOURCETAGCF,
20 | RESOURCETAGCB,
21 |
22 | USERMP,
23 | USERCF,
24 | USERTAGCF,
25 | USERTAGCB
26 | }
27 |
--------------------------------------------------------------------------------
/src/engine/BaseLevelLearningCollectiveEngine.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import processing.BLLCalculator;
9 | import file.BookmarkReader;
10 |
11 | public class BaseLevelLearningCollectiveEngine implements EngineInterface {
12 |
13 | private BookmarkReader reader = null;
14 | private final Map collectiveTags = new LinkedHashMap();
15 |
16 | public void loadFile(String path, String filename) throws Exception {
17 | BookmarkReader reader = EngineUtils.getSortedBookmarkReader(path, filename);
18 | Map collectiveTags = BLLCalculator.getCollectiveArtifactMap(reader, reader.getBookmarks(), null, false, new ArrayList(), new ArrayList(), 0.5, true);
19 |
20 | // map to strings
21 | Map collectiveTagNames = new LinkedHashMap();
22 | for (Map.Entry tag : collectiveTags.entrySet()) {
23 | collectiveTagNames.put(reader.getTags().get(tag.getKey()), tag.getValue());
24 | }
25 |
26 | resetStructures(reader, collectiveTagNames);
27 | }
28 |
29 | @Override
30 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
31 | if (count == null || count.doubleValue() < 1) {
32 | count = 10;
33 | }
34 | Map tagMap = new LinkedHashMap();
35 | if (algorithm == null || algorithm == Algorithm.BLLcoll) {
36 | tagMap = this.collectiveTags;
37 | } else {
38 | int userID = this.reader.getUsers().indexOf(user);
39 | if (user != null && userID != -1) {
40 | Map userTags = BLLCalculator.getSortedArtifactMapForUser(userID, this.reader, this.reader.getBookmarks(), null, false, new ArrayList(), new ArrayList(), 0.5, true);
41 | for (Map.Entry tag : userTags.entrySet()) {
42 | tagMap.put(this.reader.getTags().get(tag.getKey()), tag.getValue());
43 | }
44 | }
45 | }
46 |
47 | Map returnMap = new LinkedHashMap();
48 | for (Map.Entry entry : tagMap.entrySet()) {
49 | if (returnMap.size() < count.intValue()) {
50 | returnMap.put(entry.getKey(), entry.getValue());
51 | } else {
52 | break;
53 | }
54 | }
55 | return returnMap;
56 | }
57 |
58 | private synchronized void resetStructures(BookmarkReader reader, Map collectiveTags) {
59 | this.reader = reader;
60 | this.collectiveTags.clear();
61 | this.collectiveTags.putAll(collectiveTags);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/engine/EngineInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package engine;
22 |
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | public interface EngineInterface {
27 |
28 | public void loadFile(String path, String filename) throws Exception;
29 |
30 | public Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type);
31 | }
32 |
--------------------------------------------------------------------------------
/src/engine/EngineUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package engine;
22 |
23 | import java.io.File;
24 | import java.nio.file.Files;
25 | import java.util.ArrayList;
26 | import java.util.Collections;
27 | import java.util.LinkedHashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 | import java.util.TreeMap;
31 |
32 | import common.Bookmark;
33 | import common.IntMapComparator;
34 | import file.BookmarkReader;
35 | import file.BookmarkSplitter;
36 | import file.BookmarkWriter;
37 |
38 | public class EngineUtils {
39 |
40 | public static BookmarkReader getSortedBookmarkReader(String path, String filename) {
41 | BookmarkReader reader = new BookmarkReader(0, false);
42 | reader.readFile(path, filename);
43 |
44 | Collections.sort(reader.getBookmarks());
45 |
46 | String sortedFile = filename + "_sorted";
47 | BookmarkWriter.writeSample(reader, reader.getBookmarks(), path, sortedFile, null, true);
48 | reader = new BookmarkReader(0, false);
49 | reader.readFile(path, sortedFile);
50 |
51 | try {
52 | String deletePath = "";
53 | if (path == null) {
54 | deletePath = "./data/csv/" + sortedFile + ".txt";
55 | } else {
56 | deletePath = path + sortedFile;
57 | }
58 | if (!new File(deletePath).delete()) {
59 | System.out.println("Problem while deleting sorted temp-file");
60 | }
61 | } catch (Exception e) {
62 | System.out.println("Problem while deleting sorted temp-file");
63 | }
64 |
65 | return reader;
66 | }
67 |
68 | public static List getFilterTags(boolean filterOwnEntities, BookmarkReader reader, String user, String resource) {
69 | List filterTags = new ArrayList();
70 | if (filterOwnEntities && user != null) {
71 | if (resource != null) {
72 | int userID = -1;
73 | if (user != null) {
74 | userID = reader.getUsers().indexOf(user);
75 | }
76 | int resID = -1;
77 | if (resource != null) {
78 | resID = reader.getResources().indexOf(resource);
79 | }
80 | filterTags = Bookmark.getTagsOfBookmark(reader.getBookmarks(), userID, resID);
81 | }/* else {
82 | if (userMap != null) {
83 | filterTags = new ArrayList(userMap.keySet());
84 | }
85 | }*/
86 | }
87 |
88 | return filterTags;
89 | }
90 |
91 | public static Map calcTopEntities(BookmarkReader reader, EntityType type) {
92 | Map map = new LinkedHashMap<>();
93 | Map countMap = new LinkedHashMap();
94 | List entityCounts = null;
95 | if (type == EntityType.TAG) {
96 | entityCounts = reader.getTagCounts();
97 | } else if (type == EntityType.RESOURCE) {
98 | entityCounts = reader.getResourceCounts();
99 | } else {
100 | entityCounts = reader.getUserCounts();
101 | }
102 |
103 | Integer countSum = 0;
104 | for (int i = 0; i < entityCounts.size(); i++) {
105 | countMap.put(i, entityCounts.get(i));
106 | countSum += entityCounts.get(i);
107 | }
108 |
109 | Map sortedCountMap = new TreeMap(new IntMapComparator(countMap));
110 | sortedCountMap.putAll(countMap);
111 | for (Map.Entry entry : sortedCountMap.entrySet()) {
112 | map.put(entry.getKey(), ((double) entry.getValue()) / countSum);
113 | }
114 | return map;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/engine/EntityRecommenderEngine.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | // TODO: check for duplicates (user-resource combinations)!
7 | public class EntityRecommenderEngine implements EngineInterface {
8 |
9 | private EngineInterface tagRecommender;
10 | private EngineInterface resourceRecommender;
11 | private EngineInterface userRecommender;
12 |
13 | public void loadFile(String path, String filename) throws Exception {
14 | this.tagRecommender = new TagRecommenderEvalEngine();
15 | this.tagRecommender.loadFile(path, filename);
16 | this.resourceRecommender = new ResourceRecommenderEngine();
17 | this.resourceRecommender.loadFile(path, filename);
18 | this.userRecommender = new UserRecommenderEngine();
19 | this.userRecommender.loadFile(path, filename);
20 | }
21 |
22 | public Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
23 | if (type == EntityType.TAG) {
24 | return tagRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
25 | } else if (type == EntityType.RESOURCE) {
26 | return resourceRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
27 | } else if (type == EntityType.USER) {
28 | return userRecommender.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
29 | }
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/engine/EntityType.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | public enum EntityType {
4 | TAG,
5 | RESOURCE,
6 | USER
7 | }
--------------------------------------------------------------------------------
/src/engine/MostPopularCollectiveEngine.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import file.BookmarkReader;
9 |
10 | public class MostPopularCollectiveEngine implements EngineInterface {
11 |
12 | private BookmarkReader reader;
13 | private final Map collectiveTags = new LinkedHashMap();
14 |
15 | public void loadFile(String path, String filename) throws Exception {
16 | BookmarkReader reader = EngineUtils.getSortedBookmarkReader(path, filename);
17 | Map collectiveTags = EngineUtils.calcTopEntities(reader, EntityType.TAG);
18 |
19 | // map to strings
20 | Map collectiveTagNames = new LinkedHashMap();
21 | for (Map.Entry tag : collectiveTags.entrySet()) {
22 | collectiveTagNames.put(reader.getTags().get(tag.getKey()), tag.getValue());
23 | }
24 |
25 | resetStructures(reader, collectiveTagNames);
26 | }
27 |
28 | @Override
29 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
30 | if (count == null || count.doubleValue() < 1) {
31 | count = 10;
32 | }
33 | List filterTags = EngineUtils.getFilterTags(filterOwnEntities, this.reader, user, resource);
34 |
35 | Map returnMap = new LinkedHashMap();
36 | for (Map.Entry entry : collectiveTags.entrySet()) {
37 | if (returnMap.size() < count.intValue()) {
38 | if (!filterTags.contains(entry.getKey())) {
39 | returnMap.put(entry.getKey(), entry.getValue());
40 | }
41 | } else {
42 | break;
43 | }
44 | }
45 | return returnMap;
46 | }
47 |
48 | private synchronized void resetStructures(BookmarkReader reader, Map collectiveTags) {
49 | this.reader = reader;
50 | this.collectiveTags.clear();
51 | this.collectiveTags.putAll(collectiveTags);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/engine/TagRecommenderEvalEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package engine;
22 |
23 | import java.io.BufferedWriter;
24 | import java.io.File;
25 | import java.io.FileWriter;
26 | import java.io.IOException;
27 | import java.util.List;
28 | import java.util.Map;
29 |
30 | import file.BookmarkReader;
31 |
32 | public class TagRecommenderEvalEngine implements EngineInterface {
33 |
34 | private EngineInterface lmEngine;
35 | private EngineInterface bllEngine;
36 | private EngineInterface threelEngine;
37 | private EngineInterface mpEngine;
38 |
39 | //private Random random;
40 | private BufferedWriter bw;
41 |
42 | public TagRecommenderEvalEngine() {
43 | this.lmEngine = null;
44 | this.bllEngine = null;
45 | this.threelEngine = null;
46 | this.mpEngine = null;
47 |
48 | //this.random = new Random();
49 | this.bw = null;
50 | }
51 |
52 | @Override
53 | public void loadFile(String path, String filename) throws Exception {
54 | this.lmEngine = new LanguageModelEngine();
55 | this.lmEngine.loadFile(path, filename);
56 | this.bllEngine = new BaseLevelLearningEngine();
57 | this.bllEngine.loadFile(path, filename);
58 | this.threelEngine = new ThreeLayersCollectiveEngine();
59 | this.threelEngine.loadFile(path, filename);
60 | this.mpEngine = new MostPopularCollectiveEngine();
61 | this.mpEngine.loadFile(path, filename);
62 |
63 | try {
64 | String logFile = "";
65 | if (path == null) {
66 | logFile = "./data/tagrec_log.txt";
67 | } else {
68 | logFile = path + "tagrec_log.txt";
69 | }
70 | FileWriter writer = new FileWriter(new File(logFile), true);
71 | this.bw = new BufferedWriter(writer);
72 | } catch (Exception e) {
73 | e.printStackTrace();
74 | }
75 | }
76 |
77 | @Override
78 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
79 | Map returnMap = null;
80 | String algorithmString = null;
81 |
82 | if (algorithm == Algorithm.BLLacMPr) {
83 | if (this.bllEngine != null) {
84 | algorithmString = Algorithm.BLLacMPr.name();
85 | returnMap = this.bllEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
86 | }
87 | } else if (algorithm == Algorithm.MPur) {
88 | if (this.lmEngine != null) {
89 | algorithmString = Algorithm.MPur.name();
90 | returnMap = this.lmEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
91 | }
92 | } else if (algorithm == Algorithm.THREELcoll) {
93 | if (topics != null && topics.size() > 0) {
94 | if (this.threelEngine != null) {
95 | algorithmString = Algorithm.THREELcoll.name();
96 | returnMap = this.threelEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
97 | }
98 | } else {
99 | if (this.mpEngine != null) {
100 | algorithmString = Algorithm.THREELcoll.name();
101 | returnMap = this.mpEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
102 | }
103 | }
104 | } else {
105 | if (this.mpEngine != null) {
106 | algorithmString = Algorithm.MP.name();
107 | returnMap = this.mpEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
108 | }
109 | }
110 |
111 | /* KnowBrain study
112 | if (algorithm == null || algorithm == Algorithm.THREELcoll || algorithm == Algorithm.THREEL) {
113 | if (this.threelEngine != null) {
114 | returnMap = this.threelEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
115 | if (algorithm == Algorithm.THREEL) {
116 | algorithmString = "3L";
117 | } else {
118 | algorithmString = "3Lcoll";
119 | }
120 | }
121 | } else if (algorithm == Algorithm.BLLcoll || algorithm == Algorithm.BLL) {
122 | if (this.bllEngine != null) {
123 | returnMap = this.bllEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
124 | if (algorithm == Algorithm.BLL) {
125 | algorithmString = "BLL";
126 | } else {
127 | algorithmString = "BLLcoll";
128 | }
129 | }
130 | } else {
131 | if (this.mpEngine != null) {
132 | returnMap = this.mpEngine.getEntitiesWithLikelihood(user, resource, topics, count, filterOwnEntities, algorithm, type);
133 | algorithmString = "MP";
134 | }
135 | }
136 | */
137 |
138 | if (this.bw != null) {
139 | try {
140 | this.bw.write(user + "|" + resource + "|" + topics + "|" + count + "|" + filterOwnEntities + "|" + System.currentTimeMillis() + "|" + algorithmString + "|" + returnMap.keySet() + "\n");
141 | this.bw.flush();
142 | } catch (IOException e) {
143 | e.printStackTrace();
144 | }
145 | }
146 | return returnMap;
147 | }
148 |
149 | public static boolean getRandomBoolean() {
150 | return Math.random() < 0.5;
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/engine/ThreeLayersCollectiveEngine.java:
--------------------------------------------------------------------------------
1 | package engine;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import common.CalculationType;
9 | import processing.BLLCalculator;
10 | import processing.ThreeLTCalculator;
11 | import file.BookmarkReader;
12 |
13 | public class ThreeLayersCollectiveEngine implements EngineInterface {
14 |
15 | private BookmarkReader reader = null;
16 | private ThreeLTCalculator calculator = null;
17 |
18 | public void loadFile(String path, String filename) throws Exception {
19 | BookmarkReader reader = EngineUtils.getSortedBookmarkReader(path, filename);
20 | ThreeLTCalculator calculator = new ThreeLTCalculator(reader, reader.getBookmarks().size(), 5, 5, true, false, false, CalculationType.NONE);
21 |
22 | resetStructures(reader, calculator);
23 | }
24 |
25 | @Override
26 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
27 | if (count == null || count.doubleValue() < 1) {
28 | count = 10;
29 | }
30 | if (filterOwnEntities == null) {
31 | filterOwnEntities = true;
32 | }
33 | List filterTags = EngineUtils.getFilterTags(filterOwnEntities, this.reader, user, resource);
34 |
35 | List topicIDs = new ArrayList<>();
36 | if (topics != null) {
37 | for (String t : topics) {
38 | List categories = this.reader.getCategories();
39 | int tID = categories.indexOf(t.toLowerCase());
40 | if (tID != -1) {
41 | topicIDs.add(tID);
42 | }
43 | }
44 | }
45 | Map tagIDs = null;
46 | if (algorithm == null || algorithm == Algorithm.THREELcoll) {
47 | tagIDs = this.calculator.getCollectiveRankedTagList(topicIDs, System.currentTimeMillis() / 1000.0, count.intValue(), false, false);
48 | } else {
49 | int userID = this.reader.getUsers().indexOf(user);
50 | if (user != null && userID != -1) {
51 | tagIDs = this.calculator.getRankedTagList(userID, -1, topicIDs, System.currentTimeMillis() / 1000.0, count.intValue(), false, false, true);
52 | } else {
53 | return new LinkedHashMap();
54 | }
55 | }
56 |
57 | // map to strings
58 | Map tagStrings = new LinkedHashMap();
59 | for (Map.Entry entry : tagIDs.entrySet()) {
60 | if (tagStrings.size() < count.intValue()) {
61 | if (!filterTags.contains(entry.getKey())) {
62 | tagStrings.put(this.reader.getTags().get(entry.getKey()), entry.getValue());
63 | }
64 | } else {
65 | break;
66 | }
67 | }
68 | return tagStrings;
69 | }
70 |
71 | private synchronized void resetStructures(BookmarkReader reader, ThreeLTCalculator calculator) {
72 | this.reader = reader;
73 | this.calculator = calculator;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/engine/ThreeLayersEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package engine;
22 |
23 | import processing.ThreeLTCalculator;
24 | import file.BookmarkReader;
25 |
26 | import java.util.ArrayList;
27 | import java.util.Collections;
28 | import java.util.LinkedHashMap;
29 | import java.util.List;
30 | import java.util.Map;
31 | import java.util.TreeMap;
32 |
33 | import common.CalculationType;
34 | import common.DoubleMapComparator;
35 |
36 | // TODO: make it work in online setting! (caching + LDA topic calculation)
37 | public class ThreeLayersEngine implements EngineInterface {
38 |
39 | private BookmarkReader reader = null;
40 | private ThreeLTCalculator calculator = null;
41 | private final Map topTags;
42 |
43 | public ThreeLayersEngine() {
44 | this.topTags = new LinkedHashMap<>();
45 | this.reader = null;
46 | }
47 |
48 | public void loadFile(String path, String filename) throws Exception {
49 | BookmarkReader reader = EngineUtils.getSortedBookmarkReader(path, filename);
50 |
51 | ThreeLTCalculator calculator = new ThreeLTCalculator(reader, reader.getBookmarks().size(), 5, 5, true, true, false, CalculationType.NONE);
52 | Map topTags = EngineUtils.calcTopEntities(reader, EntityType.TAG);
53 | resetStructure(reader, calculator, topTags);
54 | }
55 |
56 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
57 | if (count == null || count.doubleValue() < 1) {
58 | count = 10;
59 | }
60 | if (filterOwnEntities == null) {
61 | filterOwnEntities = true;
62 | }
63 | List filterTags = new ArrayList();
64 |
65 | Map tagIDs = new LinkedHashMap<>();
66 | Map tagMap = new LinkedHashMap<>();
67 | if (this.reader == null || this.calculator == null) {
68 | return tagMap;
69 | }
70 | if (algorithm == null || algorithm != Algorithm.MP) {
71 | int userID = -1;
72 | if (user != null) {
73 | userID = this.reader.getUsers().indexOf(user);
74 | }
75 | filterTags = EngineUtils.getFilterTags(filterOwnEntities, this.reader, user, resource/*, this.calculator.getUserMaps().get(userID)*/);
76 | int resID = -1;
77 | if (resource != null) {
78 | resID = this.reader.getResources().indexOf(resource);
79 | }
80 | List topicIDs = new ArrayList<>();
81 | if (topics != null) {
82 | for (String t : topics) {
83 | int tID = this.reader.getCategories().indexOf(t);
84 | if (tID != -1) {
85 | topicIDs.add(tID);
86 | }
87 | }
88 | }
89 | if (algorithm == null || algorithm == Algorithm.THREELTMPr) {
90 | tagIDs = this.calculator.getRankedTagList(userID, resID, topicIDs, System.currentTimeMillis() / 1000.0, count, this.reader.hasTimestamp(), false, false); // not sorted
91 | } else if (algorithm == Algorithm.THREELT) {
92 | tagIDs = this.calculator.getRankedTagList(userID, -1, topicIDs, System.currentTimeMillis() / 1000.0, count, this.reader.hasTimestamp(), false, false); // not sorted
93 | } else if (algorithm == Algorithm.THREEL) {
94 | tagIDs = this.calculator.getRankedTagList(userID, -1, topicIDs, System.currentTimeMillis() / 1000.0, count, false, false, false); // not sorted
95 | }
96 | }
97 |
98 | // TODO: finish filtering
99 |
100 | // fill up with MP tags
101 | if (tagIDs.size() < count) {
102 | for (Map.Entry t : this.topTags.entrySet()) {
103 | if (tagIDs.size() < count) {
104 | if (!tagIDs.containsKey(t.getKey())) {
105 | tagIDs.put(t.getKey(), t.getValue());
106 | }
107 | } else {
108 | break;
109 | }
110 | }
111 | }
112 |
113 | // sort
114 | Map sortedResultMap = new TreeMap(new DoubleMapComparator(tagIDs));
115 | sortedResultMap.putAll(tagIDs);
116 | // map tag-IDs back to strings
117 | for (Map.Entry tEntry : sortedResultMap.entrySet()) {
118 | if (tagMap.size() < count) {
119 | tagMap.put(this.reader.getTags().get(tEntry.getKey()), tEntry.getValue());
120 | }
121 | }
122 | return tagMap;
123 | }
124 |
125 | public synchronized void resetStructure(BookmarkReader reader, ThreeLTCalculator calculator, Map topTags) {
126 | this.reader = reader;
127 | this.calculator = calculator;
128 |
129 | this.topTags.clear();
130 | this.topTags.putAll(topTags);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/engine/UserRecommenderEngine.java:
--------------------------------------------------------------------------------
1 | /*
2 | TagRecommender:
3 | A framework to implement and evaluate algorithms for the recommendation
4 | of tags.
5 | Copyright (C) 2013 Dominik Kowald
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU Affero General Public License as
9 | published by the Free Software Foundation, either version 3 of the
10 | License, or (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU Affero General Public License for more details.
16 |
17 | You should have received a copy of the GNU Affero General Public License
18 | along with this program. If not, see .
19 | */
20 |
21 | package engine;
22 |
23 | import file.BookmarkReader;
24 | import itemrecommendations.CFResourceCalculator;
25 |
26 | import java.util.Collections;
27 | import java.util.LinkedHashMap;
28 | import java.util.List;
29 | import java.util.Map;
30 | import java.util.TreeMap;
31 |
32 | import common.Bookmark;
33 | import common.DoubleMapComparator;
34 | import common.Features;
35 | import common.Similarity;
36 |
37 | // TODO: cache values
38 | public class UserRecommenderEngine implements EngineInterface {
39 |
40 | private BookmarkReader reader = null;
41 | private CFResourceCalculator calculator = null;
42 | private CFResourceCalculator tagCalculator = null;
43 | private CFResourceCalculator cbCalculator = null;
44 | private final Map topUsers;
45 |
46 | public UserRecommenderEngine() {
47 | this.topUsers = new LinkedHashMap();
48 | this.reader = new BookmarkReader(0, false);
49 | }
50 |
51 | public void loadFile(String path, String filename) throws Exception {
52 | BookmarkReader reader = EngineUtils.getSortedBookmarkReader(path, filename);
53 |
54 | CFResourceCalculator calculator = new CFResourceCalculator(reader, reader.getBookmarks().size(), false, true, false, 5, Similarity.COSINE, Features.ENTITIES);
55 | CFResourceCalculator tagCalculator = new CFResourceCalculator(reader, reader.getBookmarks().size(), false, true, false, 5, Similarity.COSINE, Features.TAGS);
56 | CFResourceCalculator cbCalculator = new CFResourceCalculator(reader, reader.getBookmarks().size(), false, false, true, 5, Similarity.COSINE, Features.TAGS);
57 |
58 | Map topUsers = EngineUtils.calcTopEntities(reader, EntityType.USER);
59 | resetStructure(reader, calculator, tagCalculator, cbCalculator, topUsers);
60 | }
61 |
62 | public synchronized Map getEntitiesWithLikelihood(String user, String resource, List topics, Integer count, Boolean filterOwnEntities, Algorithm algorithm, EntityType type) {
63 |
64 | if (count == null || count.doubleValue() < 1) {
65 | count = 10;
66 | }
67 | if (filterOwnEntities == null) {
68 | filterOwnEntities = true;
69 | }
70 |
71 | Map userIDs = new LinkedHashMap<>();
72 | Map userMap = new LinkedHashMap<>();
73 | if (this.reader == null || this.calculator == null) {
74 | System.out.println("No data has been loaded");
75 | return userMap;
76 | }
77 | int userID = -1;
78 | int resID = -1;
79 | if (user != null) {
80 | userID = this.reader.getUsers().indexOf(user);
81 | }
82 | if (resource != null) {
83 | resID = this.reader.getResources().indexOf(resource);
84 | }
85 | // used to filter already assigned users
86 | List resourceUsers = null;
87 | if (resID != -1 && filterOwnEntities.booleanValue()) {
88 | resourceUsers = Bookmark.getUsersFromResource(this.reader.getBookmarks(), resID);
89 | }
90 |
91 | if (algorithm == null || algorithm != Algorithm.USERMP) {
92 | if (userID != -1) {
93 | if (algorithm == Algorithm.USERTAGCF) {
94 | userIDs = this.tagCalculator.getRankedResourcesList(userID, -1, false, false, false, filterOwnEntities.booleanValue(), true); // not sorted!
95 | } else {
96 | userIDs = this.calculator.getRankedResourcesList(userID, -1, false, false, false, filterOwnEntities.booleanValue(), true); // not sorted!
97 | }
98 | } else if (resID != -1) {
99 | userIDs = this.cbCalculator.getRankedResourcesList(-1, resID, false, false, false, filterOwnEntities.booleanValue(), true); // not sorted
100 | }
101 | }
102 | // then call MP if necessary
103 | if (userIDs.size() < count) {
104 | for (Map.Entry t : this.topUsers.entrySet()) {
105 | if (userIDs.size() < count) {
106 | // add MP users if they are not already in the recommeded list
107 | if (!userIDs.containsKey(t.getKey()) && (resourceUsers == null || !resourceUsers.contains(t.getKey()))) {
108 | userIDs.put(t.getKey(), t.getValue());
109 | }
110 | } else {
111 | break;
112 | }
113 | }
114 | }
115 |
116 | // sort
117 | Map sortedResultMap = new TreeMap(new DoubleMapComparator(userIDs));
118 | sortedResultMap.putAll(userIDs);
119 |
120 | // last map IDs back to strings
121 | for (Map.Entry tEntry : sortedResultMap.entrySet()) {
122 | if (userMap.size() < count) {
123 | userMap.put(this.reader.getUsers().get(tEntry.getKey()), tEntry.getValue());
124 | } else {
125 | break;
126 | }
127 | }
128 |
129 | return userMap;
130 | }
131 |
132 | public synchronized void resetStructure(BookmarkReader reader, CFResourceCalculator calculator, CFResourceCalculator tagCalculator, CFResourceCalculator cbCalculator, Map topUsers) {
133 | this.reader = reader;
134 | this.calculator = calculator;
135 | this.tagCalculator = tagCalculator;
136 | this.cbCalculator = cbCalculator;
137 |
138 | this.topUsers.clear();
139 | this.topUsers.putAll(topUsers);
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/file/BookmarkWriter.java:
--------------------------------------------------------------------------------
1 | package file;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileOutputStream;
7 | import java.io.FileWriter;
8 | import java.io.IOException;
9 | import java.io.InputStreamReader;
10 | import java.io.OutputStreamWriter;
11 | import java.util.List;
12 |
13 | import com.google.common.primitives.Ints;
14 |
15 | import common.Bookmark;
16 |
17 | public class BookmarkWriter {
18 |
19 | public static boolean writeSample(BookmarkReader reader, List userSample, String filename, List catPredictions, boolean realValues) {
20 | return doWriteSample(reader, userSample, null, filename, catPredictions, realValues);
21 | }
22 |
23 | public static boolean writeSample(BookmarkReader reader, List userSample, String path, String filename, List catPredictions, boolean realValues) {
24 | return doWriteSample(reader, userSample, path, filename, catPredictions, realValues);
25 | }
26 |
27 | private static boolean doWriteSample(BookmarkReader reader, List userSample, String path, String filename, List catPredictions, boolean realValues) {
28 | try {
29 | String filePath = "";
30 | if (path == null) {
31 | filePath = "./data/csv/" + filename + ".txt";
32 | } else {
33 | filePath = path + filename;
34 | }
35 | //FileWriter writer = new FileWriter(new File(filePath));
36 | OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(filePath)), "UTF8");
37 | BufferedWriter bw = new BufferedWriter(writer);
38 | int userCount = 0;
39 | // TODO: check encoding
40 | for (Bookmark bookmark : userSample) {
41 | String user = (realValues ? reader.getUsers().get(bookmark.getUserID()).replace("\"", "") : Integer.toString(bookmark.getUserID()));
42 | String resource = (realValues ? reader.getResources().get(bookmark.getResourceID()).replace("\"", "") : Integer.toString(bookmark.getResourceID()));
43 | bw.write("\"" + user + "\";");
44 | bw.write("\"" + resource + "\";");
45 | bw.write("\"" + bookmark.getTimestamp().replace("\"", "") + "\";\"");
46 | int i = 0;
47 | for (int t : bookmark.getTags()) {
48 | String tag = (realValues ? reader.getTags().get(t).replace("\"", "") : Integer.toString(t));
49 | bw.write(tag);
50 | if (++i < bookmark.getTags().size()) {
51 | bw.write(',');
52 | }
53 | }
54 | bw.write("\";\"");
55 |
56 | List userCats = (catPredictions == null ? bookmark.getCategories() : Ints.asList(catPredictions.get(userCount++)));
57 | i = 0;
58 | for (int cat : userCats) {
59 | //bw.write(URLEncoder.encode((catPredictions == null ? reader.getCategories().get(cat).replace("\"", "") : reader.getTags().get(cat)).replace("\"", ""), "UTF-8"));
60 | String catName = (realValues ? reader.getCategories().get(cat).replace("\"", "") : "t" + cat);
61 | bw.write(catName);
62 | if (++i < userCats.size()) {
63 | bw.write(',');
64 | }
65 | }
66 | bw.write("\"");
67 | if (bookmark.getRating() != -2) {
68 | bw.write(";\"" + (int)bookmark.getRating() + "\"");
69 | } else {
70 | bw.write(";\"\"");
71 | }
72 | if (bookmark.getTitle() != null) {
73 | bw.write(";\"" + bookmark.getTitle() + "\"");
74 | } /*else {
75 | bw.write(";\"\"");
76 | }*/
77 | bw.write("\n");
78 | }
79 |
80 | bw.flush();
81 | bw.close();
82 | return true;
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | }
86 | return false;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/file/ResultSerializer.java:
--------------------------------------------------------------------------------
1 | package file;
2 |
3 | import java.io.BufferedOutputStream;
4 | import java.io.FileOutputStream;
5 | import java.io.ObjectOutput;
6 | import java.io.ObjectOutputStream;
7 | import java.io.OutputStream;
8 | import java.util.Map;
9 |
10 | public class ResultSerializer {
11 |
12 | public static void serializePredictions(Map> predictions, String filePath) {
13 | OutputStream file = null;
14 | try {
15 | file = new FileOutputStream(filePath);
16 | OutputStream buffer = new BufferedOutputStream(file);
17 | ObjectOutput output = new ObjectOutputStream(buffer);
18 | output.writeObject(predictions);
19 | output.close();
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/file/postprocessing/CatDescFiltering.java:
--------------------------------------------------------------------------------
1 | package file.postprocessing;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.LinkedHashMap;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Set;
9 | import java.util.TreeMap;
10 |
11 |
12 |
13 | import common.Bookmark;
14 | import common.DoubleMapComparator;
15 | import common.Utilities;
16 |
17 | import file.BookmarkReader;
18 |
19 | public class CatDescFiltering {
20 |
21 | private BookmarkReader reader;
22 | private List trainList;
23 | private List