0% found this document useful (0 votes)
12 views27 pages

ISR Code: Conflation and Clustering

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views27 pages

ISR Code: Conflation and Clustering

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name: Akshata Vishal Dongaonkar

Roll No.:45020
Div: BE-IT-A
Subject: ISR

1. Conflation Algorithm

import [Link]; import

[Link]; import

[Link]; import

[Link]; import

[Link];

import [Link];

import [Link];

import [Link]; import

[Link];

public class Conflation { public static ArrayList<String> stopList = new

ArrayList<String>(); public static ArrayList<String> removestopList = new

ArrayList<String>(); public static String suffixes[] = { "able", "ing", "ion",

"y", "ment" };

public static String stopwords[] = { "i", "big", "am", "m", "a", "we",

"are", "it", "of", "this", "and", "is", "to", "at", "in", "was",

"with", "doing", "It", "not", "our" };

public static void main(String[] args) {

InputStreamReader st = new InputStreamReader([Link]);

BufferedReader buff = new BufferedReader(st);

String fname = "";

[Link]("Enter a filename:");

try {
fname = [Link]();

} catch (IOException e) {

[Link]();

conflation(fname);

public static void conflation(String fname) {

BufferedReader buff;

int i = 0, j = 0;

try {

buff = new BufferedReader(new FileReader(fname));

int flag = 0;

String line = "";

line = [Link]();

String[] buffer = [Link](" ");

for (i = 0; i < [Link]; i++) {

flag = 0;

if (buffer[i].endsWith("."))

buffer[i] = buffer[i].replace(".", "");

for (j = 0; j < [Link]; j++) {

if (buffer[i].equals(stopwords[j])) {

[Link](buffer[i]);

flag = 1;

break;

if (flag != 1 && !buffer[i].equals(null)) {

[Link](buffer[i]);
}

[Link]("\n--------------After Removing Stop Words-----------------");

for (int k = 0; k < [Link](); k++) {

[Link]([Link](k));

suffixesString(removestopList);

countFrequency(removestopList);

} catch (FileNotFoundException e) {

[Link]();

} catch (IOException e) {

[Link]();

private static void countFrequency(ArrayList<String> removestopList2) {

// Mapping of String->Integer (word -> frequency)

[Link]("\n\n-------After Counting Frequency-----------"); final

Map<String, Integer> frequencyMap = new HashMap<String, Integer>(); for

(int k = 0; k < [Link](); k++) {

String currentWord = [Link](k);

Integer frequency = [Link](currentWord);

// Add the word if it doesn't already exist, otherwise increment the

// frequency counter.

if (frequency == null) {

frequency = 0;

[Link](currentWord, frequency + 1);


}

Iterator entries = [Link]().iterator();

while ([Link]()) {

[Link] entry = ([Link]) [Link]();

String key = (String) [Link]();

Integer value = (Integer) [Link]();

[Link](key + " = " + value);

private static void suffixesString(ArrayList<String> removestopList) {

[Link]("\n\n--------After Removing Suffixes------------"); for

(int k = 0; k < [Link](); k++) {

String suffixString = [Link](k);

int flag = 0;

for (int m = 0; m < [Link]; m++) {

if ([Link](suffixes[m])) {

int len = [Link]();

int len1 = suffixes[m].length();

int len2 = len - len1;

String sufString = [Link](0, len2);

[Link](suffixString + "\t\t");

[Link](sufString);

flag = 1;

break;

if (flag != 1)

[Link](suffixString + "\t\t" + suffixString);

}
}

Output:
2. Single Pass Algorithm
import [Link];

import [Link]; import

[Link]; import

[Link];

public class Singlepass { public static void main(String[]

args) throws IOException {

BufferedReader stdInpt = new BufferedReader(new InputStreamReader([Link]));

[Link]("Enter the no of Tokens"); int noOfDocuments =

[Link]([Link]()); [Link]("Enter the no of

Documents"); int noOfTokens = [Link]([Link]());

[Link]("Enter the threshhold"); float threshhold =

[Link]([Link]()); [Link]("Enter the Document

Token Matrix"); int[][] input = new int[noOfDocuments][noOfTokens]; for

(int i = 0; i < noOfDocuments; ++i) { for (int j = 0; j < noOfTokens; ++j) {

[Link]("Enter(" + i + "," + j + ")");

input[i][j] = [Link]([Link]());

SinglePassAlgorithm(noOfDocuments, noOfTokens, threshhold, input);

private static void SinglePassAlgorithm(int noOfDocuments, int noOfTokens,float threshhold, int[][]


input) {
int[][] cluster = new int[noOfDocuments][noOfDocuments + 1];

ArrayList<Float[]> clusterRepresentative = new ArrayList<Float[]>();

cluster[0][0] = 1; cluster[0][1] = 0; int noOfClusters = 1;

Float[] temp = new Float[noOfTokens];

temp = convertintArrToFloatArr(input[0]);

[Link](temp); for (int i

= 1; i < noOfDocuments; ++i) {

float max = -1; int clusterId = -1; for (int j = 0; j < noOfClusters; ++j) { float similarity

= calculateSimilarity( convertintArrToFloatArr(input[i]),[Link](j));

if (similarity > threshhold) {

if (similarity > max) {

max = similarity;

clusterId = j;

if (max == -1) {

cluster[noOfClusters][0] = 1;

cluster[noOfClusters][1] = i;

noOfClusters++;

[Link](convertintArrToFloatArr(input[i]));

} else { cluster[clusterId][0] +=

1; int index = cluster[clusterId][0];

cluster[clusterId][index] = i;

[Link](clusterId,

calculateClusterRepresentative(cluster[clusterId],

input, noOfTokens));

}
for (int i = 0; i < noOfClusters; ++i) {

[Link]("\n" + i + "\t");

for (int j = 1; j <= cluster[i][0]; ++j) {

[Link](" " + cluster[i][j]);

/* This function convert input integer array into float array.*/ private

static Float[] convertintArrToFloatArr(int[] input) {

int size = [Link];

Float[] answer = new Float[size];

for (int i = 0; i < [Link]; ++i) {

answer[i] = (float) input[i];

return answer;

/**

* This function calculate the similarity value.

* Formula= answer =answer+ a[i]*b[i]

*/ private static float calculateSimilarity(Float[] a, Float[]

b) {

float answer = 0;

for (int i = 0; i < [Link]; ++i) {

answer += a[i] * b[i];

return answer;

/* This function calculates the centroid value.*/ private static

Float[] calculateClusterRepresentative(int[] cluster,


int[][] input, int noOFTokens) {

Float[] answer = new Float[noOFTokens]; for

(int i = 0; i < noOFTokens; ++i) {

answer[i] = [Link]("0");

for (int i = 1; i <= cluster[0]; ++i) {

for (int j = 0; j < noOFTokens; ++j) {

answer[j] += input[cluster[i]][j];

for (int i = 0; i < noOFTokens; ++i) {

answer[i] /= cluster[0];

return answer;

Output:
3. Inverted File
import [Link];

import [Link];

import [Link]; import

[Link]; import

[Link]; import

[Link]; import

[Link];

public class InvertedFile { public static void

displayIndex(ArrayList<String> invertedData,

int[][] docno) {

int i, j;

for (i = 0; i < [Link](); i++) {

[Link]([Link](i) + "\t"); for (j = 1; j <=

docno[i][0]; j++)

[Link](docno[i][j] + "\t");

[Link]("\n");

public static void indexing(String fname, ArrayList<String> invertedData,int[][] docno, int fileno) {

BufferedReader br;

try {

br = new BufferedReader(new FileReader(fname));

String data = "", line = [Link]();

while (line != null) {

data += line + " ";

line = [Link]();

}
String[] st = [Link]("[ ,.]");

String currenttoken = null;

int i = 0;

while (i < [Link]) {

currenttoken = st[i];

int indx = [Link](currenttoken);

if (indx == -1) {

[Link](currenttoken);

indx = [Link](currenttoken);

docno[indx][0] = 1;

docno[indx][1] = fileno;

} else {

docno[indx][docno[indx][0] + 1] = fileno;

docno[indx][0] += 1;

i += 1;

} catch (Exception e) {

[Link]();

public static void main(String[] args) throws NumberFormatException,

IOException {

String fname = "";

ArrayList<String> invertedData = new ArrayList<String>();

int docno[][] = new int[100][10];

InputStreamReader ins = new InputStreamReader([Link]);


BufferedReader br = new BufferedReader(ins);

[Link]("\nENTER TOTAL NO OF FILES:"); int no

= [Link]([Link]());

int i = 1;

while (i - 1 != no) {

[Link]("\nENTER FILE " + i + " NAME:");

fname = [Link]();

indexing(fname, invertedData, docno, i);

i += 1;

displayIndex(invertedData, docno);

Output:
4. Precision And Recall

import [Link]; import

[Link];

public class PrecisionRecallCalculator {

public static void main(String[] args) {

// Sample input: Answer set A, Query q1, and Relevant documents Rq1

Set<String> answerSetA = new HashSet<>(); [Link]("Doc1");

[Link]("Doc2"); [Link]("Doc3");

[Link]("Doc4"); [Link]("Doc5");

Set<String> relevantDocumentsRq1 = new HashSet<>();

[Link]("Doc1"); [Link]("Doc2");

[Link]("Doc3");

// Query q1

String query = "q1";

// Calculate precision and recall

double precision = calculatePrecision(answerSetA, relevantDocumentsRq1);

double recall = calculateRecall(answerSetA, relevantDocumentsRq1);

// Print the results

[Link]("Query: " + query);

[Link]("Precision: " + precision);

[Link]("Recall: " + recall);

}
// Calculate precision

public static double calculatePrecision(Set<String> retrievedDocuments, Set<String>


relevantDocuments) {

int relevantRetrieved = 0;

for (String doc : retrievedDocuments) {

if ([Link](doc)) {

relevantRetrieved++;

return (double) relevantRetrieved / [Link]();

// Calculate recall

public static double calculateRecall(Set<String> retrievedDocuments, Set<String>


relevantDocuments) {

int relevantRetrieved = 0;

for (String doc : retrievedDocuments) {

if ([Link](doc)) {

relevantRetrieved++;

return (double) relevantRetrieved / [Link]();

Output:
5. Harmonic Mean

package [Link];

public class MetricsCalculator

public static double calculateF1(double precision, double recall)

{ if (precision + recall == 0) { return 0;

} return 2 * (precision * recall) / (precision +

recall);

public static double calculateEMeasure(double precision, double recall,

double alpha) { if (precision == 0 && recall == 0) {

return 0;

} return 1 / ((alpha / precision) + ((1 - alpha) /

recall));

} public static void main(String[]

args) {

// Example values

double precision = 0.75;

double recall = 0.80;

double alpha = 0.5;

// Calculate F-measure double f1Score =

calculateF1(precision, recall);

[Link]("F-measure (F1-score): " + [Link]("%.2f",


f1Score));

// Calculate E-measure double eMeasure =

calculateEMeasure(precision, recall, alpha);

[Link]("E-measure: " + [Link]("%.2f", eMeasure));


}

Output :
6. Feature Extraction
7. Web Crowler
8. Weather Forecasting

Common questions

Powered by AI

Suffix removal, as applied in the document's Conflation algorithm, contributes to text data normalization by reducing words to a common base form, or root. This process—known as stemming—removes common suffixes like 'ing', 'able', 'ion', 'y', and 'ment' from words, thereby minimizing word variants. By converting different forms of a word to a standard version, suffix removal helps in creating a consistent vocabulary for text analysis. It enhances the effectiveness of text matching processes and reduces redundancy in text databases, improving both data management and retrieval efficiency .

Precision and Recall are critical metrics for evaluating the performance of information retrieval systems. Precision measures the accuracy of the retrieved documents by calculating the ratio of relevant documents retrieved to the total retrieved documents. Recall measures the system’s ability to retrieve all relevant documents by calculating the ratio of relevant documents retrieved to the total relevant documents available. These metrics are calculated by comparing the set of documents retrieved by a system against a set of known relevant documents. High Precision indicates most retrieved documents are relevant, while high Recall indicates that most of the relevant documents are retrieved. Calculating these helps in assessing the effectiveness of retrieval algorithms .

The F1-score is an important metric in evaluating classification systems because it balances both Precision and Recall, providing a single score to encapsulate both accuracy and completeness. It is calculated as the harmonic mean of Precision and Recall, given by the formula: F1 = 2 * (Precision * Recall) / (Precision + Recall). This score ranges from 0 to 1, with 1 being the best F1-score, indicating perfect balance between the two metrics. Its importance lies in its ability to provide a single measure of a model’s performance, especially in cases where one metric may be undesirably high or low compared to the other .

The Conflation algorithm is used in text processing to reduce words to their base or root form. This algorithm removes stop words—commonly used words in a language that are ignored in text processing—by comparing each word in a text against a predefined list of stop words. After identifying these stop words, the algorithm adds them to a 'stopList' and the non-stop words to a 'removestopList'. It then proceeds to trim suffixes from the words in the 'removestopList' through a comparison against a predefined array of suffixes such as 'able', 'ing', 'ion', 'y', and 'ment'. If a word ends with one of these suffixes, the suffix is removed to standardize the word form .

The Single Pass algorithm identifies clusters by calculating the similarity between a document and existing cluster representatives. For each document, the algorithm calculates its similarity with each cluster's representative using a specified threshold. If the similarity is greater than the threshold and maximizes the similarity among clusters, the document is added to that cluster. If no suitable cluster is found (i.e., similarity scores do not exceed the threshold), a new cluster is created with the document as its initial member. New clusters are formed based on the lack of significant similarity to existing clusters, determined through comparative similarity calculations .

When a new document is added to an existing cluster in the Single Pass Algorithm, the algorithm updates the cluster representative by recalculating the centroid of the cluster. This involves averaging the values for each feature across all documents in the cluster, including the newly added document. The cluster representative, initially calculated as the average of document vectors, is updated by adding the feature vector of the new document to the existing sum of vectors and dividing by the total number of documents in the cluster. This ensures the cluster representative’s feature vector reflects the characteristics of all included documents .

The E-measure is a performance metric used in information retrieval to account for user preference bias between precision and recall. It is calculated using the formula: E = 1 / ((α / Precision) + ((1 - α) / Recall)), where α is a parameter between 0 and 1 indicating the weight given to precision over recall and vice versa. This metric provides a composite measure that balances precision and recall according to the specific retrieval needs or user priorities, allowing for a customizable evaluation of system performance. Its significance lies in enabling more user-centered performance assessments by adapting to different informational contexts .

Implementing an inverted index in large-scale systems presents computational challenges, such as high storage requirements and need for efficient real-time updates. Given the large volume of documents, maintaining comprehensive lists of term occurrences can demand significant memory. This can also slow down indexing processes and query responses. To mitigate these challenges, systems may use distributed storage solutions like Apache Hadoop or cloud-based services to manage data across multiple nodes. Additionally, using compressed data formats and heuristic indexing strategies can reduce storage demand. Partitioning the index and using in-memory caching could also improve retrieval speed and efficiency .

Feature extraction supports information retrieval and data analysis by transforming raw data into informative and non-redundant forms that facilitate pattern recognition and enhance data interpretation. By identifying key attributes and characteristics of data, feature extraction reduces dimensionality, which simplifies further computational analysis and improves the efficiency of machine learning algorithms. This process assists in focusing on the most relevant data aspects, enhancing the system’s capacity to extract meaning and make accurate predictions or classifications based on the refined dataset. It allows for more effective indexing, retrieval, and analysis, contributing to improved decision-making and strategic insights in data-driven applications .

An 'Inverted File' is a data structure used in information retrieval systems to map content to its locations in a set of documents. It allows for efficient query processing by maintaining a list (or index) of terms and their occurrences in documents. In the given implementation, the program reads text from files and breaks it into tokens. Each token is checked against an existing list of inverted data; if it's new, the token is added, and its document number is recorded. If a token already exists, the document number is appended to the corresponding list of document numbers, helping to create a mapping of tokens to documents .

You might also like