Commit 91b11052 authored by Lelkada L L P S M's avatar Lelkada L L P S M

word filtration script - retrieve word sensitivity score

parent 006ec3e0
...@@ -869,6 +869,65 @@ ...@@ -869,6 +869,65 @@
" document = {\"word\": row[\"word\"], \"score\": row[\"offensive_scale\"]}\n", " document = {\"word\": row[\"word\"], \"score\": row[\"offensive_scale\"]}\n",
" result = collection.insert_one(document)" " result = collection.insert_one(document)"
] ]
},
{
"cell_type": "markdown",
"id": "aafbf51b-ff3b-49c7-952f-902ee628861c",
"metadata": {},
"source": [
"#### Retrieve score"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "3cd54b06-c132-45ba-9602-1a5ceee220fa",
"metadata": {},
"outputs": [],
"source": [
"def get_sensitivity_score(word):\n",
" client = pymongo.MongoClient(\"mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net/\")\n",
"\n",
" # select the database and collection\n",
" db = client[\"word_filtration\"]\n",
" collection = db[\"sensitivity_score\"]\n",
" \n",
" # find the word in the collection and return its sensitivity score\n",
" result = collection.find_one({\"word\": word})\n",
" if result:\n",
" return result[\"score\"]\n",
" else:\n",
" return -99"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "6f05439f-5fc6-4de0-9420-7117a9608cde",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.65"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_sensitivity_score('play')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "636445cc-48c8-4b01-a3a7-920b4bec76b5",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment