给定一段英文文本，请使用NLTK库计算其中的单词总数。


"This is a sample sentence to demonstrate NLTK library."
```python
import nltk

# download necessary resources for NLTK
nltk.download('punkt')

text = "This is a sample sentence to demonstrate NLTK library."
words = nltk.word_tokenize(text)
num_words = len(words)
print(num_words)
```

Output:
```
9
```