Learn R Programming

LSAfun (version 0.6.2)

coherence: Coherence of a text

Description

Computes coherence of a given paragraph/document

Usage

coherence(x,split=c(".","!","?"),tvectors=tvectors,breakdown=FALSE)

Arguments

x

a character vector of length(x) = 1 containing the document

split

a vector of expressions that determine where to split sentences

tvectors

the semantic space in which the computation is to be done (a numeric matrix where every row is a word vector)

breakdown

if TRUE, the function breakdown is applied to the input

Value

A list of two elements; the first element ($local) contains the local coherences as a numeric vector, the second element ($global) contains the global coherence as a numeric.

Details

This function applies the method described in Landauer & Dumais (1997): The local coherence is the cosine between two adjacent sentences. The global coherence is then computed as the mean value of these local coherences. The format of x (or y) should be of the kind x <- "sentence1. sentence2. sentence3" Every sentence can also just consist of one single word. To import a document Document.txt to from a directory for coherence computation, set your working directory to this directory using setwd(). Then use the following command lines: fileName1 <- "Alice_in_Wonderland.txt" x <- readChar(fileName1, file.info(fileName1)$size)

References

Landauer, T.K., & Dumais, S.T. (1997). A solution to Plato's problem: The Latent Semantic Analysis theory of acquisition, induction and representation of knowledge. Psychological Review, 104, 211-240.

See Also

cosine, Cosine, costring

Examples

Run this code
# NOT RUN {
data(wonderland)

coherence ("There was certainly too much of it in the air. Even the Duchess
sneezed occasionally; and as for the baby, it was sneezing and howling
alternately without a moment's pause. The only things in the kitchen
that did not sneeze, were the cook, and a large cat which was sitting on
the hearth and grinning from ear to ear.",
tvectors=wonderland)
# }

Run the code above in your browser using DataLab