Professional Documents
Culture Documents
Code:
1
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Output:
2
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical No:2 Java Code for Page Rank
Algorithm :
Code:
import java.util.*;
import java.io.*;
public class PageRank {
double InitialPageRank;
double OutgoingLinks=0;
double DampingFactor = 0.85;
double TempPageRank[] = new double[10];
int ExternalNodeNumber;
int InternalNodeNumber;
int k=1; // For Traversing
int ITERATION_STEP=1;
InitialPageRank = 1/totalNodes;
System.out.printf(" Total Number of Nodes :"+totalNodes+"\t Initial PageRank of
All Nodes :"+InitialPageRank+"\n");
3
Name : Kumar Vaibhav
Roll No: 4177 TYCS
}
while(ITERATION_STEP<=2) // Iterations
{
// Store the PageRank for All Nodes in Temporary Array
for(k=1;k<=totalNodes;k++)
{
TempPageRank[k]=this.pagerank[k];
this.pagerank[k]=0;
}
for(InternalNodeNumber=1;InternalNodeNumber<=totalNodes;InternalNodeNum
ber++)
{
for(ExternalNodeNumber=1;ExternalNodeNumber<=totalNodes;ExternalNodeNu
mber++)
{
if(this.path[ExternalNodeNumber][InternalNodeNumber] == 1)
{
k=1;
OutgoingLinks=0; // Count the Number of Outgoing Links for each
ExternalNodeNumber
while(k<=totalNodes)
{
if(this.path[ExternalNodeNumber][k] == 1 )
{
OutgoingLinks=OutgoingLinks+1; // Counter for Outgoing Links
}
k=k+1;
}
// Calculate PageRank
this.pagerank[InternalNodeNumber]+=TempPageRank[ExternalNodeNumber]*(1/
OutgoingLinks);
}
}
}
4
Name : Kumar Vaibhav
Roll No: 4177 TYCS
System.out.printf("\n After "+ITERATION_STEP+"th Step \n");
for(k=1;k<=totalNodes;k++)
System.out.printf(" Page Rank of "+k+" is :\t"+this.pagerank[k]+"\n");
ITERATION_STEP = ITERATION_STEP+1;
}
// Display PageRank
System.out.printf("\n Final Page Rank : \n");
for(k=1;k<=totalNodes;k++)
{
System.out.printf(" Page Rank of "+k+" is :\t"+this.pagerank[k]+"\n");
}
Output:
6
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical No-3
Implementing Dynamic Programming Algorithm for computing edit
distance between String s1 and s2.
a) Using Java
Code:
class EDIST
{
static int min(int x,int y,int z)
{
if (x<=y && x<=z) return x;
if (y<=x && y<=z) return y;
else return z;
}
// remaining strings.
if (str1.charAt(m-1) == str2.charAt(n-1))
return editDist(str1, str2, m-1, n-1);
7
Name : Kumar Vaibhav
Roll No: 4177 TYCS
// If last characters are not same, consider all three
8
Name : Kumar Vaibhav
Roll No: 4177 TYCS
B) Using Python
Code:
Output:
9
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical No-4
Program to compute similarity between two text
documents
Code:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
int lineNum = 1;
break;
10
Name : Kumar Vaibhav
Roll No: 4177 TYCS
}
else if(! line1.equalsIgnoreCase(line2))
{
areEqual = false;
break;
}
line1 = reader1.readLine();
line2 = reader2.readLine();
lineNum++;
}
if(areEqual)
{
System.out.println("Two files have same content.");
}
else
{
System.out.println("Two files have different content. They differ at line
"+lineNum);
reader1.close();
reader2.close();
}
}
11
Name : Kumar Vaibhav
Roll No: 4177 TYCS
File1.txt
File2.txt
12
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Output:
Different Content
Same Content
13
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-5
Write a map-reduce program to count the number of occurrences of each
alphabetic character in the given dataset. The count for each letter
should be case-insensitive (i.e., include both upper-case and lower-case
versions of the letter; Ignore non-alphabetic characters)
Code
Output:
14
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-6
Implement a basic IR system using Lucene
Code:
Output:
15
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-7
Write a program for Pre-processing of a Text Document: stop word
removal.
Code:
Output:
16
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-8
Write a program for mining Twitter to identify tweets for a
specific period and identify trends and named entities
Code:
Output:
17
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-9
Write a program to implement simple web crawler
Code:
Output:
18
Name : Kumar Vaibhav
Roll No: 4177 TYCS
Practical N0-10
Write a program to parse XML text, generate Web graph and
compute topic specific page rank.
Code:
Output:
19