Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nitindhar7 committed Mar 31, 2011
0 parents commit 959eb63
Show file tree
Hide file tree
Showing 16 changed files with 109,428 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.layout
*.depend
bin
obj
92 changes: 92 additions & 0 deletions Query.cpp
@@ -0,0 +1,92 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include "lib/Query.h"
using namespace std;

Query::Query(string query)
{
text = query;
count = 0;
}

node* Query::open_list(Lexicon &lexicon, LexiconCursor &lexicon_cursor)
{
int offset = 0, doc_id = 0, frequency = 0;
string inverted_list;
stringstream parseable_inverted_list;
node* head = NULL;

offset = get_offset( lexicon, lexicon_cursor );
inverted_list = get_inverted_list( offset ); // remember to seek to beg after done

parseable_inverted_list << inverted_list;

while( parseable_inverted_list >> doc_id >> frequency ) {
node *temp, *temp2;

count++;

temp = new node;
temp->doc_id = doc_id;
temp->frequency = frequency;
temp->next = NULL;

if (head == NULL)
head = temp;
else {
temp2 = head;

while (temp2->next != NULL)
temp2 = temp2->next;

temp2->next = temp;
}
}

return head;
}

int Query::get_offset(Lexicon &lexicon, LexiconCursor &lexicon_cursor)
{
lexicon_cursor = lexicon.find( text );
return ( *lexicon_cursor ).second;
}

string Query::get_inverted_list(int offset)
{
string inverted_list;
ifstream inverted_index;

inverted_index.open( "structures/inverted_index" );
inverted_index.seekg( offset, ios::beg );
getline( inverted_index, inverted_list );
inverted_index.close();

return inverted_list;
}

/*
void Query::close_list(node* head)
{
free( head );
}
int Query::get_frequency(int document_id)
{
int doc_id = 0, frequency = 0;
string inverted_list;
stringstream parseable_inverted_list;
while( parseable_inverted_list >> doc_id >> frequency ) {
if( doc_id == document_id )
return frequency;
}
return 0;
}
*/
62 changes: 62 additions & 0 deletions QueryProcessor.cpp
@@ -0,0 +1,62 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <cmath>
#include "lib/QueryProcessor.h"

#define CONSTANT_K 1.2
#define CONSTANT_B 0.75
using namespace std;

QueryProcessor::QueryProcessor(int query_count, vector<Query> user_queries)
{
num_queries = query_count;
queries = user_queries;
}

/*int QueryProcessor::nextGEQ( node* list_head, int doc_id)
{
node* head = NULL;
head = list_head;
if( head->doc_id >= doc_id )
return doc_id;
else
head = head->next;
return -1;
}
double QueryProcessor::calculate_rank(int doc_id)
{
int total_pages, total_pages_with_queryword, freq_of_query_in_doc, doc_length;
double K, page_rank, log_result,freq_result,avg_doc_length;
K = CONSTANT_K* ( (1-CONSTANT_B) + ( CONSTANT_B * (doc_length/avg_doc_length) ) );
total_pages_with_queryword = Query.count();
freq_of_query_in_doc = Query.get_frequency();
log_result = log( (total_pages - freq_of_query_in_doc + 0.5) / ( freq_of_query_in_doc + 0.5) );
freq_result = ( ((CONSTANT_K+1) * total_pages_with_queryword) / (K+total_pages_with_queryword) );
page_rank = log_result * freq_result;
return page_rank;
}
string QueryProcessor::get_url(int doc_id)
{
url_table_iterator = kyon_url_table.find( doc_id );
return ( *url_table_iterator ).second.url;
}
void QueryProcessor::add_to_heap(string url, int doc_id)
{
//add url and doc_id
}
*/

0 comments on commit 959eb63

Please sign in to comment.