Search in sources :

Example 1 with Like

use of ldbc.snb.datagen.entities.dynamic.relations.Like 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));
    }));
}
Also used : IP(ldbc.snb.datagen.entities.dynamic.person.IP) java.util(java.util) Comment(ldbc.snb.datagen.entities.dynamic.messages.Comment) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) Message(ldbc.snb.datagen.entities.dynamic.messages.Message) Dictionaries(ldbc.snb.datagen.generator.dictionary.Dictionaries) PersonBehavior(ldbc.snb.datagen.util.PersonBehavior) Pair(org.javatuples.Pair) Iterators(ldbc.snb.datagen.util.Iterators) RandomGeneratorFarm(ldbc.snb.datagen.util.RandomGeneratorFarm) Stream(java.util.stream.Stream) DatagenParams(ldbc.snb.datagen.generator.DatagenParams) Like(ldbc.snb.datagen.entities.dynamic.relations.Like) Post(ldbc.snb.datagen.entities.dynamic.messages.Post) Forum(ldbc.snb.datagen.entities.dynamic.Forum) Streams(ldbc.snb.datagen.util.Streams) TextGenerator(ldbc.snb.datagen.generator.generators.textgenerators.TextGenerator) SN(ldbc.snb.datagen.generator.vocabulary.SN) Comment(ldbc.snb.datagen.entities.dynamic.messages.Comment) Message(ldbc.snb.datagen.entities.dynamic.messages.Message) IP(ldbc.snb.datagen.entities.dynamic.person.IP) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) Stream(java.util.stream.Stream) Pair(org.javatuples.Pair)

Example 2 with Like

use of ldbc.snb.datagen.entities.dynamic.relations.Like in project ldbc_snb_datagen_spark by ldbc.

the class PersonActivityGenerator method generateAlbums.

/**
 * Generates the albums for a Person.
 *
 * @param person person
 */
private GenWall<Pair<Photo, Stream<Like>>> generateAlbums(Person person, long blockId) {
    // work out number of albums to generate
    int numberOfMonths = (int) Dictionaries.dates.numberOfMonths(person.getCreationDate());
    int numberOfPhotoAlbums = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_PHOTO_ALBUM).nextInt(DatagenParams.maxNumPhotoAlbumsPerMonth + 1);
    int numberOfPhotoAlbumsForMonths = numberOfPhotoAlbums == 0 ? numberOfPhotoAlbums : numberOfMonths * numberOfPhotoAlbums;
    return new GenWall<>(Streams.stream(Iterators.forIterator(0, i -> i < numberOfPhotoAlbumsForMonths, i -> ++i, i -> {
        Forum album = forumGenerator.createAlbum(randomFarm, startForumId++, person, i, blockId);
        if (album == null) {
            return Iterators.ForIterator.CONTINUE();
        }
        // number of photos to generate
        int numPhotosInAlbum = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_PHOTO).nextInt(DatagenParams.maxNumPhotoPerAlbums + 1);
        // create photos
        Stream<Pair<Photo, Stream<Like>>> photos = photoGenerator.createPhotos(randomFarm, album, numPhotosInAlbum, messageIdIterator, blockId);
        return Iterators.ForIterator.RETURN(new Triplet<>(album, album.getMemberships().stream(), photos));
    })));
}
Also used : Like(ldbc.snb.datagen.entities.dynamic.relations.Like) Forum(ldbc.snb.datagen.entities.dynamic.Forum) Pair(org.javatuples.Pair)

Example 3 with Like

use of ldbc.snb.datagen.entities.dynamic.relations.Like 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 4 with Like

use of ldbc.snb.datagen.entities.dynamic.relations.Like in project ldbc_snb_datagen_spark by ldbc.

the class PostGenerator method createPosts.

public Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> createPosts(RandomGeneratorFarm randomFarm, final Forum forum, final List<ForumMembership> memberships, long numPostsInForum, Iterator<Long> idIterator, long blockId) {
    Properties properties = new Properties();
    properties.setProperty("type", "post");
    return memberships.stream().flatMap(member -> {
        // generate number of posts by this member
        double numPostsPerMember = numPostsInForum / (double) memberships.size();
        if (numPostsPerMember < 1.0) {
            double prob = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_POST).nextDouble();
            if (prob < numPostsPerMember)
                numPostsPerMember = 1.0;
        } else {
            numPostsPerMember = Math.ceil(numPostsPerMember);
        }
        final int numPostsPerMemberInt = (int) numPostsPerMember;
        // 0 to 20
        int numComments = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_COMMENT).nextInt(DatagenParams.maxNumComments + 1);
        return Streams.stream(Iterators.forIterator(0, i -> i < numPostsPerMemberInt, i -> ++i, i -> {
            // create post core
            PostCore postCore = generatePostInfo(randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_POST), randomFarm.get(RandomGeneratorFarm.Aspect.TAG), randomFarm.get(RandomGeneratorFarm.Aspect.DATE), forum, member, numComments);
            if (postCore == null)
                return Iterators.ForIterator.CONTINUE();
            // create content, county, ip - sometimes randomise
            String content = this.generator.generateText(member.getPerson(), postCore.getTags(), properties);
            int country = member.getPerson().getCountry();
            IP ip = member.getPerson().getIpAddress();
            Random random = randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_IP_FOR_TRAVELER);
            if (PersonBehavior.changeUsualCountry(random, postCore.getCreationDate())) {
                random = randomFarm.get(RandomGeneratorFarm.Aspect.COUNTRY);
                country = Dictionaries.places.getRandomCountryUniform(random);
                random = randomFarm.get(RandomGeneratorFarm.Aspect.IP);
                ip = Dictionaries.ips.getIP(random, country);
            }
            Post post = new Post();
            // create post with above information and from post info
            post.initialize(SN.formId(SN.composeId(idIterator.next(), postCore.getCreationDate()), blockId), postCore.getCreationDate(), postCore.getDeletionDate(), member.getPerson(), forum.getId(), content, new ArrayList<>(postCore.getTags()), country, ip, Dictionaries.browsers.getPostBrowserId(randomFarm.get(RandomGeneratorFarm.Aspect.DIFF_BROWSER), randomFarm.get(RandomGeneratorFarm.Aspect.BROWSER), member.getPerson().getBrowserId()), forum.getLanguage(), postCore.isExplicitlyDeleted());
            Stream<Like> likeStream = randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE).nextDouble() <= 0.1 ? likeGenerator.generateLikes(randomFarm.get(RandomGeneratorFarm.Aspect.DELETION_LIKES), randomFarm.get(RandomGeneratorFarm.Aspect.NUM_LIKE), forum, post, Like.LikeType.POST) : Stream.empty();
            Stream<Pair<Comment, Stream<Like>>> commentStream = commentGenerator.createComments(randomFarm, forum, post, numComments, idIterator, blockId);
            return Iterators.ForIterator.RETURN(new Triplet<>(post, likeStream, commentStream));
        }));
    });
}
Also used : IP(ldbc.snb.datagen.entities.dynamic.person.IP) java.util(java.util) Comment(ldbc.snb.datagen.entities.dynamic.messages.Comment) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) LikeGenerator(ldbc.snb.datagen.generator.generators.LikeGenerator) Dictionaries(ldbc.snb.datagen.generator.dictionary.Dictionaries) PersonBehavior(ldbc.snb.datagen.util.PersonBehavior) Pair(org.javatuples.Pair) CommentGenerator(ldbc.snb.datagen.generator.generators.CommentGenerator) Iterators(ldbc.snb.datagen.util.Iterators) RandomGeneratorFarm(ldbc.snb.datagen.util.RandomGeneratorFarm) Stream(java.util.stream.Stream) Triplet(org.javatuples.Triplet) DatagenParams(ldbc.snb.datagen.generator.DatagenParams) Like(ldbc.snb.datagen.entities.dynamic.relations.Like) Post(ldbc.snb.datagen.entities.dynamic.messages.Post) Forum(ldbc.snb.datagen.entities.dynamic.Forum) Streams(ldbc.snb.datagen.util.Streams) TextGenerator(ldbc.snb.datagen.generator.generators.textgenerators.TextGenerator) SN(ldbc.snb.datagen.generator.vocabulary.SN) Comment(ldbc.snb.datagen.entities.dynamic.messages.Comment) Post(ldbc.snb.datagen.entities.dynamic.messages.Post) Triplet(org.javatuples.Triplet) IP(ldbc.snb.datagen.entities.dynamic.person.IP) Stream(java.util.stream.Stream)

Aggregations

Forum (ldbc.snb.datagen.entities.dynamic.Forum)4 Like (ldbc.snb.datagen.entities.dynamic.relations.Like)4 Pair (org.javatuples.Pair)4 ForumMembership (ldbc.snb.datagen.entities.dynamic.relations.ForumMembership)3 java.util (java.util)2 Stream (java.util.stream.Stream)2 Comment (ldbc.snb.datagen.entities.dynamic.messages.Comment)2 Post (ldbc.snb.datagen.entities.dynamic.messages.Post)2 IP (ldbc.snb.datagen.entities.dynamic.person.IP)2 DatagenParams (ldbc.snb.datagen.generator.DatagenParams)2 Dictionaries (ldbc.snb.datagen.generator.dictionary.Dictionaries)2 TextGenerator (ldbc.snb.datagen.generator.generators.textgenerators.TextGenerator)2 SN (ldbc.snb.datagen.generator.vocabulary.SN)2 Iterators (ldbc.snb.datagen.util.Iterators)2 PersonBehavior (ldbc.snb.datagen.util.PersonBehavior)2 RandomGeneratorFarm (ldbc.snb.datagen.util.RandomGeneratorFarm)2 Streams (ldbc.snb.datagen.util.Streams)2 Triplet (org.javatuples.Triplet)2 ArrayList (java.util.ArrayList)1 Message (ldbc.snb.datagen.entities.dynamic.messages.Message)1