reflexive 1.2.2__py3-none-any.whl → 1.2.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reflexive/__init__.py +5 -1
- reflexive/res.py +127 -0
- {reflexive-1.2.2.dist-info → reflexive-1.2.3.dist-info}/METADATA +1 -1
- {reflexive-1.2.2.dist-info → reflexive-1.2.3.dist-info}/RECORD +6 -5
- {reflexive-1.2.2.dist-info → reflexive-1.2.3.dist-info}/WHEEL +0 -0
- {reflexive-1.2.2.dist-info → reflexive-1.2.3.dist-info}/licenses/LICENSE +0 -0
reflexive/__init__.py
CHANGED
|
@@ -12,4 +12,8 @@ from reflexive.visualise import (
|
|
|
12
12
|
Display,
|
|
13
13
|
RES_graph)
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
from reflexive.res import (
|
|
16
|
+
Res_analyse,
|
|
17
|
+
Res_display)
|
|
18
|
+
|
|
19
|
+
__all__ = ["Config","AWS","S3","Comprehend","Nlp","Display","RES_graph","Res_analyse","Res_display"]
|
reflexive/res.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pandas import DataFrame
|
|
3
|
+
from spacy import displacy
|
|
4
|
+
from time import sleep
|
|
5
|
+
from reflexive import Config
|
|
6
|
+
from reflexive import AWS
|
|
7
|
+
from reflexive import S3
|
|
8
|
+
from reflexive import Comprehend
|
|
9
|
+
from reflexive import Nlp
|
|
10
|
+
from reflexive import Display
|
|
11
|
+
from reflexive import RES_graph
|
|
12
|
+
|
|
13
|
+
class Res_analyse:
|
|
14
|
+
|
|
15
|
+
config:Config
|
|
16
|
+
aws:AWS
|
|
17
|
+
s3:S3
|
|
18
|
+
comprehend:Comprehend
|
|
19
|
+
nlp:Nlp
|
|
20
|
+
|
|
21
|
+
def __init__(self,aws_profile="default") -> None:
|
|
22
|
+
return self._setup(aws_profile)
|
|
23
|
+
|
|
24
|
+
def _setup(self,aws_profile) -> None:
|
|
25
|
+
self.config = Config(aws_profile)
|
|
26
|
+
self.config.set_parameters(name_prefix="RES")
|
|
27
|
+
self.aws = AWS(self.config)
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
def set_parameters(self,
|
|
31
|
+
s3_access_point:str,
|
|
32
|
+
s3_bucket_name:str,
|
|
33
|
+
comprehend_service_role_name:str,
|
|
34
|
+
reflexive_entity_name:str,
|
|
35
|
+
reflexive_entity_version:str) -> str:
|
|
36
|
+
self.config.set_s3_parameters(s3_access_point,s3_bucket_name)
|
|
37
|
+
self.config.set_comprehend_parameters(comprehend_service_role_name)
|
|
38
|
+
self.config.set_comprehend_custom_entity_parameters(reflexive_entity_name,reflexive_entity_version)
|
|
39
|
+
params = self.config.get_parameters()
|
|
40
|
+
return json.dumps(params, indent=2)
|
|
41
|
+
|
|
42
|
+
def setup_aws(self) -> None:
|
|
43
|
+
# Create a new S3 client
|
|
44
|
+
self.s3 = S3(self.aws)
|
|
45
|
+
# Create a new Comprehend client
|
|
46
|
+
self.comprehend = Comprehend(self.aws)
|
|
47
|
+
# Create an Nlp object to perform analysis on the text
|
|
48
|
+
self.nlp = Nlp(self.aws)
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
def get_basic_analytics(self,df:DataFrame) -> DataFrame:
|
|
52
|
+
|
|
53
|
+
# Text length - this is needed for comprehend analytics
|
|
54
|
+
df = self.nlp.text_length(df)
|
|
55
|
+
#df = nlp.remove_IQR_outliers(df)
|
|
56
|
+
# Comprehend analysis
|
|
57
|
+
results = self.nlp.comprehend_analysis(self.comprehend,df)
|
|
58
|
+
#print(results)
|
|
59
|
+
errors = self.nlp.check_results(results)
|
|
60
|
+
#print(errors)
|
|
61
|
+
if errors=={}:
|
|
62
|
+
print("No errors, so adding results to dataframe")
|
|
63
|
+
df = self.nlp.add_results_to_df(results,df)
|
|
64
|
+
df = self.nlp.comprehend_analytics(df)
|
|
65
|
+
return df
|
|
66
|
+
|
|
67
|
+
def get_reflexive_analytics(self,df:DataFrame) -> DataFrame:
|
|
68
|
+
# Reflexive expression analysis
|
|
69
|
+
response = self.nlp.analyse_reflexive_expressions(df,self.s3,self.comprehend)
|
|
70
|
+
#print(response)
|
|
71
|
+
job_id = self.comprehend.get_current_job_id()
|
|
72
|
+
print("Job ID:",job_id)
|
|
73
|
+
status = self.comprehend.check_job_status()
|
|
74
|
+
print("Status:",status)
|
|
75
|
+
|
|
76
|
+
# Get the details of the job
|
|
77
|
+
# details = comp.get_job_details()
|
|
78
|
+
# print("Job details:",details)
|
|
79
|
+
|
|
80
|
+
inc = 0
|
|
81
|
+
while status=="SUBMITTED" or status=="IN_PROGRESS":
|
|
82
|
+
print("Waiting 10 seconds...")
|
|
83
|
+
sleep(10)
|
|
84
|
+
status = self.comprehend.check_job_status()
|
|
85
|
+
print(f"Job status {inc}:",status)
|
|
86
|
+
inc += 1
|
|
87
|
+
|
|
88
|
+
# Download from S3 and extract results
|
|
89
|
+
print("Downloading and extracting results...")
|
|
90
|
+
results = self.comprehend.download_and_extract(self.s3)
|
|
91
|
+
print("RESULTS:")
|
|
92
|
+
print(results)
|
|
93
|
+
|
|
94
|
+
# Extract output of analysis and add to df
|
|
95
|
+
return self.nlp.add_to_dataframe(df,results)
|
|
96
|
+
|
|
97
|
+
class Res_display:
|
|
98
|
+
|
|
99
|
+
res_analyse:Res_analyse
|
|
100
|
+
vis:Display
|
|
101
|
+
|
|
102
|
+
def __init__(self,res:Res_analyse) -> None:
|
|
103
|
+
return self._setup(res)
|
|
104
|
+
|
|
105
|
+
def _setup(self,res:Res_analyse) -> None:
|
|
106
|
+
self.res_analyse = res
|
|
107
|
+
self.vis = Display(res.aws)
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
def show_text(self,df:DataFrame,inline=True) -> str:
|
|
111
|
+
df = self.vis.add_offsets(df)
|
|
112
|
+
disp_data = self.vis.create_displacy(df)
|
|
113
|
+
if inline:
|
|
114
|
+
displacy.render(disp_data,manual=True,style="ent", options=self.res_analyse.config.display_options)
|
|
115
|
+
html_out = "Set inline to false to produce HTML"
|
|
116
|
+
else:
|
|
117
|
+
html_out = displacy.render(disp_data,manual=True,style="ent", options=self.res_analyse.config.display_options,page=True,jupyter=False)
|
|
118
|
+
return html_out
|
|
119
|
+
|
|
120
|
+
def show_graph(self,reflexive_expressions) ->list:
|
|
121
|
+
#Get RE sequence
|
|
122
|
+
reseq = [label for re,label in reflexive_expressions]
|
|
123
|
+
return reseq
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
reflexive/__init__.py,sha256=
|
|
1
|
+
reflexive/__init__.py,sha256=x5l8GV_9yC8yJyjTLqiM_WkfuPMLuNgQxF6PIz5MfFU,422
|
|
2
2
|
reflexive/analyse.py,sha256=LsDgFI_UUlK88ecQc19iPdcweAvT11CZCqtWtCsevC8,17465
|
|
3
3
|
reflexive/cfg.py,sha256=tDPiC9NwpEVoT05_831sMsMfHhJt8pVrSOsgbtzTNDM,4267
|
|
4
|
+
reflexive/res.py,sha256=D4LfMG20BikFHdLts3v6dbYZG6UubCNlGUBUJbpJfwg,4398
|
|
4
5
|
reflexive/session.py,sha256=ttyUAowaKgkwAgejRb_af5nZruKeH_kn3NB1NtitYUk,10045
|
|
5
6
|
reflexive/util.py,sha256=zwlFncsWrRSuK8rsQaZKFNVLTkRySb1WPeY6Hz6qHhc,3698
|
|
6
7
|
reflexive/visualise.py,sha256=pVnsPJOnHiLAIvDDm9P0u6-sGQINC4GVOY9b0GrzTK4,11725
|
|
7
|
-
reflexive-1.2.
|
|
8
|
-
reflexive-1.2.
|
|
9
|
-
reflexive-1.2.
|
|
10
|
-
reflexive-1.2.
|
|
8
|
+
reflexive-1.2.3.dist-info/METADATA,sha256=NlCGUhf0OJWmRImBng_9YQGTsWbDFf-roOwVT_xVl88,574
|
|
9
|
+
reflexive-1.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
reflexive-1.2.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
11
|
+
reflexive-1.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|