A complete implementation of the Extended Boolean Model (EBM) for Information Retrieval with DeMorgan AND and OR operators (p=2).
- ✅ Extended Boolean Model with p=2 (Euclidean distance)
- ✅ DeMorgan AND formula implementation
- ✅ OR formula implementation
- ✅ TF-IDF weighting with normalization
- ✅ Query parser supporting AND, OR, NOT, and parentheses
- ✅ Interactive Streamlit GUI
- ✅ Step-by-step calculation display
- ✅ Document ranking with tie-breaking
- ✅ Gemini API comparison - Compare local results with Gemini API rankings
- ✅ Visual difference highlighting and statistics
- Install dependencies:
pip install -r requirements.txtstreamlit run streamlit_app.pyThe app will open in your browser at http://localhost:8501
bird AND cat- Documents containing both bird and catdog OR tiger- Documents containing dog or tiger(bird OR cat) AND dog- Complex query with groupingNOT tiger- Documents without tiger
tf(t, d_j) = freq(t, d_j) / max_u freq(u, d_j)
idf(t) = log10(N / n_t)
idf_norm(t) = idf(t) / max_v idf(v)
W_t,j = tf(t, d_j) × idf_norm(t)
sim(q_AND, d_j) = 1 - sqrt(Σ(1 - W_i,j)² / n)
sim(q_OR, d_j) = sqrt(Σ(W_i,j²) / n)
The system includes 15 documents with 4 keywords: bird, cat, dog, tiger
- D1: [bird, cat, bird, cat, dog, dog, bird]
- D2: [cat, tiger, cat, dog]
- D3: [dog, bird, bird]
- ... (see streamlit_app.py for full corpus)
base_model.py- Extended Boolean Model implementationquery_parser.py- Boolean query parserstreamlit_app.py- Interactive GUI applicationrequirements.txt- Python dependenciesapp.py- Original Gemini API test (legacy)
EBM/
├── base_model.py # Core EBM logic
├── query_parser.py # Query parsing & tree construction
├── streamlit_app.py # GUI application
├── requirements.txt # Dependencies
├── README.md # This file
└── app.py # Legacy API test
- Document Corpus Display - View all 15 documents in sidebar
- Query Input - Enter Boolean queries with natural syntax
- TF Calculation - See term frequency for each document
- IDF Calculation - View inverse document frequency values
- IDF Normalization - See normalized IDF values
- Weight Matrix - Complete W_t,j values for all terms/documents
- Similarity Scores - Computed similarity for each document
- Final Ranking - Documents ranked by similarity (ties broken by document ID)
- Export Results - Download rankings as CSV or JSON
- 🆕 Gemini API Comparison - Compare local results with Gemini API rankings side-by-side
Compare your local EBM results with Gemini API rankings to validate calculations and identify differences.
Quick Start:
- Run
python app.pyto get Gemini results - Run
python extract_gemini_ranking.pyto extract JSON - Paste JSON into the Streamlit GUI comparison section
See GEMINI_COMPARISON.md for detailed instructions.
Information Retrieval System - Extended Boolean Model Implementation