Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 959eb63
Showing
16 changed files
with
109,428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.layout | ||
*.depend | ||
bin | ||
obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
*/ |
Oops, something went wrong.