-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
237 lines (200 loc) · 5.33 KB
/
setup.sh
File metadata and controls
237 lines (200 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash
# Search Ranking System - Complete Setup Script
# This script sets up the entire project from scratch
set -e # Exit on error
echo "=================================================="
echo " Search Ranking System - Automated Setup"
echo "=================================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_info() {
echo -e "${YELLOW}ℹ $1${NC}"
}
# Check Python version
echo "Checking Python version..."
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}')
REQUIRED_VERSION="3.8"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" = "$REQUIRED_VERSION" ]; then
print_success "Python $PYTHON_VERSION detected"
else
print_error "Python 3.8+ is required. Found: $PYTHON_VERSION"
exit 1
fi
# Create directory structure
echo ""
echo "Creating directory structure..."
mkdir -p src/rankers
mkdir -p src/features
mkdir -p src/evaluation
mkdir -p src/ab_testing
mkdir -p src/api
mkdir -p data
mkdir -p models
mkdir -p tests
mkdir -p scripts
mkdir -p demo/templates
mkdir -p notebooks
print_success "Directories created"
# Create __init__.py files
echo ""
echo "Creating Python package files..."
# src/__init__.py
cat > src/__init__.py << 'EOF'
"""Search Relevance & Ranking System"""
__version__ = "1.0.0"
EOF
# src/rankers/__init__.py
cat > src/rankers/__init__.py << 'EOF'
"""Ranking algorithms module"""
from .tfidf_ranker import TFIDFRanker
from .bm25_ranker import BM25Ranker
from .lambdamart_ranker import LambdaMARTRanker
__all__ = ['TFIDFRanker', 'BM25Ranker', 'LambdaMARTRanker']
EOF
# src/features/__init__.py
cat > src/features/__init__.py << 'EOF'
"""Feature extraction module"""
from .feature_extractor import FeatureExtractor
__all__ = ['FeatureExtractor']
EOF
# src/evaluation/__init__.py
cat > src/evaluation/__init__.py << 'EOF'
"""Evaluation metrics module"""
from .metrics import RankingMetrics
__all__ = ['RankingMetrics']
EOF
# src/ab_testing/__init__.py
cat > src/ab_testing/__init__.py << 'EOF'
"""A/B testing framework module"""
from .experiment import ABTestExperiment, ABTestManager
__all__ = ['ABTestExperiment', 'ABTestManager']
EOF
# src/api/__init__.py
cat > src/api/__init__.py << 'EOF'
"""API module"""
from .app import app
__all__ = ['app']
EOF
# tests/__init__.py
cat > tests/__init__.py << 'EOF'
"""Test suite"""
EOF
# Create .gitkeep files
touch data/.gitkeep
touch models/.gitkeep
print_success "Package files created"
# Create virtual environment
echo ""
echo "Creating virtual environment..."
if [ -d "venv" ]; then
print_info "Virtual environment already exists"
else
python3 -m venv venv
print_success "Virtual environment created"
fi
# Activate virtual environment
echo ""
echo "Activating virtual environment..."
source venv/bin/activate
print_success "Virtual environment activated"
# Upgrade pip
echo ""
echo "Upgrading pip..."
pip install --upgrade pip -q
print_success "pip upgraded"
# Install dependencies
echo ""
echo "Installing dependencies..."
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt -q
print_success "Dependencies installed"
else
print_error "requirements.txt not found!"
exit 1
fi
# Generate sample data
echo ""
echo "Generating sample data..."
if [ -f "scripts/generate_sample_data.py" ]; then
python scripts/generate_sample_data.py
print_success "Sample data generated"
else
print_error "generate_sample_data.py not found!"
exit 1
fi
# Train models
echo ""
echo "Training models (this may take a few minutes)..."
if [ -f "scripts/train_model.py" ]; then
python scripts/train_model.py
print_success "Models trained"
else
print_error "train_model.py not found!"
exit 1
fi
# Run tests
echo ""
echo "Running tests..."
if command -v pytest &> /dev/null; then
pytest tests/ -v
print_success "All tests passed"
else
print_info "pytest not found, skipping tests"
fi
# Initialize git repository
echo ""
echo "Initializing git repository..."
if [ -d ".git" ]; then
print_info "Git repository already initialized"
else
git init
git add .
git commit -m "Initial commit: Complete Search Ranking System"
print_success "Git repository initialized"
fi
# Final summary
echo ""
echo "=================================================="
echo " Setup Complete! 🎉"
echo "=================================================="
echo ""
echo "Project structure:"
echo " ✓ All directories created"
echo " ✓ Python packages configured"
echo " ✓ Dependencies installed"
echo " ✓ Sample data generated (100 documents, 50 queries)"
echo " ✓ Models trained (TF-IDF, BM25, LambdaMART)"
echo " ✓ Tests executed"
echo " ✓ Git repository initialized"
echo ""
echo "Quick Start Commands:"
echo ""
echo "1. Start API Server:"
echo " python src/api/app.py"
echo " → http://localhost:5000"
echo ""
echo "2. Start Live Demo:"
echo " python demo/app.py"
echo " → http://localhost:8080"
echo ""
echo "3. Run Experiments:"
echo " python scripts/run_experiments.py"
echo ""
echo "4. Run Tests:"
echo " pytest tests/ -v"
echo ""
echo "=================================================="
echo ""
print_success "Ready to use! Happy searching! 🔍"
echo ""