OxbridgeEconomics
commited on
Commit
·
b05adb3
1
Parent(s):
2034ad2
commit
Browse files
gov.py
CHANGED
@@ -21,7 +21,7 @@ translator = Translator()
|
|
21 |
def datemodifier(date_string):
|
22 |
"""Date Modifier Function"""
|
23 |
try:
|
24 |
-
to_date = time.strptime(date_string,"%Y-%m-%d
|
25 |
return time.strftime("%Y-%m-%d",to_date)
|
26 |
except:
|
27 |
return False
|
|
|
21 |
def datemodifier(date_string):
|
22 |
"""Date Modifier Function"""
|
23 |
try:
|
24 |
+
to_date = time.strptime(date_string,"%Y-%m-%d-%H:%M:%S")
|
25 |
return time.strftime("%Y-%m-%d",to_date)
|
26 |
except:
|
27 |
return False
|
ner.ipynb
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"metadata": {},
|
7 |
-
"outputs": [],
|
8 |
-
"source": [
|
9 |
-
"from flair.nn import Classifier\n",
|
10 |
-
"from flair.data import Sentence\n",
|
11 |
-
"\n",
|
12 |
-
"linker = Classifier.load('linker')\n",
|
13 |
-
"ner = Classifier.load('flair/ner-english-ontonotes-fast')\n",
|
14 |
-
"\n",
|
15 |
-
"def linker_model(input_text, tagger):\n",
|
16 |
-
" \"\"\"Linker model predict tags for sentences\"\"\"\n",
|
17 |
-
" sentence = Sentence(input_text)\n",
|
18 |
-
" tagger.predict(sentence)\n",
|
19 |
-
"\n",
|
20 |
-
" # iterate through sentences and print predicted labels\n",
|
21 |
-
" label_dict = {}\n",
|
22 |
-
" for label in sentence.get_labels():\n",
|
23 |
-
" if label.data_point.text.endswith(\"F.C.\"):\n",
|
24 |
-
" continue\n",
|
25 |
-
" if (label.score>0.5) & (label.value != \"<unk>\"):\n",
|
26 |
-
" if label.value in label_dict:\n",
|
27 |
-
" label_dict[label.value].append(label.data_point.text)\n",
|
28 |
-
" else:\n",
|
29 |
-
" label_dict[label.value] = [label.data_point.text]\n",
|
30 |
-
" return label_dict\n",
|
31 |
-
"\n",
|
32 |
-
"def find_keys_by_value(dictionary, value):\n",
|
33 |
-
" \"\"\"Find key by value\"\"\"\n",
|
34 |
-
" keys = []\n",
|
35 |
-
" for key, values in dictionary.items():\n",
|
36 |
-
" if value in values:\n",
|
37 |
-
" keys.append(key)\n",
|
38 |
-
" return keys\n",
|
39 |
-
"\n",
|
40 |
-
"def recognition_model(input_text, label_dict, tagger):\n",
|
41 |
-
" \"\"\"recognition model\"\"\"\n",
|
42 |
-
" ner_dict = {}\n",
|
43 |
-
" score_dict = {}\n",
|
44 |
-
" sentence = Sentence(input_text)\n",
|
45 |
-
" tagger.predict(sentence)\n",
|
46 |
-
" # for sentence in sentences:\n",
|
47 |
-
" for label in sentence.get_labels():\n",
|
48 |
-
" if label.score>0.5:\n",
|
49 |
-
" data_point = label.data_point.text\n",
|
50 |
-
" label_value = label.value\n",
|
51 |
-
" # label_value PER\n",
|
52 |
-
" keys = find_keys_by_value(label_dict, data_point)\n",
|
53 |
-
" if len(keys)>0:\n",
|
54 |
-
" if label_value in ner_dict:\n",
|
55 |
-
" if keys[0] not in ner_dict[label_value]:\n",
|
56 |
-
" ner_dict[label.value].append(keys[0])\n",
|
57 |
-
" score_dict[keys[0]] = label.score\n",
|
58 |
-
" else:\n",
|
59 |
-
" ner_dict[label.value] = [keys[0]]\n",
|
60 |
-
" score_dict[keys[0]] = label.score\n",
|
61 |
-
" return ner_dict, score_dict"
|
62 |
-
]
|
63 |
-
},
|
64 |
-
{
|
65 |
-
"cell_type": "code",
|
66 |
-
"execution_count": null,
|
67 |
-
"metadata": {},
|
68 |
-
"outputs": [],
|
69 |
-
"source": [
|
70 |
-
"for _, item in df.iterrows():\n",
|
71 |
-
" label_dict = linker_model(item['content'],linker)\n",
|
72 |
-
" ner_dict, score_dict = recognition_model(item['content'], label_dict, ner)\n",
|
73 |
-
" # result = result_dictionary_constructor(ner_dict, label_dict)\n",
|
74 |
-
" print(ner_dict, score_dict)"
|
75 |
-
]
|
76 |
-
}
|
77 |
-
],
|
78 |
-
"metadata": {
|
79 |
-
"language_info": {
|
80 |
-
"name": "python"
|
81 |
-
}
|
82 |
-
},
|
83 |
-
"nbformat": 4,
|
84 |
-
"nbformat_minor": 2
|
85 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|