Я создал веб-приложение с помощью 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
-
Anonymous
1715582095
Anonymous
Я создал веб-приложение с помощью 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')
Подробнее здесь: [url]https://stackoverflow.com/questions/78470434/nltk-package-is-not-working-in-production-but-working-in-development[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия