Я создал веб-приложение с помощью Django. В это веб-приложение я хочу добавить функционал по извлечению фраз из контента. Мой код работает нормально в разработке, но не работает в производстве. Используя пакет nltk, я создал функцию, которая возвращает список фраз из содержимого. ниже мой код:
import nltk
from typing import List
def extract_phrases(content: str) -> List:
# Tokenize text into sentences
sentences = nltk.sent_tokenize(content)
# Initialize list to store phrases
phrases = set()
# Iterate through each sentence
for sentence in sentences:
# Tokenize sentence into words
words = nltk.word_tokenize(sentence)
# Get part-of-speech tags for words
pos_tags = nltk.pos_tag(words)
# Initialize list to store phrases in current sentence
current_phrase = []
# Iterate through each word and its part-of-speech tag
for word, pos_tag in pos_tags:
# If the word is a noun or an adjective, add it to the current phrase
if pos_tag.startswith("NN") or pos_tag.startswith("JJ"):
current_phrase.append(word)
# If the word is not a noun or adjective and the current phrase is not empty,
# add the current phrase to the list of phrases and reset it
elif current_phrase:
phrases.add(" ".join(current_phrase))
current_phrase = []
# Add the last phrase from the current sentence (if any)
if current_phrase:
phrases.add(" ".join(current_phrase))
return list(phrases)
Функция и все веб-приложение корректно работают в среде разработки. Но в рабочей среде, где используется модуль nltk, эта строка не выполняется.
Примечание
Я активировал свою виртуальную среду и также запустил следующий код:
import nltk
nltk.download('all')
Подробнее здесь: https://stackoverflow.com/questions/784 ... evelopment
Пакет NLTK не работает в производстве, а работает в разработке ⇐ Apache
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение