use of ldbc.snb.datagen.entities.dynamic.relations.ForumMembership in project ldbc_snb_datagen_hadoop by ldbc.
the class PersonActivityGenerator method generateGroups.
private void generateGroups(Person person, List<Person> block) throws IOException {
// generate user created groups
double moderatorProb = randomFarm_.get(RandomGeneratorFarm.Aspect.FORUM_MODERATOR).nextDouble();
if (moderatorProb <= DatagenParams.groupModeratorProb) {
int numGroup = randomFarm_.get(RandomGeneratorFarm.Aspect.NUM_FORUM).nextInt(DatagenParams.maxNumGroupCreatedPerUser) + 1;
for (int j = 0; j < numGroup; j++) {
Forum group = forumGenerator_.createGroup(randomFarm_, forumId++, person, block);
exporter_.export(group);
for (ForumMembership fm : group.memberships()) {
exporter_.export(fm);
}
// generate uniform posts/comments
messageId = uniformPostGenerator_.createPosts(randomFarm_, group, group.memberships(), numPostsPerGroup(randomFarm_, group, DatagenParams.maxNumGroupPostPerMonth, DatagenParams.maxNumMemberGroup), messageId, exporter_);
messageId = flashmobPostGenerator_.createPosts(randomFarm_, group, group.memberships(), numPostsPerGroup(randomFarm_, group, DatagenParams.maxNumGroupFlashmobPostPerMonth, DatagenParams.maxNumMemberGroup), messageId, exporter_);
}
}
}
use of ldbc.snb.datagen.entities.dynamic.relations.ForumMembership in project ldbc_snb_datagen_hadoop by ldbc.
the class PostGenerator method createPosts.
public long createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final List<ForumMembership> memberships, long numPosts, long startId, PersonActivityExporter exporter) throws IOException {
long postId = startId;
Properties prop = new Properties();
prop.setProperty("type", "post");
for (ForumMembership member : memberships) {
double numPostsMember = numPosts / (double) memberships.size();
if (numPostsMember < 1.0) {
double prob = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_POST).nextDouble();
if (prob < numPostsMember)
numPostsMember = 1.0;
} else {
numPostsMember = Math.ceil(numPostsMember);
}
for (int i = 0; i < (int) (numPostsMember); ++i) {
PostInfo postInfo = generatePostInfo(randomFarm.get(RandomGeneratorFarm.Aspect.TAG), randomFarm.get(RandomGeneratorFarm.Aspect.DATE), forum, member);
if (postInfo != null) {
String content = "";
content = this.generator_.generateText(member.person(), postInfo.tags, prop);
int country = member.person().countryId();
IP ip = member.person().ipAddress();
Random random = randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER);
if (PersonBehavior.changeUsualCountry(random, postInfo.date)) {
random = randomFarm.get(RandomGeneratorFarm.Aspect.COUNTRY);
country = Dictionaries.places.getRandomCountryUniform(random);
random = randomFarm.get(RandomGeneratorFarm.Aspect.IP);
ip = Dictionaries.ips.getIP(random, country);
}
post_.initialize(SN.formId(SN.composeId(postId++, postInfo.date)), postInfo.date, member.person(), forum.id(), content, postInfo.tags, country, ip, Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.person().browserId()), forum.language());
exporter.export(post_);
if (randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1) {
likeGenerator_.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, post_, Like.LikeType.POST, exporter);
}
// generate comments
int numComments = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_COMMENT).nextInt(DatagenParams.maxNumComments + 1);
postId = commentGenerator_.createComments(randomFarm, forum, post_, numComments, postId, exporter);
}
}
}
return postId;
}
use of ldbc.snb.datagen.entities.dynamic.relations.ForumMembership in project ldbc_snb_datagen_hadoop by ldbc.
the class ForumGenerator method createWall.
public Forum createWall(RandomGeneratorFarm randomFarm, long forumId, Person person) {
int language = randomFarm.get(RandomGeneratorFarm.Aspect.LANGUAGE).nextInt(person.languages().size());
Forum forum = new Forum(SN.formId(SN.composeId(forumId, person.creationDate() + DatagenParams.deltaTime)), person.creationDate() + DatagenParams.deltaTime, new Person.PersonSummary(person), StringUtils.clampString("Wall of " + person.firstName() + " " + person.lastName(), 256), person.cityId(), language);
List<Integer> forumTags = new ArrayList<>();
for (Integer interest : person.interests()) {
forumTags.add(interest);
}
forum.tags(forumTags);
TreeSet<Knows> knows = person.knows();
for (Knows k : knows) {
long date = Math.max(k.creationDate(), forum.creationDate()) + DatagenParams.deltaTime;
assert (forum.creationDate() + DatagenParams.deltaTime) <= date : "Forum creation date is larger than knows in wall " + forum.creationDate() + " " + k.creationDate();
forum.addMember(new ForumMembership(forum.id(), date, k.to()));
}
return forum;
}
use of ldbc.snb.datagen.entities.dynamic.relations.ForumMembership in project ldbc_snb_datagen_spark by ldbc.
the class CommentGenerator method createComments.
public Stream<Pair<Comment, Stream<Like>>> createComments(RandomGeneratorFarm randomFarm, final Forum forum, final Post post, long numComments, Iterator<Long> idIterator, long blockId) {
List<Message> parentCandidates = new ArrayList<>();
parentCandidates.add(post);
Properties prop = new Properties();
prop.setProperty("type", "comment");
// each iteration adds a new leaf node, for the first iteration this is a child of root Post
return Streams.stream(Iterators.forIterator(0, i -> i < numComments, i -> ++i, i -> {
// pick from parent candidates
int parentIndex = randomFarm.get(RandomGeneratorFarm.Aspect.REPLY_TO).nextInt(parentCandidates.size());
Message parentMessage = parentCandidates.get(parentIndex);
// memberships that overlap with the existence of the parent message
List<ForumMembership> validMemberships = new ArrayList<>();
for (ForumMembership membership : forum.getMemberships()) {
if ((membership.getCreationDate() < parentMessage.getCreationDate() && membership.getDeletionDate() > parentMessage.getCreationDate()) || membership.getCreationDate() < parentMessage.getDeletionDate() && membership.getDeletionDate() > parentMessage.getDeletionDate()) {
validMemberships.add(membership);
}
}
if (validMemberships.size() == 0) {
// skip if no valid membership
return Iterators.ForIterator.BREAK();
}
// get random membership from valid memberships - picking who created the comment
int membershipIndex = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX).nextInt(validMemberships.size());
ForumMembership membership = validMemberships.get(membershipIndex);
TreeSet<Integer> tags = new TreeSet<>();
String content;
boolean isShort = false;
if (randomFarm.get(RandomGeneratorFarm.Aspect.REDUCED_TEXT).nextDouble() > 0.6666) {
List<Integer> currentTags = new ArrayList<>();
for (Integer tag : parentMessage.getTags()) {
if (randomFarm.get(RandomGeneratorFarm.Aspect.TAG).nextDouble() > 0.5) {
tags.add(tag);
}
currentTags.add(tag);
}
for (int j = 0; j < (int) Math.ceil(parentMessage.getTags().size() / 2.0); ++j) {
int randomTag = currentTags.get(randomFarm.get(RandomGeneratorFarm.Aspect.TAG).nextInt(currentTags.size()));
tags.add(Dictionaries.tagMatrix.getRandomRelated(randomFarm.get(RandomGeneratorFarm.Aspect.TOPIC), randomTag));
}
content = this.generator.generateText(membership.getPerson(), tags, prop);
} else {
isShort = true;
int index = randomFarm.get(RandomGeneratorFarm.Aspect.TEXT_SIZE).nextInt(shortComments.length);
content = shortComments[index];
}
// creation date
long minCreationDate = Math.max(parentMessage.getCreationDate(), membership.getCreationDate()) + DatagenParams.delta;
long maxCreationDate = Collections.min(Arrays.asList(membership.getDeletionDate(), parentMessage.getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
if (maxCreationDate <= minCreationDate) {
return Iterators.ForIterator.CONTINUE();
}
// powerlaw distribtion
long creationDate = Dictionaries.dates.powerLawCommDateDay(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), minCreationDate);
if (creationDate > maxCreationDate) {
return Iterators.ForIterator.CONTINUE();
}
long deletionDate;
boolean isExplicitlyDeleted;
// if person is a deleter and selected for delete
if (membership.getPerson().isMessageDeleter() && randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_COMM).nextDouble() < DatagenParams.probCommentDeleted) {
isExplicitlyDeleted = true;
long minDeletionDate = creationDate + DatagenParams.delta;
long maxDeletionDate = Collections.min(Arrays.asList(parentMessage.getDeletionDate(), membership.getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
if (maxDeletionDate <= minDeletionDate) {
return Iterators.ForIterator.CONTINUE();
}
deletionDate = Dictionaries.dates.powerLawDeleteDate(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), minDeletionDate, maxDeletionDate);
} else {
isExplicitlyDeleted = false;
deletionDate = Collections.min(Arrays.asList(parentMessage.getDeletionDate(), membership.getDeletionDate()));
}
int country = membership.getPerson().getCountry();
IP ip = membership.getPerson().getIpAddress();
Random random = randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER);
if (PersonBehavior.changeUsualCountry(random, creationDate)) {
random = randomFarm.get(RandomGeneratorFarm.Aspect.COUNTRY);
country = Dictionaries.places.getRandomCountryUniform(random);
random = randomFarm.get(RandomGeneratorFarm.Aspect.IP);
ip = Dictionaries.ips.getIP(random, country);
}
Comment comment = new Comment(SN.formId(SN.composeId(idIterator.next(), creationDate), blockId), creationDate, deletionDate, membership.getPerson(), forum.getId(), content, new ArrayList<>(tags), country, ip, Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), membership.getPerson().getBrowserId()), post.getMessageId(), parentMessage.getMessageId(), isExplicitlyDeleted);
if (!isShort)
parentCandidates.add(new Comment(comment));
Stream<Like> likeStream = comment.getContent().length() > 10 && randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ? likeGenerator.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_LIKES), randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, comment, Like.LikeType.COMMENT) : Stream.empty();
return Iterators.ForIterator.RETURN(new Pair<>(comment, likeStream));
}));
}
use of ldbc.snb.datagen.entities.dynamic.relations.ForumMembership in project ldbc_snb_datagen_spark by ldbc.
the class ForumGenerator method createWall.
/**
* Creates a personal wall for a given Person. All friends become members
*
* @param randomFarm randomFarm
* @param forumId forumID
* @param person Person
* @return Forum
*/
Forum createWall(RandomGeneratorFarm randomFarm, long forumId, Person person, long blockId) {
int language = person.getLanguages().get(randomFarm.get(RandomGeneratorFarm.Aspect.LANGUAGE).nextInt(person.getLanguages().size()));
// Check moderator can be added
if (person.getDeletionDate() - person.getCreationDate() + DatagenParams.delta < 0) {
// what to return?
return null;
}
Forum forum = new Forum(SN.formId(SN.composeId(forumId, person.getCreationDate() + DatagenParams.delta), blockId), person.getCreationDate() + DatagenParams.delta, person.getDeletionDate(), new PersonSummary(person), person.getDeletionDate(), StringUtils.clampString("Wall of " + person.getFirstName() + " " + person.getLastName(), 256), person.getCityId(), language, Forum.ForumType.WALL, false);
// wall inherits tags from person
List<Integer> forumTags = new ArrayList<>(person.getInterests());
forum.setTags(forumTags);
// adds all friends as members of wall
List<Knows> knows = person.getKnows();
// for each friend generate hasMember edge
for (Knows know : knows) {
long hasMemberCreationDate = know.getCreationDate() + DatagenParams.delta;
long hasMemberDeletionDate = Math.min(forum.getDeletionDate(), know.getDeletionDate());
if (hasMemberDeletionDate - hasMemberCreationDate < 0) {
continue;
}
forum.addMember(new ForumMembership(forum.getId(), hasMemberCreationDate, hasMemberDeletionDate, know.to(), Forum.ForumType.WALL, false));
}
return forum;
}
Aggregations