reflexive 1.2.0__tar.gz → 1.2.1__tar.gz
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-1.2.0 → reflexive-1.2.1}/PKG-INFO +1 -1
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.13-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.13.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.14-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.14.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.15-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.15.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.16-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.16.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.17-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.17.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.18-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.18.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.19-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.19.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.20-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.0.20.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.1.0-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.1.0.tar.gz +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.1.1-py3-none-any.whl +0 -0
- reflexive-1.2.1/old reflexive dist/reflexive-1.1.1.tar.gz +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/pyproject.toml +1 -1
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/visualise.py +151 -1
- reflexive-1.2.1/tests/__init__.py +0 -0
- reflexive-1.2.1/tests/test_reflexive.py +110 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/.gitignore +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/LICENSE +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/README.md +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/pixi.lock +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/__init__.py +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/analyse.py +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/cfg.py +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/session.py +0 -0
- {reflexive-1.2.0 → reflexive-1.2.1}/src/reflexive/util.py +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
from graph_tool.all import *
|
|
2
|
+
import cairo
|
|
3
|
+
|
|
1
4
|
from reflexive import session
|
|
2
5
|
from reflexive import cfg
|
|
3
6
|
|
|
@@ -183,4 +186,151 @@ class Display:
|
|
|
183
186
|
b = v[0]
|
|
184
187
|
e = v[1]
|
|
185
188
|
#print("New offsets:",len(new_offsets[k]))
|
|
186
|
-
return new_offsets
|
|
189
|
+
return new_offsets
|
|
190
|
+
|
|
191
|
+
class RES_graph:
|
|
192
|
+
|
|
193
|
+
#
|
|
194
|
+
gt_props = {0:{ "lbl":"RR",
|
|
195
|
+
"pos":(0.2,6.5),
|
|
196
|
+
"clr":"#00AEEF"},
|
|
197
|
+
1:{ "lbl":"NR",
|
|
198
|
+
"pos":(5,10),
|
|
199
|
+
"clr":"#ED1B23"},
|
|
200
|
+
2:{ "lbl":"AR",
|
|
201
|
+
"pos":(9.8,6.5),
|
|
202
|
+
"clr":"#00A64F"},
|
|
203
|
+
3:{ "lbl":"AF",
|
|
204
|
+
"pos":(7.9,1),
|
|
205
|
+
"clr":"#EC008C"},
|
|
206
|
+
4:{ "lbl":"EP",
|
|
207
|
+
"pos":(2.1,1),
|
|
208
|
+
"clr":"#FFF200"}}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
# re_props = {"RR":{
|
|
212
|
+
# "idx": 0,
|
|
213
|
+
# "pos":(0.2,6.5),
|
|
214
|
+
# "clr":"#00AEEF"},
|
|
215
|
+
# "NR":{
|
|
216
|
+
# "idx": 1,
|
|
217
|
+
# "pos":(5,10),
|
|
218
|
+
# "clr":"#ED1B23"},
|
|
219
|
+
# "AR":{
|
|
220
|
+
# "idx": 2,
|
|
221
|
+
# "pos":(9.8,6.5),
|
|
222
|
+
# "clr":"#00A64F"},
|
|
223
|
+
# "AF":{
|
|
224
|
+
# "idx": 3,
|
|
225
|
+
# "pos":(7.9,1),
|
|
226
|
+
# "clr":"#EC008C"},
|
|
227
|
+
# "EP":{
|
|
228
|
+
# "idx": 4,
|
|
229
|
+
# "pos":(2.1,1),
|
|
230
|
+
# "clr":"#FFF200"}}
|
|
231
|
+
|
|
232
|
+
#
|
|
233
|
+
edges = dict()
|
|
234
|
+
#
|
|
235
|
+
iso_vertices = set()
|
|
236
|
+
#
|
|
237
|
+
v_label = None
|
|
238
|
+
#
|
|
239
|
+
v_color = None
|
|
240
|
+
#
|
|
241
|
+
v_pos = None
|
|
242
|
+
|
|
243
|
+
#
|
|
244
|
+
def __init__(self,matrix=None):
|
|
245
|
+
self._setup(matrix)
|
|
246
|
+
|
|
247
|
+
#
|
|
248
|
+
def _setup(self,matrix):
|
|
249
|
+
if matrix:
|
|
250
|
+
# Edges from matrix
|
|
251
|
+
self.edges = self._matrix_to_dict(matrix)
|
|
252
|
+
self.graph = Graph(g=self.edges.keys(),directed=False)
|
|
253
|
+
self.e_weight = self.graph.new_ep("double",vals=self.edges.values())
|
|
254
|
+
# Handle colour of isolated vertices
|
|
255
|
+
default_clrs = self._get_prop_values('clr')
|
|
256
|
+
actual_clrs = []
|
|
257
|
+
for i in range(5):
|
|
258
|
+
if i in self.iso_vertices:
|
|
259
|
+
clr = "#cccccc"
|
|
260
|
+
else:
|
|
261
|
+
clr = default_clrs[i]
|
|
262
|
+
actual_clrs.append(clr)
|
|
263
|
+
self.v_color = self.graph.new_vp("string",vals=actual_clrs)
|
|
264
|
+
else:
|
|
265
|
+
# No edges
|
|
266
|
+
self.graph = Graph(g=self._empty_edge_dict(),directed=False)
|
|
267
|
+
self.e_weight = self.graph.new_ep("double")
|
|
268
|
+
self.v_color = self.graph.new_vp("string",val="#cccccc")
|
|
269
|
+
# Vertex properties common to all graphs
|
|
270
|
+
self.v_label = self.graph.new_vp("string",vals=self._get_prop_values('lbl'))
|
|
271
|
+
self.v_pos = self.graph.new_vp("vector<double>",vals=self._get_prop_values('pos'))
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
#
|
|
276
|
+
def _matrix_to_dict(self,matrix):
|
|
277
|
+
edges = {}
|
|
278
|
+
for r,row in enumerate(matrix):
|
|
279
|
+
# if empty row, add to iso_vertices
|
|
280
|
+
if sum(row) == 0:
|
|
281
|
+
self.iso_vertices.add(r)
|
|
282
|
+
else:
|
|
283
|
+
for c,weight in enumerate(row):
|
|
284
|
+
if weight > 0:
|
|
285
|
+
edge = tuple(sorted((r,c)))
|
|
286
|
+
#print("r,c:",edge," - ",weight)
|
|
287
|
+
edges[edge] = weight
|
|
288
|
+
return edges
|
|
289
|
+
|
|
290
|
+
#
|
|
291
|
+
def _empty_edge_dict(self):
|
|
292
|
+
empty_edges = {}
|
|
293
|
+
for idx in self.gt_props.keys():
|
|
294
|
+
empty_edges[idx] = []
|
|
295
|
+
return empty_edges
|
|
296
|
+
|
|
297
|
+
#
|
|
298
|
+
def _get_prop_values(self,key):
|
|
299
|
+
values_list = self.gt_props.values()
|
|
300
|
+
return [p[key] for p in values_list]
|
|
301
|
+
|
|
302
|
+
# flip coordinates for graph-tool
|
|
303
|
+
def _flipY(self,vpositions):
|
|
304
|
+
x, y = ungroup_vector_property(vpositions, [0, 1])
|
|
305
|
+
y.fa *= -1
|
|
306
|
+
y.fa -= y.fa.min()
|
|
307
|
+
return group_vector_property([x, y])
|
|
308
|
+
|
|
309
|
+
#
|
|
310
|
+
def show(self,inline=True):
|
|
311
|
+
graph = self.graph
|
|
312
|
+
positions = self._flipY(self.v_pos)
|
|
313
|
+
labels = self.v_label
|
|
314
|
+
colors = self.v_color
|
|
315
|
+
weights = self.e_weight
|
|
316
|
+
graph_draw(graph, inline=inline,output_size=(300,300),fit_view=0.7,
|
|
317
|
+
pos=positions,
|
|
318
|
+
vertex_text=labels,
|
|
319
|
+
vertex_font_family="sans serif",
|
|
320
|
+
vertex_font_size=18,
|
|
321
|
+
vertex_font_weight=cairo.FONT_WEIGHT_BOLD,
|
|
322
|
+
vertex_fill_color=colors,
|
|
323
|
+
vertex_size = 50,
|
|
324
|
+
vertex_halo=False,
|
|
325
|
+
vertex_pen_width=1.2,
|
|
326
|
+
vertex_color="#999999",
|
|
327
|
+
edge_pen_width=weights)
|
|
328
|
+
|
|
329
|
+
def get_vertex_labels(self):
|
|
330
|
+
return self._get_prop_values('lbl')
|
|
331
|
+
|
|
332
|
+
def get_vertex_colours(self):
|
|
333
|
+
return self._get_prop_values('clr')
|
|
334
|
+
|
|
335
|
+
def get_vertex_positions(self):
|
|
336
|
+
return self._get_prop_values('pos')
|
|
File without changes
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
logging.basicConfig(level=logging.INFO)
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
import reflexive as rfx
|
|
13
|
+
|
|
14
|
+
# Create a config with a profile (local credentials) - leave blank for 'default' profile
|
|
15
|
+
cfg = rfx.cfg.Config('r3-admin')
|
|
16
|
+
# Set default parameters - specify name_prefix, local_path, and date_string for custom options
|
|
17
|
+
parameters = cfg.set_parameters()
|
|
18
|
+
#print("After set_parameters:",parameters)
|
|
19
|
+
|
|
20
|
+
# Create a session with AWS using profile - some parameters require AWS session (like account number)
|
|
21
|
+
aws = rfx.session.AWS(cfg)
|
|
22
|
+
#print("aws parameters:",cfg.get_parameters())
|
|
23
|
+
|
|
24
|
+
# Set the parameters for S3 - required for comprehend
|
|
25
|
+
parameters = cfg.set_s3_parameters(s3_access_point="qut-gibsonap-reflexive",s3_bucket_name="au-edu-qld-qut-gibsonap-reflexive")
|
|
26
|
+
#print("After set_s3_parameters:",parameters)
|
|
27
|
+
|
|
28
|
+
# Set comprehend parameters
|
|
29
|
+
parameters = cfg.set_comprehend_parameters(comprehend_service_role_name="AmazonComprehendServiceRole-gibsonap-reflexive")
|
|
30
|
+
#print("After set_comprehend_parameters:",parameters)
|
|
31
|
+
|
|
32
|
+
# Set custom entity recogniser parameters
|
|
33
|
+
parameters = cfg.set_comprehend_custom_entity_parameters(reflexive_entity_name="ReflexiveExpressionRecogniser",reflexive_entity_version="v17")
|
|
34
|
+
#print("After set_comprehend_custom_entity_parameters:",parameters)
|
|
35
|
+
|
|
36
|
+
# Display all parameters stored in Config
|
|
37
|
+
params_fmt = json.dumps(parameters, indent=2)
|
|
38
|
+
#print(params_fmt)
|
|
39
|
+
|
|
40
|
+
# Create a new S3 client
|
|
41
|
+
s3 = rfx.session.S3(aws)
|
|
42
|
+
s3_client = s3.client()
|
|
43
|
+
|
|
44
|
+
# Create a new Comprehend client
|
|
45
|
+
comp = rfx.session.Comprehend(aws)
|
|
46
|
+
comp_client = comp.client()
|
|
47
|
+
|
|
48
|
+
# Perform test analysis
|
|
49
|
+
test_dict = {"text":["This is a test text. I hope that this will work for some basic analysis. Previously, this has not been as straight forward as I thought. Perhaps this time may be different. With any luck, this will not be a frustrating experience, but I hope that it will just work straight away. I can only hope!"]}
|
|
50
|
+
test_series = pd.Series(test_dict['text'])
|
|
51
|
+
df = pd.DataFrame.from_dict(test_dict)
|
|
52
|
+
#print(df.describe())
|
|
53
|
+
|
|
54
|
+
nlp = rfx.analyse.Nlp(aws)
|
|
55
|
+
|
|
56
|
+
# Text length - this is needed for comprehend analytics
|
|
57
|
+
df = nlp.text_length(df)
|
|
58
|
+
df = nlp.remove_IQR_outliers(df)
|
|
59
|
+
#print(df.describe())
|
|
60
|
+
|
|
61
|
+
# Domain terms
|
|
62
|
+
#domain_terms = {"hedge":['hope','perhaps','luck'],"emotion":['hope','frustrating']}
|
|
63
|
+
#nlp.add_domain_terms(domain_terms)
|
|
64
|
+
#df = nlp.match_domain_terms(df)
|
|
65
|
+
#print(df['domain_counts'])
|
|
66
|
+
|
|
67
|
+
# Ngrams
|
|
68
|
+
#top_ngrams = nlp.get_top_ngrams(df['text'],2)
|
|
69
|
+
#print(top_ngrams)
|
|
70
|
+
#df = nlp.match_top_ngrams(df)
|
|
71
|
+
#print(df)
|
|
72
|
+
|
|
73
|
+
# Comprehend analysis
|
|
74
|
+
# results = nlp.comprehend_analysis(comp,df)
|
|
75
|
+
# print(results)
|
|
76
|
+
# errors = nlp.check_results(results)
|
|
77
|
+
# print(errors)
|
|
78
|
+
# if errors=={}:
|
|
79
|
+
# print("No errors, so adding results to dataframe")
|
|
80
|
+
# df = nlp.add_results_to_df(results,df)
|
|
81
|
+
# print(df)
|
|
82
|
+
|
|
83
|
+
# df.to_pickle(f"{cfg.local_path}comp_df.pkl")
|
|
84
|
+
df = pd.read_pickle(f"{cfg.local_path}comp_df.pkl")
|
|
85
|
+
|
|
86
|
+
# Comprehend analytics
|
|
87
|
+
df = nlp.comprehend_analytics(df)
|
|
88
|
+
df.to_csv(f"{cfg.local_path}comp_analytics.csv")
|
|
89
|
+
print("DONE!!")
|
|
90
|
+
|
|
91
|
+
# Reflexive expression analysis
|
|
92
|
+
response = nlp.analyse_reflexive_expressions(df,s3,comp)
|
|
93
|
+
print(response)
|
|
94
|
+
job_id = comp.get_current_job_id()
|
|
95
|
+
time.sleep(5)
|
|
96
|
+
status = comp.check_job_status()
|
|
97
|
+
print(status)
|
|
98
|
+
time.sleep(5)
|
|
99
|
+
details = comp.get_job_details()
|
|
100
|
+
print(details)
|
|
101
|
+
|
|
102
|
+
while status=="IN_PROGRESS":
|
|
103
|
+
time.sleep(10)
|
|
104
|
+
status = comp.check_job_status()
|
|
105
|
+
print(status)
|
|
106
|
+
|
|
107
|
+
result = comp.download_and_extract(s3)
|
|
108
|
+
print(result)
|
|
109
|
+
|
|
110
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|