You are on page 1of 22

MUTUAL FREINDS

GROUP MEMBERS:

AMAR KESHRI,TECHNO INDIA SALTLAKE,151300110134

CHINTAN LAKHLANI,TECHNO INDIA SALTLAKE,151300110156

DHEERAJ KUMAR PANDEY,TECHNO INDIA SALTLAKE,151300110158

HIMANSHI SINGH,TECHNO INDIA SALTLAKE,141300110643

ABHINAV BIKASH, INSTITUTE OF ENGINEERING & MANAGEMENT,151040110004

ANKIT KUMAR, INSTITUTE OF ENGINEERING & MANAGEMENT,151040110035

Document sign date :Feb 26, 2018


Table of Contents

Project Objective ........................................................ Error! Bookmark not defined.

Project Scope ............................................................. Error! Bookmark not defined.

Database Design ......................................................... Error! Bookmark not defined.

Application Work Flow ................................................ Error! Bookmark not defined.

Future Scope of Improvements .................................. Error! Bookmark not defined.

Code ............................................................................ Error! Bookmark not defined.

Project Certificate.......................................................................................23

Document sign date :Feb 26, 2018


ACKNOWLEDGEMENT

I take this opportunity to express my profound gratitude and deep


regards to my faculty Professor Titas RoyChowdhury for his exemplary
guidance, monitoring and constant encouragement throughout the
course of this project. The blessing, help and guidance given by
him/her time to time shall carry me a long way in the journey of life
on which I am about to embark.

I am obliged to my project team members for the valuable


information provided by them in their respective fields. I am grateful
for their cooperation during the period of my assignment.

AMAR KESHRI

ABHINAV BIKASH

ANKIT KUMAR

DHEERAJ KUMAR PANDEY

CHINTAN LAKHLANI

HIMANSHI SINGH

Document sign date :Feb 26, 2018


PROJECT OBJECTIVE

Manually accounting for all factors associated with a


mutual friend poses an intractable
challenge. This research uses concept of big data to
these factors. The goal of creating this system is to help
people in finding their friends, relatives and close ones
very easily on different social websites. Based on the
data provided , I designed and implemented a Big data
and hadoop system that aims to provide an
instant indicator to help people.

Document sign date :Feb 26, 2018


APPLICATION WORKFLOW

Document sign date :Feb 26, 2018


Document sign date :Feb 26, 2018
SCREENSHOTS

Fig 1:Output(no of mutual friends for each user)

Document sign date :Feb 26, 2018


Fig 2:Mapping in progress

Fig 4:Job Completion

Document sign date :Feb 26, 2018


FUTURE SCOPE OF IMPROVEMENT

The study found that the social network’s mutual friends feature
“creates myriad security risks and privacy concerns,” adding that
even though users can adjust their privacy settings, hackers can
still access information that is intended to be private. With such a
huge user base in such systems, a minor privacy breach can have a
significant impact. It is important to understand all possible privacy
threats to users of social networking sites so that appropriate
mechanisms can be developed. This work of ours is an effort to
comprehensively understand such threats related to the mutual-
friend feature so that appropriate measures can be taken. In future
we need to develop such technology that will breach the privacy of
any user.

Document sign date :Feb 26, 2018


CODES

#IMPORTING PACKAGES

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.io.Writable;

import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.Mapper;

import org.apache.hadoop.mapreduce.Reducer;

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.DataInput;

import java.io.DataOutput;

import java.io.IOException;

import java.util.*;

public class FriendRecommendation {

static public class FriendCountWritable implements Writable {

Document sign date :Feb 26, 2018


public Long user;

public Long mutualFriend;

public FriendCountWritable(Long user, Long mutualFriend) {

this.user = user;

this.mutualFriend = mutualFriend;

public FriendCountWritable() {

this(-1L, -1L);

@Override

public void write(DataOutput out) throws IOException {

out.writeLong(user);

out.writeLong(mutualFriend);

@Override

public void readFields(DataInput in) throws IOException {

user = in.readLong();

mutualFriend = in.readLong();

@Override

public String toString() {

return " toUser: "

Document sign date :Feb 26, 2018


+ Long.toString(user) + " mutualFriend: " +
Long.toString(mutualFriend);

#MAPPER CLASS

public static class Map extends Mapper<LongWritable, Text, LongWritable,


FriendCountWritable> {

private Text word = new Text();

@Override

public void map(LongWritable key, Text value, Context context) throws


IOException, InterruptedException {

String line[] = value.toString().split("\t");

Long fromUser = Long.parseLong(line[0]);

List<Long> toUsers = new ArrayList<Long>();

if (line.length == 2) {

StringTokenizer tokenizer = new StringTokenizer(line[1], ",");

while (tokenizer.hasMoreTokens()) {

Long toUser = Long.parseLong(tokenizer.nextToken());

toUsers.add(toUser);

context.write(new LongWritable(fromUser), new


FriendCountWritable(toUser, -1L));

for (int i = 0; i < toUsers.size(); i++) {

for (int j = i + 1; j < toUsers.size(); j++) {

Document sign date :Feb 26, 2018


context.write(new LongWritable(toUsers.get(i)), new
FriendCountWritable((toUsers.get(j)), fromUser));

context.write(new LongWritable(toUsers.get(j)), new


FriendCountWritable((toUsers.get(i)), fromUser));

#REDUCER CLASS

public static class Reduce extends Reducer<LongWritable,


FriendCountWritable, LongWritable, Text> {

@Override

public void reduce(LongWritable key, Iterable<FriendCountWritable> values,


Context context)

throws IOException, InterruptedException {

// key is the recommended friend, and value is the list of mutual friends

final java.util.Map<Long, List<Long>> mutualFriends = new


HashMap<Long, List<Long>>();

for (FriendCountWritable val : values) {

final Boolean isAlreadyFriend = (val.mutualFriend == -1);

final Long toUser = val.user;

final Long mutualFriend = val.mutualFriend;

if (mutualFriends.containsKey(toUser)) {

if (isAlreadyFriend) {

Document sign date :Feb 26, 2018


mutualFriends.put(toUser, null);

} else if (mutualFriends.get(toUser) != null) {

mutualFriends.get(toUser).add(mutualFriend);

} else {

if (!isAlreadyFriend) {

mutualFriends.put(toUser, new ArrayList<Long>() {

add(mutualFriend);

});

} else {

mutualFriends.put(toUser, null);

java.util.SortedMap<Long, List<Long>> sortedMutualFriends = new


TreeMap<Long, List<Long>>(new Comparator<Long>() {

@Override

public int compare(Long key1, Long key2) {

Integer v1 = mutualFriends.get(key1).size();

Integer v2 = mutualFriends.get(key2).size();

if (v1 > v2) {

return -1;

} else if (v1.equals(v2) && key1 < key2) {

return -1;

Document sign date :Feb 26, 2018


} else {

return 1;

});

for (java.util.Map.Entry<Long, List<Long>> entry :


mutualFriends.entrySet()) {

if (entry.getValue() != null) {

sortedMutualFriends.put(entry.getKey(), entry.getValue());

Integer i = 0;

String output = "";

for (java.util.Map.Entry<Long, List<Long>> entry :


sortedMutualFriends.entrySet()) {

if (i == 0) {

output = entry.getKey().toString() + " (" + entry.getValue().size() + ": "


+ entry.getValue() + ")";

} else {

output += "," + entry.getKey().toString() + " (" + entry.getValue().size()


+ ": " + entry.getValue() + ")";

++i;

context.write(key, new Text(output));

Document sign date :Feb 26, 2018


}

#DRIVER CLASS

Public class Driver{

public static void main(String[] args) throws Exception {

Configuration conf = new Configuration();

Job job = new Job(conf, "FriendRecommendation");

job.setJarByClass(FriendRecommendation.class);

job.setOutputKeyClass(LongWritable.class);

job.setOutputValueClass(FriendCountWritable.class);

job.setMapperClass(Map.class);

job.setReducerClass(Reduce.class);

job.setInputFormatClass(TextInputFormat.class);

job.setOutputFormatClass(TextOutputFormat.class);

FileSystem outFs = new Path(mfout).getFileSystem(conf);

outFs.delete(new Path(mfout), true);

FileInputFormat.addInputPath(job, new Path(mfin));

FileOutputFormat.setOutputPath(job, new Path(mfout));

job.waitForCompletion(true);

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Mr AMAR KESHRI of TECHNO INDIA

SALTLAKE, registration number: 151300110134 has successfully

completed a project on MUTUAL FRIENDS DETECTION using BIG

DATAA(HADOOP) under the guidance of Mr TITAS ROYCHOWDHURY.

[ AMAR KESHRI]
Globsyn Finishing School

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Mr ABHINAV BIKASH of INSTITUTE OF

ENGINEERING & MANAGEMENT, registration number:

151040110004 has successfully completed a project on MUTUAL

FRIENDS DETECTION using BIG DATAA(HADOOP) under the

guidance of Mr TITAS ROYCHOWDHURY.

[ ABHINAV BIKASH ]
Globsyn Finishing School

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Mr ANKIT KUMAR of INSTITUTE OF

ENGINEERING & MANAGEMENT, registration number:

151040110035 has successfully completed a project on MUTUAL

FRIENDS DETECTION using BIG DATAA(HADOOP) under the

guidance of Mr TITAS ROYCHOWDHURY.

[ ANKIT KUMAR ]
Globsyn Finishing School

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Mr DHEERAJ KUMAR PANDEY of TECHNO

INDIA SALTLAKE, registration number: 151300110158 has

successfully completed a project on MUTUAL FRIENDS DETECTION

using BIG DATAA(HADOOP) under the guidance of Mr TITAS

ROYCHOWDHURY.

[ DHEERAJ KUMAR PANDEY]


Globsyn Finishing School

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Miss HIMANSHI SINGH of TECHNO INDIA

SALTLAKE, registration number: 141300110643 has successfully

completed a project on MUTUAL FRIENDS DETECTION using BIG

DATAA(HADOOP) under the guidance of Mr TITAS ROYCHOWDHURY.

[ HIMANSHI SINGH ]
Globsyn Finishing School

Document sign date :Feb 26, 2018


CERTIFICATE

This is to certify that Mr CHINTAN LAKHLANI of TECHNO INDIA

SALTLAKE, registration number: 151300110156 has successfully

completed a project on MUTUAL FRIENDS DETECTION using BIG

DATAA(HADOOP) under the guidance of Mr TITAS ROYCHOWDHURY.

[ CHINTAN LAKHLANI ]
Globsyn Finishing School

Document sign date :Feb 26, 2018

You might also like