reflexive 1.2.1__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 CHANGED
@@ -1,5 +1,19 @@
1
- import reflexive.analyse
2
- import reflexive.cfg
3
- import reflexive.session
4
- import reflexive.util
5
- import reflexive.visualise
1
+ # Make classes available at top level
2
+
3
+ from reflexive.cfg import Config
4
+ from reflexive.session import (
5
+ AWS,
6
+ S3,
7
+ Comprehend)
8
+
9
+ # import reflexive.util
10
+ from reflexive.analyse import Nlp
11
+ from reflexive.visualise import (
12
+ Display,
13
+ RES_graph)
14
+
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/analyse.py CHANGED
@@ -6,7 +6,6 @@ import re
6
6
  from reflexive import util
7
7
  from reflexive import cfg
8
8
  from reflexive import session
9
- import reflexive as rfx
10
9
 
11
10
  import logging
12
11
  logging.basicConfig(level=logging.DEBUG)
@@ -290,7 +289,7 @@ class Nlp:
290
289
  for grp in targetedSentiment_results:
291
290
  for mention in grp["Mentions"]:
292
291
  if mention['Score'] >= threshold:
293
- if not "NEUTRAL" in mention['MentionSentiment']['Sentiment']:
292
+ if "NEUTRAL" not in mention['MentionSentiment']['Sentiment']:
294
293
  k = mention['MentionSentiment']['Sentiment']
295
294
  text = str.lower(mention['Text'])
296
295
  sents.setdefault(k,{text}).add(text)
reflexive/cfg.py CHANGED
@@ -1,10 +1,8 @@
1
1
  import logging
2
2
  import os
3
3
  from datetime import datetime
4
- import json
5
- import reflexive as rfx
6
4
 
7
- logging.basicConfig(level=logging.DEBUG)
5
+ #logging.basicConfig(level=logging.DEBUG)
8
6
  logger = logging.getLogger(__name__)
9
7
 
10
8
  class Config:
@@ -74,7 +72,7 @@ class Config:
74
72
  if not os.path.exists(data_dir):
75
73
  logger.warning("Path does not exist, creating directory")
76
74
  os.makedirs(data_dir)
77
- logger.info(f"Created %s",repr(data_dir))
75
+ logger.info("Created %s",repr(data_dir))
78
76
  self.local_path = local_path
79
77
  if not date_string:
80
78
  date_string = datetime.today().strftime('%Y%m%d')
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
+
reflexive/session.py CHANGED
@@ -5,7 +5,6 @@ import tarfile
5
5
  import json
6
6
 
7
7
  from reflexive import cfg
8
- import reflexive as rfx
9
8
 
10
9
  import logging
11
10
  logging.basicConfig(level=logging.DEBUG)
@@ -19,7 +18,7 @@ class AWS:
19
18
  def __init__(self,config:cfg.Config):
20
19
  # on initialisation create a new session with provided profile (or with default profile)
21
20
  #logger.error(config.get_parameters())
22
- if config==None:
21
+ if config is None:
23
22
  config = cfg.Config()
24
23
  self.config = config
25
24
  self.new_session()
reflexive/util.py CHANGED
@@ -1,10 +1,12 @@
1
1
  import os
2
-
2
+ import json
3
+ import pandas as pd
4
+ from sklearn.preprocessing import MinMaxScaler
3
5
  import logging
4
6
  logging.basicConfig(level=logging.DEBUG)
5
7
  logger = logging.getLogger(__name__)
6
8
 
7
- from sklearn.preprocessing import MinMaxScaler
9
+
8
10
 
9
11
  # File functions
10
12
  def get_data_path_name(config,name,ext):
@@ -20,7 +22,7 @@ def set_sub_dir(config,sub_dir=None):
20
22
  logger.info(f"Creating subdirectory: {local_dir}")
21
23
  os.makedirs(local_dir)
22
24
  else:
23
- local_dir = local_path
25
+ local_dir = config.local_path
24
26
  return local_dir
25
27
 
26
28
 
@@ -46,12 +48,12 @@ def filter_dict_by_value(ngrams,min_val=3):
46
48
 
47
49
  # Input a series and output a list of lists with each maxn elements
48
50
  def series_to_chunked_list(series,maxn=25):
49
- l = list(series)
50
- return __chunk_list(l,maxn)
51
+ lst = list(series)
52
+ return __chunk_list(lst,maxn)
51
53
 
52
54
  # Chunk a list into a list of lists with maxn elements
53
- def __chunk_list(l,maxn=25):
54
- return [l[i:i + maxn] for i in range(0, len(l), maxn)]
55
+ def __chunk_list(lst,maxn=25):
56
+ return [lst[i:i + maxn] for i in range(0, len(lst), maxn)]
55
57
 
56
58
  # Count named entities
57
59
  def count_entities(entities):
reflexive/visualise.py CHANGED
@@ -1,6 +1,13 @@
1
- from graph_tool.all import *
1
+ from graph_tool.all import (
2
+ Graph,
3
+ graph_draw,
4
+ ungroup_vector_property,
5
+ group_vector_property
6
+ )
2
7
  import cairo
3
8
 
9
+ from spacy import displacy
10
+
4
11
  from reflexive import session
5
12
  from reflexive import cfg
6
13
 
@@ -188,6 +195,18 @@ class Display:
188
195
  #print("New offsets:",len(new_offsets[k]))
189
196
  return new_offsets
190
197
 
198
+ class RES_text:
199
+
200
+ def __init__(self):
201
+ self._setup()
202
+
203
+ def _setup(self):
204
+ return None
205
+
206
+ def show(self):
207
+ #displacy.render(disp_data,manual=True,style="ent", options=cfg.display_options)
208
+ return None
209
+
191
210
  class RES_graph:
192
211
 
193
212
  #
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reflexive
3
- Version: 1.2.1
3
+ Version: 1.2.3
4
4
  Summary: Supports AWS Reflexive Expressions Systems (RES) Analysis
5
5
  Project-URL: Repository, https://github.com/nlytx/reflexive.git
6
6
  Author-email: Andrew Gibson <andrew@nlytx.io>
@@ -0,0 +1,11 @@
1
+ reflexive/__init__.py,sha256=x5l8GV_9yC8yJyjTLqiM_WkfuPMLuNgQxF6PIz5MfFU,422
2
+ reflexive/analyse.py,sha256=LsDgFI_UUlK88ecQc19iPdcweAvT11CZCqtWtCsevC8,17465
3
+ reflexive/cfg.py,sha256=tDPiC9NwpEVoT05_831sMsMfHhJt8pVrSOsgbtzTNDM,4267
4
+ reflexive/res.py,sha256=D4LfMG20BikFHdLts3v6dbYZG6UubCNlGUBUJbpJfwg,4398
5
+ reflexive/session.py,sha256=ttyUAowaKgkwAgejRb_af5nZruKeH_kn3NB1NtitYUk,10045
6
+ reflexive/util.py,sha256=zwlFncsWrRSuK8rsQaZKFNVLTkRySb1WPeY6Hz6qHhc,3698
7
+ reflexive/visualise.py,sha256=pVnsPJOnHiLAIvDDm9P0u6-sGQINC4GVOY9b0GrzTK4,11725
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,,
@@ -1,10 +0,0 @@
1
- reflexive/__init__.py,sha256=Ke3gGqrVgPP2IRgifljQL8Ep3qVuuOf4LgZUkxdJQ2k,119
2
- reflexive/analyse.py,sha256=UzWwgjAFNjeWFkCQ2o99g2vWajf17_OtSq4dFCvuPYU,17489
3
- reflexive/cfg.py,sha256=Ges35G234P2lvOQHgPZQae5hMSOGyBsmp1bY_yQEKkk,4303
4
- reflexive/session.py,sha256=MbqwTsYTgq_e_gw3mb1eRv6USs-zZ2cTCrvUNWuKfAQ,10067
5
- reflexive/util.py,sha256=WQ1oyzDi1i8wQ6IBwBPk6IFy07YKhg-Ug2FsOGVJRJQ,3649
6
- reflexive/visualise.py,sha256=76ItFjz9KyPCxlfKuF16dmY5kLVbdTXAHyfcndMStH0,11355
7
- reflexive-1.2.1.dist-info/METADATA,sha256=sFL4BMnt-cMD8Ks--16hSTDmLI6F7anBF9zR_61hJDA,574
8
- reflexive-1.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
- reflexive-1.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
- reflexive-1.2.1.dist-info/RECORD,,