tag:blogger.com,1999:blog-5482711974230096808.post7406869190847472728..comments2019-01-25T04:10:15.294-05:00Comments on Computing in Psychological Research: Developing a user-friendly regular expression function (easyGregexpr)Michaelhttp://www.blogger.com/profile/16966694492052508244noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5482711974230096808.post-87784742127327189072019-01-25T04:08:13.120-05:002019-01-25T04:08:13.120-05:00java programming code snippets
Applet that demonst...java programming code snippets<br /><a href="https://java.happycodings.com/java2d/code2.html" rel="nofollow">Applet that demonstrates a Java2D GeneralPath</a><br />sunsethttps://www.blogger.com/profile/13290811765991812385noreply@blogger.comtag:blogger.com,1999:blog-5482711974230096808.post-32922314974325950592010-09-18T20:48:06.531-04:002010-09-18T20:48:06.531-04:00Your post rocks. I'll thank you in advance for...Your post rocks. I'll thank you in advance for the time you have saved me. Now I can play more TF2.JFKhttps://www.blogger.com/profile/02528881172701909757noreply@blogger.comtag:blogger.com,1999:blog-5482711974230096808.post-20976111080402539362010-06-04T18:30:37.407-04:002010-06-04T18:30:37.407-04:00This is the function I use, comments are welcome!
...This is the function I use, comments are welcome!<br /><br />exact.matches <- function(search.expression, corpus.vector, pcre=TRUE, case.sens=TRUE, output=1:5) {<br /><br />search.parameters <- c(search.expression, substr(corpus.vector[1], 1, 100), pcre, case.sens)<br />names(search.parameters) <- c("pattern", "corpus (1st 100 char.)", "PCRE", "case-sensitive")<br /><br /> # identify all line numbers of lines that contain at least one match<br /> line.numbers.with.matches <- grep(search.expression, corpus.vector, perl=pcre, value=FALSE, ignore.case=!case.sens)<br /><br /> # if there are no matches, stop<br /> if(any(line.numbers.with.matches)==TRUE) {<br /><br /> # identify all lines that contain at least one match<br /> lines.with.matches <- corpus.vector[line.numbers.with.matches]<br /><br /> # get the exact starting positions and lengths of the matches<br /> matches <- gregexpr(search.expression, lines.with.matches, perl=pcre, ignore.case=!case.sens)<br /><br /> # get the number of matches per line<br /> number.of.matches <- sapply(matches, length)<br /><br /> # generate a vector that contains the line numbers as often as often as there are matches in each line<br /> line.numbers <- rep(line.numbers.with.matches, number.of.matches)<br /><br /> # generate a vector that contains the lines as often as often as there are matches in each line<br /> lines <- rep(lines.with.matches, number.of.matches)<br /><br /> # generate vectors of all starting and stop positions for substr<br /> starts <- unlist(matches)<br /> stops <- starts+unlist(sapply(matches, attributes))-1<br /><br /> # generate a vector with all the exact matches regardless of where they occur<br /> exact.string.matches <- substr(lines, starts, stops)<br /><br /> # generate a vector with the locations of the exact matches<br /> exact.string.matches.loc <- line.numbers<br /><br /> # generate a vector with lines that have tab stops before and after each match<br /> lines.with.delimited.matches <- paste("Line: ", line.numbers, "\t",<br /> substr(lines, 1, starts-1), "\t",<br /> substr(lines, starts, stops), "\t",<br /> substr(lines, stops+1, 10^9),<br /> sep="")<br /><br /> output.list <- list("exact matches"=exact.string.matches,<br /> "locations of matches"=exact.string.matches.loc,<br /> "proportion of corpus parts with matches"=length(line.numbers.with.matches)/length(corpus.vector),<br /> "lines with delimited matches"=lines.with.delimited.matches,<br /> "search parameters"=search.parameters)<br /> return(output.list[output])<br /> }<br />}STGhttps://www.blogger.com/profile/00776241079325719811noreply@blogger.comtag:blogger.com,1999:blog-5482711974230096808.post-6954574357343466072010-05-04T13:50:31.791-04:002010-05-04T13:50:31.791-04:00You might want to check out the gsubfn package, to...You might want to check out the gsubfn package, too:<br /><br />http://code.google.com/p/gsubfn/Steve Lianoglouhttps://www.blogger.com/profile/01538274673179158781noreply@blogger.com