-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
document paths on disk, adjusted tfidf scoring
- Loading branch information
Showing
6 changed files
with
99 additions
and
52 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
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
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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
use crate::disk::{bits_reader::BitsReader, bits_writer::BitsWriter}; | ||
|
||
use super::DOCUMENT_LENGHTS_EXTENSION; | ||
use super::DOCUMENTS_EXTENSION; | ||
|
||
pub fn write_doc_lentghts(document_lenghts: &Vec<u32>, output_path: &str) { | ||
let doc_path = output_path.to_string() + DOCUMENT_LENGHTS_EXTENSION; | ||
#[derive(Clone)] | ||
pub struct Document { | ||
pub path: String, | ||
pub lenght: u32, | ||
} | ||
|
||
pub fn write_documents(documents: &Vec<Document>, output_path: &str) { | ||
let doc_path = output_path.to_string() + DOCUMENTS_EXTENSION; | ||
let mut doc_writer = BitsWriter::new(&doc_path); | ||
|
||
doc_writer.write_vbyte(document_lenghts.len() as u32); | ||
document_lenghts.iter().for_each(|l| { | ||
doc_writer.write_gamma(*l); | ||
doc_writer.write_vbyte(documents.len() as u32); | ||
documents.iter().for_each(|l| { | ||
doc_writer.write_str(&l.path); | ||
doc_writer.write_vbyte(l.lenght); | ||
}); | ||
|
||
doc_writer.flush(); | ||
} | ||
|
||
pub fn load_document_lenghts(input_path: &str) -> Vec<u32> { | ||
let mut reader = BitsReader::new(&(input_path.to_string() + DOCUMENT_LENGHTS_EXTENSION)); | ||
reader.read_vbyte_gamma_vector() | ||
pub fn load_documents(input_path: &str) -> Vec<Document> { | ||
let mut reader = BitsReader::new(&(input_path.to_string() + DOCUMENTS_EXTENSION)); | ||
|
||
(0..reader.read_vbyte()) | ||
.map(|_| Document { | ||
path: reader.read_str(), | ||
lenght: reader.read_vbyte(), | ||
}) | ||
.collect() | ||
} |
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
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
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