Skip to content

meta data version of the code where documents are chunked and tagged by year and page number #218

Answered by anujcb
anujcb asked this question in Q&A
Discussion options

You must be logged in to vote

const groupDocumentsByYear = (documents) => {
const groups = new Map();
for (const doc of documents) {
try {
console.log('Processing document:', doc.metadata.source);
//const year = doc.filepath.split('/')[1];
console.log('Processing doc before year:', doc.metadata.source.replace(///g, '\'));
const year = doc.metadata.source.replace(///g, '\').split('\')[9];
console.log('Processing doc year:', year);
const docs = groups.get(year) || [];
docs.push(doc);
groups.set(year, docs);
} catch (error) {
console.log(Error occurred while grouping ${doc.filepath}: ${error});
}
}
return groups;
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@report2model
Comment options

Answer selected by anujcb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants