-
Notifications
You must be signed in to change notification settings - Fork 0
/
newFilter.r
executable file
·106 lines (94 loc) · 4.97 KB
/
newFilter.r
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
newFilter <- function(mapFilter,hideCountry,countryFilter,crossFilterType,hideCrossCountry,countryCrossFilter,citation,year,gsRank,authors,university,publisher,keywordList){
debug = FALSE
if(debug){
if(!is.null(authors)){
authors <- unlist(strsplit(authors,","))
print(authors)
}
return(countries)
}
hideCountryList <- isoList[hideCrossCountry] %>% as.character()
countryList <- isoList[countryCrossFilter] %>% as.character()
filteredArticles <- articles
#filteredArticles <- subset(filteredArticles, (Cites %in% c(citation[1]:citation[2])))
#filteredArticles <- subset(filteredArticles, (Year %in% c(year[1]:year[2])))
#filteredArticles <- subset(filteredArticles, (GSRank %in% c(gsRank[1]:gsRank[2])))
if(!is.null(authors)) {
pattern = paste(authors,collapse="|")
filteredArticles <- subset(filteredArticles, (grepl(pattern, Authors)))
}
if(!is.null(university)) {
pattern = paste(university,collapse = "|")
filteredArticles <- subset(filteredArticles, (grepl(pattern, Place.of.Publish..1st.author.)))
}
if(!is.null(keywordList)){
pattern = paste(keywordList,collapse = "|")
filteredArticles <- subset(filteredArticles, (grepl(pattern, keywords,ignore.case = TRUE)))
}
#print(c("before Type filter, there are", dim(filteredArticles)))
# Type filter
if (!is.null(hideCrossCountry) || !is.null(countryCrossFilter)){
hideCountryPattern = paste(hideCountryList,collapse = "|")
countryPattern = paste(countryList,collapse = "|")
if (crossFilterType == "WORK"){
if (!is.null(hideCrossCountry)) filteredArticles <- subset(filteredArticles,!grepl(hideCountryPattern, Place.of.Work))
filteredArticles <- subset(filteredArticles,grepl(countryPattern, Place.of.Work))
}
else if (crossFilterType == "FIRSTPUB"){
if (!is.null(hideCrossCountry)) filteredArticles <- subset(filteredArticles,!grepl(hideCountryPattern, Country.of.Publication..1st.Author.))
filteredArticles <- subset(filteredArticles,grepl(countryPattern, Country.of.Publication..1st.Author.))
}
else if (crossFilterType == "RESTPUB"){
if (!is.null(hideCrossCountry)) filteredArticles <- subset(filteredArticles,!grepl(hideCountryPattern, Country.of.Publication..Rest.of.authors.))
filteredArticles <- subset(filteredArticles,grepl(countryPattern, Country.of.Publication..Rest.of.authors.))
}
else if (crossFilterType == "ALLPUB"){
if (!is.null(hideCrossCountry)){
filteredArticles <- subset(filteredArticles,!grepl(hideCountryPattern, Country.of.Publication..1st.Author.))
filteredArticles <- subset(filteredArticles,!grepl(hideCountryPattern, Country.of.Publication..Rest.of.authors.))
}
filteredArticles <- subset(filteredArticles,(grepl(countryPattern, paste(Country.of.Publication..1st.Author.,Country.of.Publication..Rest.of.authors.))))
}
}
#filteredArticles <- subset(filteredArticles, (Place.of.Publish..1st.author. %in% university))
#filteredArticles <- subset(filteredArticles, (Publisher %in% publisher))
#filteredArticles <- subset(filteredArticles, (Second.Keyword %in% keywordList))
print(c("Filtered article number", dim(filteredArticles)[1]))
#write.csv(filteredArticles,"test.csv")
return (filteredArticles)
}
getStat <- function(filteredArticles, mapFilter, hideCountry, countryFilter){
#This is a middle file between the source and the data source for the map
midparticipatory <- countries@data
midparticipatory$Count <- 0
#mapFilter determines what data to show? "WORK", "FIRSTPUB", "RESTPUB", "ALLPUB"
if (mapFilter == "WORK") crossarray<-sapply(filteredArticles$Place.of.Work, as.character)
else if(mapFilter == "FIRSTPUB") crossarray<-sapply(filteredArticles$Country.of.Publication..1st.Author., as.character)
else if(mapFilter == "RESTPUB") crossarray<-sapply(filteredArticles$Country.of.Publication..Rest.of.authors., as.character)
else if(mapFilter == "ALLPUB"){
s<-sapply(filteredArticles$Country.of.Publication..1st.Author., as.character)
t<-sapply(filteredArticles$Country.of.Publication..Rest.of.authors., as.character)
crossarray<-paste(s, t)
}
crossarray <- paste(crossarray,collapse=",")
# traverse the middle participatory to count number of articles filtered
for (i in 1:nrow(midparticipatory)){
countryISO2name <- midparticipatory[i,"ISO2"] %>% as.character()
if (midparticipatory$NAME[i] %in% hideCountry){
midparticipatory$Count[i] <- 0
}
else if (!is.null(countryFilter)){
if (midparticipatory$NAME[i] %in% countryFilter){
#print(c("mid name", midparticipatory$NAME[i], "in filter:", countryFilter))
midparticipatory$Count[i] <- str_count(crossarray,pattern=countryISO2name)
}
}
else {
midparticipatory$Count[i] <- str_count(crossarray,pattern=countryISO2name)
}
#midparticipatory$Count[i] <- str_count(crossarray,pattern=countryISO2name)
}
#write.csv(midparticipatory, file = "test.csv")
countries@data <- midparticipatory
return(countries)
}