R/word_associations.R

Defines functions word_associations

Documented in word_associations

word_associations = function(term,abs){res = Give_Sentences(term,abs);if (length(res) != 0) {res = unlist(res);resr1 = gregexpr("\\w+",res);res2 = lapply(1:length(res),function(x){temp = regmatches(res[x],resr1[x]); temp1 = which(temp[[1]] == term); temp0 = length(temp[[1]]);temp3 = NULL;for (i in 1:length(temp1)) {if (temp1[i] < temp0) {temp2 = c(temp1[i] - 1,temp1[i],temp1[i] + 1);  if (temp2[1] == 0) temp2[1] = 1;start = resr1[[x]][temp2[1]]; stop = (resr1[[x]][temp2[3]] + attr(resr1[[x]],"match.length")[temp2[3]]);temp3 = substr(res[x],start,stop)} else {temp2 = c(temp1[i] - 1,temp1[i]);if (temp2[1] == 0) temp2[1] = 1; start = resr1[[x]][temp2[1]]; stop = (resr1[[x]][temp2[2]] + attr(resr1[[x]],"match.length")[temp2[2]]);temp3 = substr(res[x],start,stop)}};return(temp3)});return(res2)} else return("term not found")}

Try the pubmed.mineR package in your browser

Any scripts or data that you put into this service are public.

pubmed.mineR documentation built on Nov. 26, 2021, 5:11 p.m.