Spaces:
Sleeping
Sleeping
Delete nltk_install.py
Browse files- nltk_install.py +0 -69
nltk_install.py
DELETED
|
@@ -1,69 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import nltk
|
| 3 |
-
import sys
|
| 4 |
-
|
| 5 |
-
def setup_nltk():
|
| 6 |
-
# Set NLTK data directory
|
| 7 |
-
nltk_dir = os.path.join(os.path.expanduser('~'), 'nltk_data')
|
| 8 |
-
os.makedirs(nltk_dir, exist_ok=True)
|
| 9 |
-
nltk.data.path.append(nltk_dir)
|
| 10 |
-
|
| 11 |
-
print(f"NLTK data directory: {nltk_dir}")
|
| 12 |
-
|
| 13 |
-
# List of required NLTK packages
|
| 14 |
-
packages = [
|
| 15 |
-
'punkt',
|
| 16 |
-
'stopwords',
|
| 17 |
-
'averaged_perceptron_tagger',
|
| 18 |
-
'wordnet',
|
| 19 |
-
'omw-1.4'
|
| 20 |
-
]
|
| 21 |
-
|
| 22 |
-
# Download each package
|
| 23 |
-
for package in packages:
|
| 24 |
-
print(f"\nDownloading {package}...")
|
| 25 |
-
try:
|
| 26 |
-
nltk.download(package, download_dir=nltk_dir, quiet=False)
|
| 27 |
-
print(f"✓ {package} downloaded successfully")
|
| 28 |
-
except Exception as e:
|
| 29 |
-
print(f"✗ Error downloading {package}: {str(e)}")
|
| 30 |
-
|
| 31 |
-
# Verify installation
|
| 32 |
-
print("\n=== Verifying NLTK Installation ===")
|
| 33 |
-
try:
|
| 34 |
-
from nltk.tokenize import word_tokenize, sent_tokenize
|
| 35 |
-
from nltk import pos_tag
|
| 36 |
-
from nltk.corpus import stopwords
|
| 37 |
-
|
| 38 |
-
test_text = "NLTK is working correctly if you can read this."
|
| 39 |
-
|
| 40 |
-
# Test tokenization
|
| 41 |
-
print("Testing tokenization...")
|
| 42 |
-
words = word_tokenize(test_text)
|
| 43 |
-
print(f"Word tokens: {words}")
|
| 44 |
-
|
| 45 |
-
# Test sentence tokenization
|
| 46 |
-
sentences = sent_tokenize(test_text)
|
| 47 |
-
print(f"Sentences: {sentences}")
|
| 48 |
-
|
| 49 |
-
# Test POS tagging
|
| 50 |
-
print("\nTesting POS tagging...")
|
| 51 |
-
tags = pos_tag(words)
|
| 52 |
-
print(f"POS tags: {tags}")
|
| 53 |
-
|
| 54 |
-
# Test stopwords
|
| 55 |
-
print("\nTesting stopwords...")
|
| 56 |
-
stop_words = stopwords.words('english')
|
| 57 |
-
print(f"Sample stopwords: {stop_words[:5]}...")
|
| 58 |
-
|
| 59 |
-
print("\n✅ NLTK is working correctly!")
|
| 60 |
-
|
| 61 |
-
except Exception as e:
|
| 62 |
-
print(f"\n❌ Error verifying NLTK: {str(e)}")
|
| 63 |
-
print("\nPlease try running these commands manually:")
|
| 64 |
-
print("import nltk")
|
| 65 |
-
for package in packages:
|
| 66 |
-
print(f"nltk.download('{package}')")
|
| 67 |
-
|
| 68 |
-
if __name__ == "__main__":
|
| 69 |
-
setup_nltk()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|