-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
840 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tweetpro; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CountMinSketch implements TopHashTags | ||
{ | ||
@Override | ||
public List<String> calculate(int k, ArrayList<Tweets> listaTweet) | ||
{ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tweetpro; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class MyTopHashtags implements TopHashTags | ||
{ | ||
public List<String> calculate(int k,ArrayList<Tweets> listaTweet) | ||
{ | ||
Map<String,Integer> mapHashtag=new HashMap<>(); | ||
List<String> hashList=new ArrayList<>(); | ||
|
||
for (Tweets t: listaTweet) | ||
{ if (t.getHashtags().size()>0) hashList.addAll(t.getHashtags()); } | ||
|
||
for (String h:hashList) | ||
{ | ||
if (mapHashtag.isEmpty() || (!mapHashtag.containsKey(h))) mapHashtag.put(h, 1); | ||
if (mapHashtag.containsKey(h)) mapHashtag.put(h, mapHashtag.get(h)+1); | ||
} | ||
List<String> result = mapHashtag.entrySet().stream() | ||
.sorted(Map.Entry.<String,Integer>comparingByValue().reversed()) | ||
.map(Map.Entry::getKey) | ||
.limit(k) | ||
.collect(Collectors.toList()); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tweetpro; | ||
|
||
import java.util.ArrayList; | ||
import java.util.stream.Collectors; | ||
|
||
public class MyUniqueUsers implements UniqueUsers | ||
{ | ||
@Override | ||
public int calculate(ArrayList<Tweets> listaTweet) | ||
{ | ||
return listaTweet.stream().map(s->s.getUser().getId()).collect(Collectors.toSet()).size(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tweetpro; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public interface TopHashTags | ||
{ | ||
/** | ||
* @param int k | ||
* @param List<Tweets> listaTweet | ||
* @return List<String> k hashtags most popular | ||
*/ | ||
public List<String> calculate(int k, ArrayList<Tweets> listaTweet); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package tweetpro; | ||
|
||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class Tweet implements Tweets | ||
{ | ||
private long id; | ||
private String text; | ||
private Users user; | ||
private int likeCount; | ||
private int RTCount; | ||
private boolean isRetweet; | ||
private Tweets originalTweet; | ||
private URL urlMedia; | ||
private List<String> hashtags; | ||
|
||
public Tweet(long id,String text,Users user,int likeCount,int RTCount, boolean isRetweet, Tweets originalTweet,URL urlMedia, List<String> hashtags) | ||
{ | ||
this.id=id; | ||
this.user=user; | ||
this.text=text; | ||
this.likeCount=likeCount; | ||
this.RTCount=RTCount; | ||
this.isRetweet=isRetweet; | ||
this.originalTweet=originalTweet; | ||
this.urlMedia=urlMedia; | ||
this.hashtags=hashtags; | ||
} | ||
@Override | ||
public long getID() | ||
{ | ||
return id; | ||
} | ||
@Override | ||
public Users getUser() | ||
{ | ||
return user; | ||
} | ||
|
||
@Override | ||
public String getText() | ||
{ | ||
return text; | ||
} | ||
|
||
@Override | ||
public List<String> getHashtags() | ||
{ | ||
return hashtags; | ||
} | ||
|
||
@Override | ||
public int getLikeCount() | ||
{ | ||
return likeCount; | ||
} | ||
|
||
@Override | ||
public int getRTCount() | ||
{ | ||
return RTCount; | ||
} | ||
|
||
@Override | ||
public boolean isRetweet() | ||
{ | ||
return isRetweet; | ||
} | ||
|
||
@Override | ||
public Tweets getOriginalTweet() | ||
{ | ||
return originalTweet; | ||
} | ||
|
||
@Override | ||
public Optional<URL> getMedia() | ||
{ | ||
if (urlMedia!=null) return Optional.of(urlMedia); | ||
return Optional.empty(); | ||
|
||
} | ||
@Override | ||
public String toString() | ||
{ | ||
return "{"+"id: "+id+", "+"text: "+text+", "+"user: "+user.toString()+", "+"like: "+likeCount+", " | ||
+"RT: "+RTCount+", "+"isRetweet: "+isRetweet+", "+"originalTweet: "+originalTweet+", " | ||
+"url: "+urlMedia+", "+"hashtags: "+hashtags+"}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package tweetpro; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class TweetCorpus implements TweetCorpusInterface | ||
{ | ||
protected ArrayList<Tweets> tweetList; | ||
private TopHashTags strategyTH; | ||
private UniqueUsers strategyUU; | ||
|
||
public TweetCorpus() | ||
{ | ||
tweetList=new ArrayList<>(); | ||
strategyTH=new MyTopHashtags(); | ||
strategyUU=new MyUniqueUsers(); | ||
} | ||
|
||
@Override | ||
public Iterator<Tweets> iterator() | ||
{ | ||
return tweetList.iterator(); | ||
} | ||
|
||
@Override | ||
public int getTweetCount() | ||
{ | ||
return (int)tweetList.stream().count(); | ||
} | ||
|
||
@Override | ||
public List<Tweets> getTweets(Users user) | ||
{ | ||
return tweetList.stream().filter(t->t.getUser().equals(user)).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public List<String> getTopHashtags(int k) | ||
{ | ||
return strategyTH.calculate(k, tweetList); | ||
} | ||
|
||
@Override | ||
public int getUniqueUsersCount() | ||
{ | ||
return strategyUU.calculate(tweetList); | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return tweetList.toString(); | ||
} | ||
|
||
public void setUniqueUsersCountStrategy(UniqueUsers u) | ||
{ | ||
strategyUU=u; | ||
} | ||
|
||
public void setTopHashtagsStrategy(TopHashTags t) | ||
{ | ||
strategyTH=t; | ||
} | ||
|
||
} |
Oops, something went wrong.