前提
python勉強中の者です。
https://zerofromlight.com/blogs/detail/93/#_4
上記のサイト様を参考にchatterbotのwebアプリを作成しています。
webアプリ化は成功したため、次の段階としてpythonの自然言語処理を行うライブラリであるmecabを導入したいと考えています。
https://zerofromlight.com/blogs/detail/55/
上記のサイト様の別の記事を見てpythonにインポートすることは出来ましたが、djangoと統合したchatterbotに同じようにインポートするとエラーが出てしまいます。
djangoと統合したchatterbotにはインポート出来ないのでしょうか?
発生している問題・エラーメッセージ
ModuleNotFoundError: No module named 'my_tagging'
該当のソースコード
my_tagging.py from chatterbot import languages import MeCab class MecabTagger(object): def __init__(self, language=None): self.language = language if self.language == languages.ENG: self.language = '-Owakati' self.tagger = MeCab.Tagger(self.language) def get_text_index_string(self, text): bigram_pairs = [] document = self.tagger.parseToNode(text).next if document: tokens = [] while document.next: feature = document.feature.split(',') if feature[0] in ['補助記号', '記号']: pass else: tokens.append(feature[0]) # 名詞を追加 tokens.append(feature[-1]) # カナ文字を追加 document = document.next for index in range(2, len(tokens), 2): bigram_pairs.append('{}:{}'.format( tokens[index - 1], tokens[index] )) if not bigram_pairs: document = self.tagger.parseToNode(text).next while document.next: feature = document.feature.split(',') if feature[0] in ['補助記号', '記号']: pass else: bigram_pairs.append( feature[-1] ) document = document.next return ' '.join(bigram_pairs)
setting.py from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'django-insecure-nfg1ho@h3q5%t$u&$vge00oqbc*@^5vz)j*(%(r977gb&kq@k%' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'prototype', 'chatterbot.ext.django_chatterbot', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'sample_bot.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'sample_bot.wsgi.application' # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } } # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ LANGUAGE_CODE = 'ja' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True USE_TZ = True # ChatterBotパラメータ from . import languages from my_tagging import MecabTagger CHATTERBOT = { 'name': 'Iris', # チャットボットの名前 'tagger_language': languages.JPN, 'tagger':mecabtagger } # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ STATIC_URL = '/static/' # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
あなたの回答
tips
プレビュー