generate_sentence: Generate sentences.

Description Usage Arguments Details Value Word types Word info codes Author(s) Examples

Description

Generates sentences by inserting randomly selected words of specified word types at specified locations in sentence structures.

Use internal sentence structures and / or provide your own.

Use internal word lists and / or provide your own.

Specify constraints on the selection of words.

Usage

1
2
generate_sentence(n = 1, structures = NULL, word_lists = NULL,
  int_structures = TRUE, int_word_lists = TRUE)

Arguments

n

Number of sentences to generate (Integer).

structures

Character Vector. E.g.:

c("My [noun] is [positive_adj] today!", "[salutation]! How you've grown with the task!")

Constrain the selection of words by specifying word info codes. E.g. only sample elements from the word list with max. 1 word in them, i.e. no white spaces:

"[salutation(w1)]"

Pass multiple word types - from which one is randomly selected:

"[male_first_name/female_first_name]"

See available Word Types below.

See available Word Info Codes below.

word_lists

List of word lists. A word list is named by the word type, e.g. verb.

int_structures

Use internal structures (Logical).

int_word_lists

Use internal word lists (Logical).

Details

A structure is randomly chosen. To make sure you get a specific structure, pass only one structure and set int_structures to FALSE.

Value

Character Vector

Word types

Word lists have been collected from the internet. They might contain words that seem out of place. Let me know and I'll remove them.

Positive words

[superb] [positive_adj] [positive_vb] [positive_vb_past] [positive_adv]

Verb forms

[verb_base] [verb_past] [verb_past_participle] [verb_es] [verb_ing]

Noun forms

[noun] [noun_plural]

Persons

[salutation] [male_first_name] [female_first_name] [male_full_name] [female_full_name]

Specific synonyms

Notice: These are added as needed by author.

[create_syn] [small_syn] [big_syn]

Nationality

[nationality_adj] [nationality_people]

Statistics

[statistics_tradition]

Word info codes

w + number

Sample from elements with maximum number of words, i.e. number of white spaces -1.

E.g.: (w1)

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Attach package
library(bhappyr)

# Create structures
st <- c("[salutation]! You are [positive_adj] today! ;)",
        "You [positive_vb_past] that code! [positive_adj]!")

# Create list of word lists
wl <- list("salutation" = c("Sir", "Mother", "Dear", "Friend"),
           "positive_adj" = c("beautiful", "bright", "smart"),
           "positive_vb_past" = c("accomplished","played", "modified"))

## Example 1
# Using internal structures + word lists

# Generate 1 sentence
generate_sentence()

## Example 2
# Providing structures
# and not using internal structures

# Generate 2 sentences
generate_sentence(n = 3, structures = st,
                  int_structures = FALSE)

## Example 3
# Providing word_lists and structures
# and not using internal word_lists and structures

# Generate 3 sentences
generate_sentence(n = 3, structures = st,
                  word_lists = wl,
                  int_structures = FALSE,
                  int_word_lists = FALSE)

LudvigOlsen/bhappyr documentation built on May 7, 2019, 2:02 p.m.