-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_altword_counts.py
74 lines (52 loc) · 2.43 KB
/
6_altword_counts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
import pandas as pd
from collections import Counter
# import numpy as np
################
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows',None)
pd.set_option('display.max_colwidth', 150)
import locale
locale.getpreferredencoding()
#################
xx = pd.read_csv("data/manualdata/5scopus_zot_ipcc_v2.csv")
xx.columns
len(xx)
################## Count occurence of alt terms
# prep
xx['authkeywords'] = xx['authkeywords'].str.replace("|", ".").fillna("")
xx['articletype'] = xx['articletype'].str.strip()
terms = xx[(xx['exclude'] == 0)]
len(terms)
terms['articletype'].value_counts()
empis, reviews, concs = [*dict([*terms.groupby('articletype')]).values()]
len(empis), len(reviews), len(concs)
for testset_i in [empis, concs, reviews, terms]:
testset = testset_i
TAK = testset['title'] + " " + '[SEP]' + " " + testset['authkeywords'] + " " + '[SEP]' + " " + testset['description']
TAK = TAK.astype("str")
TAK = [i.lower() for i in TAK]
TAK = pd.Series(TAK).str.replace("-", " ").to_list()
altlist = ["tradeoff", "trade off", "problem shift", "burden shift", "cascad", "interact", "interaction effect", "interdepend", "coupled", "coupli", " linkage",
"co benefit", "cobenefit", "disbenefit", "dis benefit", "co cost", "displace", "displacement", "co impact", "spill over", "spillover", "byproduct", "by product",
"ancillary", "adverse side effect", "side effect", "adverse effect", "unintended", "unanticipated", "feedback", "environmental side effect", "side-effect", "interlink"]
print("length", len(TAK))
kwcounts = []
for kw in altlist:
count = sum(kw in s for s in TAK)
kwcounts.append(count)
kwcount = pd.DataFrame(zip(altlist, kwcounts))
print(kwcount.sort_values(0)) # [kwcount[1]>0]
# Check for double doublecounts:
kwtestpairs = [['by product', 'byproduct'], ['tradeoff', 'trade off'], ['co benefit', 'cobenefit'],['spill over', 'spillover'], ['coupled', 'coupli'], ['adverse side effect', 'side effect', "side-effect"], ['interlink', 'linkage']]
def count_substrings(strings, substrings):
count = 0
for string in strings:
for substring in substrings:
if substring in string:
count += 1
break
return count
for pair in kwtestpairs:
print(pair[0], count_substrings(TAK, pair))
###################################