Last updated:
0 purchases
flutter tf idf
flutter_tf_idf #
A Dart package for calculating TF-IDF (Term Frequency-Inverse Document Frequency) and performing text analysis tasks in Flutter applications.
Features #
Calculate TF-IDF matrix for a collection of documents
Compute cosine similarity and distance between documents
Retrieve top terms for a specific document
Search documents based on a query
Get TF-IDF scores for specific terms and documents
Find the highest-scoring document for a given term
Getting Started #
Add flutter_tf_idf to your pubspec.yaml:
dependencies:
flutter_tf_idf: ^1.0.0
copied to clipboard
Then run: #
flutter pub get
Import: #
import 'package:flutter_tf_idf/flutter_tf_idf.dart';
Usage: #
Create a TfIdf instance with a list of documents: #
var documents = [
Document('doc1', 'This is a sample document'),
Document('doc2', 'Another example document'),
Document('doc3', 'A third document for demonstration'),
];
final tfIdf = TfIdf(documents);
copied to clipboard
Calculate Cosine Similarity: #
double similarity = tfIdf.calculateCosineSimilarity('doc1', 'doc2');
print('Cosine similarity between doc1 and doc2: $similarity');
copied to clipboard
Calculate Cosine Distance #
double distance = tfIdf.calculateCosineDistance('doc1', 'doc2');
print('Cosine distance between doc1 and doc2: $distance');
copied to clipboard
Get Top Terms for a Document #
List<String> topTerms = tfIdf.getTopTerms('doc1', 5);
print('Top 5 terms in doc1: $topTerms');
copied to clipboard
Search Documents #
List<String> searchResults = tfIdf.searchDocuments('first document', 2);
print('Top 2 documents matching "first document": $searchResults');
copied to clipboard
Get TF-IDF Score #
double score = tfIdf.getTfIdfScore('document', 'doc2');
print('TF-IDF score of "document" in doc2: $score');
copied to clipboard
Get Highest Scoring Document for a Term #
String docId = tfIdf.getHighestScoringDocument('third');
print('Document with highest score for "third": $docId');
copied to clipboard
Print TF-IDF Matrix #
tfIdf.printTfIdfMatrix();
copied to clipboard
Additional information #
For more information on how to use this package, please refer to the API documentation and the example provided in the example/main.dart file.
Author #
This package is developed and maintained by Jahangir Jehad.
Show Your Support #
If you find this package helpful, please consider giving it a star on GitHub. Your support helps to make this project more visible to others who might benefit from it.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.