Updating the component and the service
In order to respond to the Calculate IDF button inside the template, all we need to do in the component is catch the click event and call the related function from the service. So just add the onIDFs() function as follow:
// src/app/evidence/evidence.component.ts // ... export class EvidenceComponent implements OnInit{ // ... onIDFs() { this.evidenceService.saveIDFs(); } }
However, on the service side, we have a lot of work to do. We can summarize the required steps for IDF calculations as follow:
Remove previous IDF calculations: every time a new article is added to the corpus, it makes all previous IDF calculations invalid, so we need to erase them before starting the new calculations.
Loop through articles and gather all unique words by looking into bag of words for each article. This will be a corpus-level bag of words or a bag of words made out of all available bags of words if you like.
Loop through unique words and find the number...