-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nils Reiter
committed
Oct 20, 2017
1 parent
a449ac9
commit 4e7daff
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' @name personnelExchange | ||
#' @title Measuring Personnel Exchange over Boundaries | ||
#' @aliases hamming | ||
#' @aliases scenicDifference | ||
#' @description There are multiple ways to quantify the number of characters that are | ||
#' exchanged over a scene or act boundary. | ||
#' @param mtext The segmented drama text | ||
#' @param variant For hamming(), variants are "Trilcke" (default), "NormalizedHamming", and "Hamming" | ||
#' @param norm For scenicDifference(), specifies the normalization constant | ||
#' @rdname personnelExchange | ||
#' @export | ||
#' @examples | ||
#' data(rksp.0) | ||
#' dist_trilcke <- hamming(rksp.0$mtext) | ||
#' dist_hamming <- hamming(rksp.0$mtext, variant = "Hamming") | ||
#' dist_nhamming <- hamming(rksp.0$mtext, variant = "NormalizedHamming") | ||
hamming <- function(mtext, variant=c("Trilcke","Hamming","NormalizedHamming")) { | ||
mtext <- na.omit(mtext) | ||
numberOfFigures <- length(unique(mtext$Speaker.figure_surface)) | ||
scenes <- length(unique(mtext$begin.Scene)) | ||
pm <- configuration(mtext, by="Scene", onlyPresence = TRUE) | ||
vec <- vector(mode="integer",length=scenes-1) | ||
variant <- match.arg(variant) | ||
for (i in 1:(ncol(pm$matrix)-1)) { | ||
allFigures <- switch(variant, | ||
Trilcke=sum(pm$matrix[,i] | pm$matrix[,i+1]), | ||
Hamming=1, | ||
NormalizedHamming=numberOfFigures) | ||
edits <- sum(xor(pm$matrix[,i],pm$matrix[,i+1])) | ||
vec[i] <- edits/allFigures | ||
} | ||
vec | ||
} | ||
|
||
#' @rdname personnelExchange | ||
#' @export | ||
scenicDifference <- function(mtext, norm=length(unique(mtext$Speaker.figure_surface))) { | ||
mtext <- na.omit(mtext) | ||
numberOfFigures <- length(unique(mtext$Speaker.figure_surface)) | ||
scenes <- length(unique(mtext$begin.Scene)) | ||
|
||
pm <- configuration(mtext, by="Scene", onlyPresence = TRUE) | ||
vec <- vector(mode="integer",length=scenes-1) | ||
for (i in 1:(ncol(pm$matrix)-1)) { | ||
same <- sum(pm$matrix[,i] & pm$matrix[,i+1]) | ||
vec[i] <- numberOfFigures - same | ||
} | ||
vec/norm | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.