Search in sources :

Example 1 with PersonSummary

use of ldbc.snb.datagen.entities.dynamic.person.PersonSummary 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;
}
Also used : ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary) Knows(ldbc.snb.datagen.entities.dynamic.relations.Knows) Forum(ldbc.snb.datagen.entities.dynamic.Forum)

Example 2 with PersonSummary

use of ldbc.snb.datagen.entities.dynamic.person.PersonSummary in project ldbc_snb_datagen_spark by ldbc.

the class ForumGenerator method createAlbum.

/**
 * Creates an album for a given Person.
 *
 * @param randomFarm random farm
 * @param forumId    forumId
 * @param person     Person who the album belongs it
 * @param numAlbum   number of album e.g. Album 10
 * @return Album
 */
Forum createAlbum(RandomGeneratorFarm randomFarm, long forumId, Person person, int numAlbum, long blockId) {
    long minAlbumCreationDate = person.getCreationDate() + DatagenParams.delta;
    long maxAlbumCreationDate = Math.min(person.getDeletionDate(), Dictionaries.dates.getSimulationEnd());
    long albumCreationDate = Dictionaries.dates.randomDate(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), minAlbumCreationDate, maxAlbumCreationDate);
    long albumDeletionDate;
    boolean isExplicitlyDeleted;
    if (randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_FORUM).nextDouble() < DatagenParams.probForumDeleted) {
        isExplicitlyDeleted = true;
        long minAlbumDeletionDate = albumCreationDate + DatagenParams.delta;
        long maxAlbumDeletionDate = Math.min(person.getDeletionDate(), Dictionaries.dates.getSimulationEnd());
        if (maxAlbumDeletionDate - minAlbumCreationDate < 0) {
            return null;
        }
        albumDeletionDate = Dictionaries.dates.randomDate(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), minAlbumDeletionDate, maxAlbumDeletionDate);
    } else {
        isExplicitlyDeleted = false;
        albumDeletionDate = person.getDeletionDate();
    }
    int language = person.getLanguages().get(randomFarm.get(RandomGeneratorFarm.Aspect.LANGUAGE).nextInt(person.getLanguages().size()));
    Forum forum = new Forum(SN.formId(SN.composeId(forumId, albumCreationDate), blockId), albumCreationDate, albumDeletionDate, new PersonSummary(person), person.getDeletionDate(), StringUtils.clampString("Album " + numAlbum + " of " + person.getFirstName() + " " + person.getLastName(), 256), person.getCityId(), language, Forum.ForumType.ALBUM, isExplicitlyDeleted);
    Iterator<Integer> iter = person.getInterests().iterator();
    int idx = randomFarm.get(RandomGeneratorFarm.Aspect.FORUM_INTEREST).nextInt(person.getInterests().size());
    for (int i = 0; i < idx; i++) {
        iter.next();
    }
    int interestId = iter.next();
    List<Integer> interest = new ArrayList<>();
    interest.add(interestId);
    forum.setTags(interest);
    List<Integer> countries = Dictionaries.places.getCountries();
    int randomCountry = randomFarm.get(RandomGeneratorFarm.Aspect.COUNTRY).nextInt(countries.size());
    forum.setPlaceId(countries.get(randomCountry));
    List<Knows> friends = new ArrayList<>(person.getKnows());
    for (Knows knows : friends) {
        double prob = randomFarm.get(RandomGeneratorFarm.Aspect.ALBUM_MEMBERSHIP).nextDouble();
        if (prob < 0.7) {
            long hasMemberCreationDate = Math.max(knows.to().getCreationDate(), forum.getCreationDate()) + DatagenParams.delta;
            long hasMemberDeletionDate = Collections.min(Arrays.asList(knows.to().getDeletionDate(), forum.getDeletionDate()));
            if (hasMemberDeletionDate - hasMemberCreationDate > 0) {
                forum.addMember(new ForumMembership(forum.getId(), hasMemberCreationDate, hasMemberDeletionDate, knows.to(), Forum.ForumType.ALBUM, false));
            }
        }
    }
    return forum;
}
Also used : Forum(ldbc.snb.datagen.entities.dynamic.Forum) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary) Knows(ldbc.snb.datagen.entities.dynamic.relations.Knows)

Example 3 with PersonSummary

use of ldbc.snb.datagen.entities.dynamic.person.PersonSummary in project ldbc_snb_datagen_spark by ldbc.

the class ForumGenerator method createGroup.

/**
 * Creates a Group with the Person as the moderator. 30% membership come from friends the rest are random.
 *
 * @param randomFarm random number generator
 * @param forumId    forumID
 * @param moderator  moderator
 * @param block      person block
 * @return Group
 */
Forum createGroup(RandomGeneratorFarm randomFarm, long forumId, Person moderator, List<Person> block, long blockId) {
    // creation date
    long groupMinCreationDate = moderator.getCreationDate() + DatagenParams.delta;
    long groupMaxCreationDate = Math.min(moderator.getDeletionDate(), Dictionaries.dates.getSimulationEnd());
    long groupCreationDate = Dictionaries.dates.randomDate(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), groupMinCreationDate, groupMaxCreationDate);
    // deletion date
    long groupDeletionDate;
    boolean isExplicitlyDeleted;
    if (randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_FORUM).nextDouble() < DatagenParams.probForumDeleted) {
        isExplicitlyDeleted = true;
        long groupMinDeletionDate = groupCreationDate + DatagenParams.delta;
        long groupMaxDeletionDate = Dictionaries.dates.getSimulationEnd();
        groupDeletionDate = Dictionaries.dates.randomDate(randomFarm.get(RandomGeneratorFarm.Aspect.DATE), groupMinDeletionDate, groupMaxDeletionDate);
    } else {
        isExplicitlyDeleted = false;
        groupDeletionDate = Dictionaries.dates.getNetworkCollapse();
    }
    // the hasModerator edge is deleted if either the Forum (group) or the Person (moderator) is deleted
    long moderatorDeletionDate = Math.min(groupDeletionDate, moderator.getDeletionDate());
    int language = moderator.getLanguages().get(randomFarm.get(RandomGeneratorFarm.Aspect.LANGUAGE).nextInt(moderator.getLanguages().size()));
    Iterator<Integer> iter = moderator.getInterests().iterator();
    int idx = randomFarm.get(RandomGeneratorFarm.Aspect.FORUM_INTEREST).nextInt(moderator.getInterests().size());
    for (int i = 0; i < idx; i++) {
        iter.next();
    }
    int interestId = iter.next();
    List<Integer> interest = new ArrayList<>();
    interest.add(interestId);
    // Create group
    Forum forum = new Forum(SN.formId(SN.composeId(forumId, groupCreationDate), blockId), groupCreationDate, groupDeletionDate, new PersonSummary(moderator), moderatorDeletionDate, StringUtils.clampString("Group for " + Dictionaries.tags.getName(interestId).replace("\"", "\\\"") + " in " + Dictionaries.places.getPlaceName(moderator.getCityId()), 256), moderator.getCityId(), language, Forum.ForumType.GROUP, isExplicitlyDeleted);
    // Set tags of this forum
    forum.setTags(interest);
    // Add members
    TreeSet<Long> groupMembers = new TreeSet<>();
    List<Knows> moderatorKnows = new ArrayList<>(moderator.getKnows());
    int numModeratorKnows = moderatorKnows.size();
    int groupSize = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_USERS_PER_FORUM).nextInt(DatagenParams.maxGroupSize);
    int numLoop = 0;
    while ((forum.getMemberships().size() < groupSize) && (numLoop < DatagenParams.blockSize)) {
        // controls the proportion of members that are friends
        double prob = randomFarm.get(RandomGeneratorFarm.Aspect.KNOWS_LEVEL).nextDouble();
        if (prob < 0.3 && numModeratorKnows > 0) {
            // pick random knows edge from friends
            int knowsIndex = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX).nextInt(numModeratorKnows);
            Knows knows = moderatorKnows.get(knowsIndex);
            if (!groupMembers.contains(knows.to().getAccountId())) {
                // if friend not already member of group
                long minCreationDate = Math.max(forum.getCreationDate(), knows.to().getCreationDate()) + DatagenParams.delta;
                long maxCreationDate = Collections.min(Arrays.asList(forum.getDeletionDate(), knows.to().getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
                if (maxCreationDate - minCreationDate > 0) {
                    Random random = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX);
                    long hasMemberCreationDate = Dictionaries.dates.randomDate(random, minCreationDate, maxCreationDate);
                    long hasMemberDeletionDate;
                    boolean isHasMemberExplicitlyDeleted;
                    if (randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_MEMB).nextDouble() < DatagenParams.probMembDeleted) {
                        isHasMemberExplicitlyDeleted = true;
                        long minDeletionDate = hasMemberCreationDate + DatagenParams.delta;
                        long maxDeletionDate = Collections.min(Arrays.asList(knows.to().getDeletionDate(), forum.getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
                        if (maxDeletionDate - minDeletionDate < 0) {
                            continue;
                        }
                        hasMemberDeletionDate = Dictionaries.dates.randomDate(random, minDeletionDate, maxDeletionDate);
                    } else {
                        isHasMemberExplicitlyDeleted = false;
                        hasMemberDeletionDate = Collections.min(Arrays.asList(knows.to().getDeletionDate(), forum.getDeletionDate()));
                    }
                    ForumMembership hasMember = new ForumMembership(forum.getId(), hasMemberCreationDate, hasMemberDeletionDate, knows.to(), Forum.ForumType.GROUP, isHasMemberExplicitlyDeleted);
                    forum.addMember(hasMember);
                    groupMembers.add(knows.to().getAccountId());
                }
            }
        } else {
            // pick from the person block
            int candidateIndex = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX).nextInt(block.size());
            Person member = block.get(candidateIndex);
            prob = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP).nextDouble();
            if ((prob < 0.1) && !groupMembers.contains(member.getAccountId())) {
                long minHasMemberCreationDate = Math.max(forum.getCreationDate(), member.getCreationDate()) + DatagenParams.delta;
                long maxHasMemberCreationDate = Collections.min(Arrays.asList(forum.getDeletionDate(), member.getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
                if (maxHasMemberCreationDate - minHasMemberCreationDate > 0) {
                    Random random = randomFarm.get(RandomGeneratorFarm.Aspect.MEMBERSHIP_INDEX);
                    long hasMemberCreationDate = Dictionaries.dates.randomDate(random, minHasMemberCreationDate, maxHasMemberCreationDate);
                    long hasMemberDeletionDate;
                    boolean isHasMemberExplicitlyDeleted;
                    if (randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_MEMB).nextDouble() < DatagenParams.probMembDeleted) {
                        isHasMemberExplicitlyDeleted = true;
                        long minHasMemberDeletionDate = hasMemberCreationDate + DatagenParams.delta;
                        long maxHasMemberDeletionDate = Collections.min(Arrays.asList(member.getDeletionDate(), forum.getDeletionDate(), Dictionaries.dates.getSimulationEnd()));
                        if (maxHasMemberCreationDate - minHasMemberDeletionDate < 0) {
                            continue;
                        }
                        hasMemberDeletionDate = Dictionaries.dates.randomDate(random, minHasMemberDeletionDate, maxHasMemberDeletionDate);
                    } else {
                        isHasMemberExplicitlyDeleted = false;
                        hasMemberDeletionDate = Collections.min(Arrays.asList(member.getDeletionDate(), forum.getDeletionDate()));
                    }
                    forum.addMember(new ForumMembership(forum.getId(), hasMemberCreationDate, hasMemberDeletionDate, new PersonSummary(member), Forum.ForumType.GROUP, isHasMemberExplicitlyDeleted));
                    groupMembers.add(member.getAccountId());
                }
            }
        }
        numLoop++;
    }
    return forum;
}
Also used : Forum(ldbc.snb.datagen.entities.dynamic.Forum) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary) Knows(ldbc.snb.datagen.entities.dynamic.relations.Knows) Person(ldbc.snb.datagen.entities.dynamic.person.Person)

Example 4 with PersonSummary

use of ldbc.snb.datagen.entities.dynamic.person.PersonSummary in project ldbc_snb_datagen_spark by ldbc.

the class PersonActivityGenerator method generateWall.

/**
 * Generates the personal wall for a Person. Note, only this Person creates Posts in the wall.
 *
 * @param person Person
 */
private GenWall<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> generateWall(Person person, long blockId) {
    // Generate wall
    Forum wall = forumGenerator.createWall(randomFarm, startForumId++, person, blockId);
    // Could be null as moderator can't be added
    if (wall == null)
        return new GenWall<>(Stream.empty());
    // creates a forum membership for the moderator
    // only the moderator can post on their wall
    ForumMembership moderator = new ForumMembership(wall.getId(), wall.getCreationDate() + DatagenParams.delta, wall.getDeletionDate(), new PersonSummary(person), Forum.ForumType.WALL, false);
    // list of members who can post on the wall - only moderator of wall can post on it
    List<ForumMembership> memberships = new ArrayList<>();
    memberships.add(moderator);
    Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> uniform = uniformPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
    Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> flashMob = flashmobPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumFlashmobPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
    return new GenWall<>(Stream.of(new Triplet<>(wall, wall.getMemberships().stream(), Stream.concat(uniform, flashMob))));
}
Also used : Like(ldbc.snb.datagen.entities.dynamic.relations.Like) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) Triplet(org.javatuples.Triplet) ArrayList(java.util.ArrayList) PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary) Forum(ldbc.snb.datagen.entities.dynamic.Forum) Pair(org.javatuples.Pair)

Example 5 with PersonSummary

use of ldbc.snb.datagen.entities.dynamic.person.PersonSummary in project ldbc_snb_datagen_spark by ldbc.

the class Message method initialize.

public void initialize(long messageId, long creationDate, long deletionDate, PersonSummary author, long forumId, String content, List<Integer> tags, int countryId, IP ipAddress, int browserId, boolean isExplicitlyDeleted) {
    this.messageId = messageId;
    this.creationDate = creationDate;
    this.deletionDate = deletionDate;
    this.author = new PersonSummary(author);
    this.forumId = forumId;
    this.content = content;
    this.tags.clear();
    this.tags.addAll(tags);
    this.countryId = countryId;
    this.ipAddress.copy(ipAddress);
    this.browserId = browserId;
    this.isExplicitlyDeleted = isExplicitlyDeleted;
}
Also used : PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary)

Aggregations

PersonSummary (ldbc.snb.datagen.entities.dynamic.person.PersonSummary)5 Forum (ldbc.snb.datagen.entities.dynamic.Forum)4 ForumMembership (ldbc.snb.datagen.entities.dynamic.relations.ForumMembership)4 Knows (ldbc.snb.datagen.entities.dynamic.relations.Knows)3 ArrayList (java.util.ArrayList)1 Person (ldbc.snb.datagen.entities.dynamic.person.Person)1 Like (ldbc.snb.datagen.entities.dynamic.relations.Like)1 Pair (org.javatuples.Pair)1 Triplet (org.javatuples.Triplet)1