kerryrodden / tiny-tfidf

Minimal implementations of a couple of classic text analysis tools (TF-IDF and cosine similarity)
MIT License
56 stars 13 forks source link

Suggestion Corpus.addDocument(identifier, document) #4

Open krrishh-org opened 3 years ago

krrishh-org commented 3 years ago

It will be helpful to add Corpus.addDocument(identifier, document) for cases where the documents repository keeps growing over time.

idea-launch-lab commented 3 years ago

Following function may be added to the class Corpus to add documents after the Corpus has been instantiated:

  // Adds a document to the corpus
  addDocument(documentIdentifier, documentString) {
    this._documents.set(identifier, new Document(text, this._stopwords));
    this._calculateCollectionFrequencies();
    this._calculateCollectionFrequencyWeights();
    this._calculateDocumentVectors();
  }