reflexive 0.1.0__py3-none-any.whl → 0.1.1__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.
File without changes
@@ -0,0 +1,110 @@
1
+
2
+ #from spacy import displacy
3
+
4
+ #from reflexive.common.parameters import Parameters
5
+
6
+ import logging
7
+ try:
8
+ import coloredlogs
9
+ coloredlogs.install(level='INFO')
10
+ except:
11
+ print("Colored logs not available")
12
+
13
+ class Display:
14
+
15
+ logger = logging.getLogger(__name__)
16
+
17
+ def __init__(self): #,parameters:Parameters):
18
+ self.name="Display"
19
+ self.priority_tags = ["AR","EP","VR_EV_CN","ER_AF","RR","KP"]
20
+ self.colours = {"VR_EV_CN": "#ff6644","ER_AF": "#dd44cc","AR": "#00cc00","EP": "#aacc33","RR": "#00aaff","KP":"#aaaacc"}
21
+ self.options = {"ents": ["VR_EV_CN","ER_AF","AR","EP","RR","KP"], "colors": self.colours}
22
+
23
+
24
+
25
+ def add_reflexive_offsets(self,df):
26
+ temp_df = df.copy()
27
+ temp_df['reflexive_offsets'] = temp_df.reflexiveResults.apply(self.collect_reflexive_offsets)
28
+ return temp_df
29
+
30
+ def add_keyphrase_offsets(self,df):
31
+ temp_df = df.copy()
32
+ temp_df['keyphrase_offsets'] = temp_df.KeyPhraseResults.apply(self.collect_keyphrase_offsets)
33
+ return temp_df
34
+
35
+ def add_offsets(self,df):
36
+ df = self.add_reflexive_offsets(df)
37
+ return self.add_keyphrase_offsets(df)
38
+
39
+ def create_displacy(self,df):
40
+ all_ents = list(df.apply(self.render_record,axis=1))
41
+ #html_out = displacy.render(all_ents,manual=True,style="ent", options=options,page=True,jupyter=False)
42
+ # with open(f"{path}{prefix}annotated_reflections{postfix}.html","w") as fp:
43
+ # fp.write(html_out)
44
+ #displacy.render(all_ents,manual=True,style="ent", options=options)
45
+ return all_ents
46
+
47
+ def render_record(self,record,title="----"):
48
+ #timestamp = record['timestamp'].split('T')[0]
49
+ #pseudonym = record['pseudonym']
50
+ #point_round = record['point_round']
51
+ #title = f"{pseudonym} ({point_round}) - {timestamp}"
52
+ tags = self.priority_tags
53
+ text = record['text']
54
+ reflexive_offsets = record['reflexive_offsets']
55
+ keyphrase_offsets = record['keyphrase_offsets']
56
+ ents = []
57
+ taken = []
58
+ offsets = []
59
+ for tag in tags:
60
+ if tag in reflexive_offsets:
61
+ offsets = reflexive_offsets[tag]
62
+ elif tag in keyphrase_offsets:
63
+ offsets = keyphrase_offsets[tag]
64
+
65
+ for off in offsets:
66
+ new_ent = {}
67
+ if off[0] in taken:
68
+ # the start offset is taken
69
+ x = None
70
+ elif off[1] in taken:
71
+ # the end offset is taken
72
+ x = None
73
+ else:
74
+ # both start and end is available
75
+ taken.append(off[0])
76
+ taken.append(off[1])
77
+ #print(taken)
78
+ new_ent["start"] = off[0]
79
+ new_ent["end"] = off[1]
80
+ new_ent["label"] = tag
81
+ ents.append(new_ent)
82
+
83
+ text_ents = {
84
+ "text": text, #.replace('\r\n','\n'),
85
+ "ents": ents,
86
+ "title": title
87
+ }
88
+
89
+ return text_ents
90
+
91
+ def collect_keyphrase_offsets(self,krs):
92
+ new_krs = {}
93
+ for kr in krs:
94
+ if kr['Score']>0.98:
95
+ new_krs.setdefault("KP",[]).append((kr['BeginOffset'],kr['EndOffset']))
96
+ return new_krs
97
+
98
+ def collect_reflexive_offsets(self,rrs):
99
+ new_rrs = {}
100
+ for rr in rrs:
101
+ if rr['Score']>0.5:
102
+ ent_type = rr['Type']
103
+ if ent_type in ['VR','EV','CN']:
104
+ label = "VR_EV_CN"
105
+ elif ent_type in ['ER','AF']:
106
+ label = "ER_AF"
107
+ else:
108
+ label = ent_type
109
+ new_rrs.setdefault(label,[]).append((rr['BeginOffset'],rr['EndOffset']))
110
+ return new_rrs
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reflexive
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Supports AWS Reflexive Expressions Analysis
5
5
  Home-page: https://github.com/nlytx/reflexive
6
6
  Author: Andrew Gibson
@@ -10,8 +10,10 @@ reflexive/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
10
10
  reflexive/common/local.py,sha256=euhMmdRnL5c5d_Co2f2ehNP7Lv43T571tDCWQzpKaF4,1752
11
11
  reflexive/common/parameters.py,sha256=p_0YdP8d0q1l76dOK3Xaj24GKPUVtzMY1buvzgT-IPU,3044
12
12
  reflexive/common/util.py,sha256=_aft-pgX3oDPgvK1HaazdH9kIt52cVD-tjm6M24hq6M,3175
13
- reflexive-0.1.0.dist-info/LICENSE.txt,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
14
- reflexive-0.1.0.dist-info/METADATA,sha256=hn7GFc8BxusB3rSAR6-cO4WplMxVk_CiRImLRY-Xayo,597
15
- reflexive-0.1.0.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
16
- reflexive-0.1.0.dist-info/top_level.txt,sha256=pOMr-QGleRBRCFBozgvM-UUUmOjD_-naJfu1522E2V8,10
17
- reflexive-0.1.0.dist-info/RECORD,,
13
+ reflexive/visual/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ reflexive/visual/display.py,sha256=XiRC3Asx9Ed3xCNCt3_DlbF45JcifNbXH_B44jxqqp0,3886
15
+ reflexive-0.1.1.dist-info/LICENSE.txt,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
16
+ reflexive-0.1.1.dist-info/METADATA,sha256=_Q2YGxhybMZuK1qDVeAhketHbXha-m5pYXDBy1JTv7c,597
17
+ reflexive-0.1.1.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
18
+ reflexive-0.1.1.dist-info/top_level.txt,sha256=pOMr-QGleRBRCFBozgvM-UUUmOjD_-naJfu1522E2V8,10
19
+ reflexive-0.1.1.dist-info/RECORD,,