私は、あるjsonファイルを使用しています。
私のjsonファイルは、下のURLのjsonファイルでワインについてのレビューについてのデータで、多くの種類のワインのレビューについてリストとして記載されています。
'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/wine.json'
行には”country”,"variety", "price", "point", "description"などの項目があります。
私は、このファイルの"description"の列で5000件以上のレビューに現れるユニグラムを求めることを目的としています。
また、'stopwords.txt'というテキストファイルに含まれる単語は考慮せずに省いた状態で求めなければなりません。下がURLです。
'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/stopwords.txt'
しかし、その方法がわかりません。
どのようにコードを書けば'stopwords.txt'を適応して
"description"の列で5000件以上のレビューに現れるユニグラムを求める際に
それに記載されている単語をjsonファイルの”discription”から省いた状態にすることができるのでしょうか。(私のjsonファイルの”discription”の列のストップワードを取り除いた状態の新たなjsonファイルをまず作成したい)
下のコードは、わたしが途中まで書いたコードです。その先の'stopwords.txt'を適応してjsonファイルの”discription”の列のストップワードを取り除いた状態の新たなjsonファイルをまず作成する方法をおしえてください。
!pip install wget
python
1import wget 2 3link_to_data = 'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/wine.json' 4DataSet = wget.download(link_to_data) 5 6link_to_data = 'https://github.com/tulip-lab/sit742/raw/master/Assessment/2019/data/stopwords.txt' 7 8DataSet = wget.download(link_to_data)
!ls
python
1import json 2import pandas as pd 3import matplotlib.pyplot as plt
python
1file = 'wine.json'
python
1df = pd.read_json("wine.json")
python
1import re 2import nltk 3from nltk.tokenize import RegexpTokenizer 4from nltk.probability import * 5from itertools import chain 6 7import codecs
python
1with open('stopwords.txt') as f: 2 stop_words = f.read().splitlines() 3stop_words = set(stop_words)
python
1tokenizer = RegexpTokenizer(r"\w+(?:[-']\w+)?")
<追記>全ての"description"から'stopwords.txt'に記載されている単語を省いた結果を欲しいとかんがえており、
その結果でfreqDist()とsort()を使用して最終的に"description"の列で5000件以上のレビューに現れるユニグラムとそれらのユニグラムを持つ全ての行を知りたいと考えています。
なので、フォーマットとしてはその結果をトークンへの分割後、単語数、異なり語数、出現頻度が求められるような形でお願いしたいです。