<jupyter_start><jupyter_text>SynopsisUse Jockers' [Syuzhet module](https://rdrr.io/cran/syuzhet/) in R.To use R in Jupyter, see https://docs.anaconda.com/anaconda/navigator/tutorials/r-lang/  Configuration<jupyter_code># methods = c("syuzhet", "afinn", "bing", "nrc", "stanford")
# Try bing or syuzhet
method = 'syuzhet'
fft_low_pass = 3
dct_low_pass = 5<jupyter_output><empty_output><jupyter_text>Libraries<jupyter_code>library(syuzhet)
library(repr)<jupyter_output><empty_output><jupyter_text>Pragmas<jupyter_code>options(repr.plot.width=5, repr.plot.height=3)
# system("export PATH=$PATH:/Users/rca2t/stanford-corenlp")<jupyter_output><empty_output><jupyter_text>Process  Persuasion<jupyter_code>pers.file <- "persuasion.txt"
pers <- get_text_as_string(pers.file)
pers.s_v <- get_sentences(pers)
pers.sentiment_vector <- get_sentiment(pers.s_v, method=method)<jupyter_output><empty_output><jupyter_text>Raw Signal<jupyter_code>plot(pers.sentiment_vector, 
     type="l", 
     main="Persuasion Plot Trajectory", 
     xlab = "Narrative Time", 
     ylab= "Emotional Valence")
pers.ft_values <- get_transformed_values(pers.sentiment_vector, 
                                         low_pass_size=fft_low_pass, 
                                         x_reverse_len=100, 
                                         scale_vals=TRUE, 
                                         scale_range=FALSE)<jupyter_output>Warning message in get_transformed_values(pers.sentiment_vector, low_pass_size = fft_low_pass, :
“This function is maintained for legacy purposes.  Consider using get_dct_transform() instead.”<jupyter_text>Transformed<jupyter_code>plot(pers.ft_values, 
     type ="h", 
     main ="Auten's Persuasion transformed", 
     xlab = "narrative time", 
     ylab = "Emotional Valence", col = "red")<jupyter_output><empty_output><jupyter_text>Moby Dick<jupyter_code>moby_file <- "moby.txt"
moby <- get_text_as_string(moby_file)
moby.s_v <- get_sentences(moby)
moby.sentiment_vector <- get_sentiment(moby.s_v, method=method)<jupyter_output><empty_output><jupyter_text>Raw Signal<jupyter_code>plot(moby.sentiment_vector, 
     type="l", 
     main="Moby Dick Plot Trajectory", 
     xlab = "Narrative Time", 
     ylab= "Emotional Valence")
moby.ft_values <- get_transformed_values(moby.sentiment_vector, 
                                     low_pass_size=fft_low_pass, 
                                     x_reverse_len=100,
                                     scale_vals=TRUE, 
                                     scale_range=FALSE)<jupyter_output>Warning message in get_transformed_values(moby.sentiment_vector, low_pass_size = fft_low_pass, :
“This function is maintained for legacy purposes.  Consider using get_dct_transform() instead.”<jupyter_text>Transformed<jupyter_code>plot(moby.ft_values,
     type ="h", 
     main ="Moby Dick transformed", 
     xlab = "narrative time", 
     ylab = "Emotional Valence", col = "red")<jupyter_output><empty_output><jupyter_text>DCT Versions  Moby Dick<jupyter_code>moby.dct = get_dct_transform(
    raw_values = moby.sentiment_vector, 
    low_pass_size = dct_low_pass,
    scale_vals = T)

jpeg("moby_rplot.jpg", width = 650, height = 350)
plot(moby.dct, 
     type ="h", 
     main ="Moby Dick transformed (DCT)", 
     xlab = "narrative time", 
     ylab = "Emotional Valence", 
     col = "red")
dev.off()<jupyter_output><empty_output><jupyter_text>Persuasion<jupyter_code>pers.dct = get_dct_transform(
    raw_values = pers.sentiment_vector, 
    low_pass_size = dct_low_pass,
    scale_vals = T)

jpeg("pers_rplot.jpg", width = 650, height = 350)
plot(pers.dct, 
     type ="h", 
     main ="Persuasion transformed (DCT)", 
     xlab = "narrative time", 
     ylab = "Emotional Valence", 
     col = "red")
dev.off()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11487907465825446, 'fraction_numerical': 0.006046267087276551, 'mean_word_length': 3.595410628019324, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 43, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '57593', 'license': 'MIT', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1336, 'n_words': 206, 'path': 'labs/2019-04-11_Lab11/DS5559_Syuzhet_R.ipynb', 'repo_name': 'samarthsing/DSI', 'size': '3804'}