nonsensical
Advanced tools
Comparing version 0.4.0 to 0.5.0
{ | ||
"name": "nonsensical", | ||
"description": "Generate somewhat grammatical sentences of nonsense", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
@@ -32,21 +32,14 @@ | ||
> Some codes of the void air a nihility. | ||
> Those nihilities in the verb pass those estimators. | ||
> The noun in those spaces exhibitted the pragmatism. | ||
> A world on the dimension placed the metres. | ||
> Those regular hexahedra in the distances scromble some times. | ||
> A reckoner on those third powers frames the noun. | ||
> Some entities in some cubes render the electronic computer. | ||
> The graphic in those cubes uploads an attribute. | ||
> Those texts in the texts bring forth those spaces. | ||
> Those pillars in a data processor became an orang. | ||
> The production on the outputs goes past a Pongo pygmaeus. | ||
> Some anchors in the turnouts transgress the reality. | ||
> A secret plot in the charming saddle block anesthesias slammed those lacrimal sacs. | ||
> An enlisted woman on the adductive pitch blackness navigated an animatism. | ||
> Some spatula-shaped floricultures on the trap destressed the bad park. | ||
> A fight in a Malaysian straightenned some rosy-colored flags. | ||
> The imbricated throat in an alarming fire brigade queried a Circassian. | ||
> Some affixal icicles in a wintertime erred some white yams. | ||
> The virtuous sweetener in the ambulatory vase glorifies a downmarket graveyard. | ||
> Those cherries in a flying iron boot pursue some Plautuses. | ||
> Some stingy snows in those scriptural contraptions construct a Lygodium palmatum. | ||
So far it's somewhat homogeneous. There's only *one sentence structure* output! | ||
(DET NOUN PREP DET NOUN VERB DET NOUN PUNCT) | ||
In [the app](https://1j01.itch.io/nonsensical) you can mess around with giving it seed/suggestion/topic words. | ||
But it's already fun. | ||
In [the app](https://1j01.itch.io/nonsensical) currently uses seed words themed around [r/SurrealMemes](https://www.reddit.com/r/surrealmemes/) | ||
and computers. | ||
@@ -101,3 +94,3 @@ ## Install | ||
verbs: ["purr", "pet", "hiss", "catch", "chase", "sleep"], | ||
adjectives: ["soft", "warm"] // not used yet! | ||
adjectives: ["soft", "warm"] | ||
}, | ||
@@ -104,0 +97,0 @@ useSuggestionRelatedWordChance: 1/2, |
@@ -7,3 +7,10 @@ const Nonsensical = require("./nonsensical"); | ||
const another_one_button = document.getElementById("another-one"); | ||
// const previous_one_button = document.getElementById("previous-one"); | ||
const toggle_config_button = document.getElementById("toggle-config"); | ||
const config_container = document.getElementById("config"); | ||
const nouns_input = document.getElementById("nouns"); | ||
const verbs_input = document.getElementById("verbs"); | ||
const adjectives_input = document.getElementById("adjectives"); | ||
const adverbs_input = document.getElementById("adverbs"); | ||
// const presets_select = document.getElementById("presets"); | ||
// const use_suggestion_chance_slider = document.getElementById("use-suggestion-chance"); | ||
@@ -17,6 +24,15 @@ const data_file_paths = { | ||
const SOME_VERBS = ["keyboard", "output", "generate", "put", "display", "render", "upload", "consume", "transcend", "ascend", "assemble", "scromble", "scronch", "become", "fear"]; | ||
const SOME_NOUNS = ["type", "output", "code", "graphic", "computer", "screen", "text", "orang", "meme man", "vegetal", "cube", "dimension", "hypercube", "pillar", "space", "time", "reality", "entity", "void", "meme"]; | ||
const SOME_ADJECTIVES = ["aesthetic", "surreal", "hyperdimensional", "human", "real", "true", "cuboid", "cool", "good", "cool and good", "ANGERY"]; | ||
toggle_config_button.onclick = () => { | ||
if (config_container.classList.contains("hidden")) { | ||
config_container.style.height = "0px"; | ||
config_container.classList.remove("hidden"); | ||
config_container.style.height = config_container.scrollHeight + "px"; | ||
} else { | ||
config_container.classList.add("hidden"); | ||
config_container.style.height = "0px"; | ||
} | ||
}; | ||
const split_words = (input_text) => input_text.split(/[,\s]\s*/); | ||
loading_indicator.removeAttribute("hidden"); | ||
@@ -32,7 +48,8 @@ nonsensical.load(data_file_paths, function () { | ||
wordSuggestions: { | ||
nouns: SOME_NOUNS, | ||
verbs: SOME_VERBS, | ||
adjectives: SOME_ADJECTIVES, | ||
nouns: split_words(nouns_input.value), | ||
verbs: split_words(verbs_input.value), | ||
adjectives: split_words(adjectives_input.value), | ||
adverbs: split_words(adverbs_input.value), | ||
}, | ||
useSuggestionRelatedWordChance: 1, | ||
useSuggestionRelatedWordChance: 1 / 2,//parseFloat(use_suggestion_chance_slider.value) / 100, | ||
maxSemanticStepsRemovedFromSuggestions: 5 | ||
@@ -53,6 +70,2 @@ }); | ||
another_one_button.onclick = another_one; | ||
// previous_one_button.onclick = ()=> { | ||
// history.back(); | ||
// }; | ||
}); |
@@ -22,2 +22,3 @@ const Wordnet = require("wordnetjs"); | ||
} | ||
load(files, callback) { | ||
@@ -28,4 +29,9 @@ // TODO: error handling | ||
} | ||
generateSentence(options = {}) { | ||
this._word_suggestions = Object.assign({}, default_word_suggestions, options.wordSuggestions); | ||
for (let key in this._word_suggestions) { | ||
this._word_suggestions[key] = this._word_suggestions[key].filter((suggestion) => suggestion); | ||
} | ||
this._use_suggestion_related_word_chance = options.useSuggestionRelatedWordChance != null ? | ||
@@ -39,7 +45,7 @@ options.useSuggestionRelatedWordChance : default_use_suggestion_related_word_chance; | ||
_find_a_word(part_of_speech, search_base_terms, semantic_removal_depth = 0) { | ||
_find_a_term(part_of_speech, search_base_terms, semantic_removal_depth = 0) { | ||
if (!search_base_terms) { | ||
// const word_suggestions_key = tag_to_suggestions_part_of_speech[tag]; | ||
const word_suggestions_key = part_of_speech + "s"; | ||
if (Math.random() < this._use_suggestion_related_word_chance) { | ||
if (Math.random() < this._use_suggestion_related_word_chance && this._word_suggestions[word_suggestions_key].length) { | ||
search_base_terms = this._word_suggestions[word_suggestions_key]; | ||
@@ -50,3 +56,3 @@ } else { | ||
} | ||
if (this._max_semantic_steps_removed_from_suggestions < 1) { | ||
if (Math.random() < 0.7 || this._max_semantic_steps_removed_from_suggestions < 1) { | ||
return choose(search_base_terms); | ||
@@ -66,3 +72,3 @@ } | ||
if (Math.random() < 0.5 && semantic_removal_depth < this._max_semantic_steps_removed_from_suggestions) { | ||
return this._find_a_word(part_of_speech, [word], semantic_removal_depth + 1); | ||
return this._find_a_term(part_of_speech, [word], semantic_removal_depth + 1); | ||
} | ||
@@ -76,5 +82,7 @@ return word; | ||
_make_noun() { | ||
const noun = new Token({ partOfSpeech: { tag: TAG.NOUN } }); | ||
// TODO: make sure lemmas are lemmas | ||
noun.lemma = this._find_a_word("noun"); | ||
const noun = new Token({ | ||
partOfSpeech: { tag: TAG.NOUN }, | ||
// TODO: do something about the fact that these aren't necessarily single words and thus not really lemmas | ||
lemma: this._find_a_term("noun"), | ||
}); | ||
noun.partOfSpeech.number = choose([NUMBER.PLURAL, NUMBER.SINGULAR]) | ||
@@ -87,36 +95,82 @@ if (noun.partOfSpeech.number === NUMBER.PLURAL || noun.partOfSpeech.number === NUMBER.DUAL) { | ||
return noun; | ||
}; | ||
} | ||
_make_spicy_noun() { | ||
const noun = this._make_noun(); | ||
const initial_noun_text = this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun)); | ||
const determiner = new Token({ partOfSpeech: { tag: TAG.DET } }); | ||
noun.addDependency(determiner, "det"); | ||
if (noun.partOfSpeech.number === NUMBER.PLURAL) { | ||
determiner.text = choose(["some", "some", "those", "those", "the"]); // could include informal "them"/"dem"/"'em" | ||
// console.log(`using plural determiner: \`${this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun))}\` for`, noun); | ||
} else { | ||
if (Math.random() < 0.5) { | ||
determiner.text = get_indefinite_article(initial_noun_text); | ||
// TODO: compound nouns | ||
if (Math.random() < 0.5) { | ||
// TODO: use an enum for all labels | ||
noun.addDependency(this._make_adjective(), "adj"); | ||
} | ||
const det_chance = noun.partOfSpeech.number === NUMBER.PLURAL || noun.partOfSpeech.number === NUMBER.DUAL ? | ||
0.7 : 1; | ||
// TODO: pronouns/possessives | ||
if (Math.random() < det_chance) { | ||
const noun_text_before_adding_determiner = this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun)); | ||
const determiner = new Token({ partOfSpeech: { tag: TAG.DET } }); | ||
noun.addDependency(determiner, "det"); | ||
if (noun.partOfSpeech.number === NUMBER.PLURAL) { | ||
determiner.text = choose([ | ||
"some", "some", | ||
"those", "those", | ||
"the", "the", "the", | ||
"many", "both", "a couple", "a few", | ||
// could include informal "them"/"dem"/"'em"; 'em would warrant better capitaliZation rools | ||
// "each" would need a singular noun or a preposition | ||
]); | ||
// console.log(`using plural determiner: \`${this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun))}\` for`, noun); | ||
} else if (noun.partOfSpeech.number === NUMBER.DUAL) { | ||
// DUAL is not really a thing in English, but it'd be something like this: | ||
determiner.text = choose(["the", "both"]); | ||
} else { | ||
determiner.text = "the"; | ||
if (Math.random() < 0.5) { | ||
// TODO: do this determination later? | ||
determiner.text = get_indefinite_article(noun_text_before_adding_determiner); | ||
} else { | ||
determiner.text = "the"; | ||
} | ||
// console.log(`using singular determiner: \`${this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun))}\` for`, noun); | ||
} | ||
// console.log(`using singular determiner: \`${this._stringify_tokens_array(this._make_flat_tokens_array_from_structure(noun))}\` for`, noun); | ||
} | ||
return noun; | ||
}; | ||
} | ||
_make_adpositional_phrase() { | ||
const preposition = new Token({ partOfSpeech: { tag: TAG.ADP } }); | ||
_make_adjective() { | ||
return new Token({ | ||
partOfSpeech: { tag: TAG.ADJ }, | ||
lemma: this._find_a_term("adjective"), | ||
}); | ||
} | ||
_make_adverb() { | ||
return new Token({ | ||
partOfSpeech: { tag: TAG.ADV }, | ||
lemma: this._find_a_term("adverb"), | ||
}); | ||
} | ||
_make_adpositional_phrase(recurse_depth = 0) { | ||
const max_recurse_depth = 2; | ||
const preposition = new Token({ | ||
partOfSpeech: { tag: TAG.ADP }, | ||
lemma: choose(["in", "in", "in", "on", "of"]), | ||
}); | ||
const preposition_object_noun = this._make_spicy_noun(); | ||
preposition.lemma = choose(["in", "in", "in", "on", "of"]); | ||
if (Math.random() < 0.1 && recurse_depth < max_recurse_depth) { | ||
preposition_object_noun.addDependency(this._make_adpositional_phrase(recurse_depth + 1), "prep"); | ||
} | ||
preposition.addDependency(preposition_object_noun, "pobj"); | ||
return preposition; | ||
}; | ||
} | ||
_make_verb() { | ||
const verb = new Token({ partOfSpeech: { tag: TAG.VERB } }); | ||
verb.lemma = this._find_a_word("verb"); | ||
const verb = new Token({ | ||
partOfSpeech: { tag: TAG.VERB }, | ||
// TODO: detect when the term has multiple words and especially if it includes an object (like "express joy") | ||
// maybe pass in the lemma from outside? idk, this whole system is kinda messy | ||
lemma: this._find_a_term("verb"), | ||
}); | ||
// TODO: this should probably be at a later step, | ||
// since it has to get overridden later in at least one case | ||
// Note: one piece of code stringifies a noun during generation in order to do a/an | ||
if (Math.random() < 0.5) { | ||
@@ -127,2 +181,4 @@ verb.text = tensify_verb_phrase(verb.lemma, "past"); | ||
// Note: plural means _without_ an s | ||
// FIXME: removes s's from words with double s's like access, toss, etc. | ||
// but we do want to do normalization here ideally, especially for input from the app | ||
verb.text = tensify_verb_phrase(verb.lemma, "present_plural"); | ||
@@ -132,5 +188,6 @@ verb.partOfSpeech.tense = TENSE.PRESENT; | ||
return verb; | ||
}; | ||
} | ||
_make_structure() { | ||
// TODO: compound verbs, compound sentences | ||
const root_verb = this._make_verb(); | ||
@@ -141,4 +198,9 @@ root_verb.label = "root"; | ||
const object_noun = this._make_spicy_noun(); | ||
// TODO: adverbs after object sometimes too | ||
root_verb.addDependency(this._make_adverb(), "advmod"); | ||
root_verb.addDependency(subject_noun, "nsubj"); | ||
subject_noun.addDependency(this._make_adpositional_phrase(), "prep"); | ||
if (Math.random() < 0.5) { | ||
subject_noun.addDependency(this._make_adpositional_phrase(), "prep"); | ||
} | ||
// TODO: handle intransitive verbs (no direct object) | ||
root_verb.addDependency(object_noun, "nobj"); | ||
@@ -152,3 +214,3 @@ root_verb.addDependency(ending_punctuation, "p"); | ||
return root_verb; | ||
}; | ||
} | ||
@@ -171,2 +233,6 @@ _make_flat_tokens_array_from_structure(token) { | ||
// but there are also phrases like "in the room, there's a clock" | ||
} else if (dep_tag === TAG.ADJ) { | ||
// adjectives prospective may be ordered poetic / poetic, reversed, and aft | ||
// that would be with a flag, you see / not just global, no don't be daft | ||
dep_after = false; | ||
} else { | ||
@@ -184,3 +250,3 @@ dep_after = (dep_tag === TAG.NOUN && dep_token.label === "nobj"); | ||
return tokens; | ||
}; | ||
} | ||
@@ -201,3 +267,3 @@ _stringify_tokens_array(tokens) { | ||
return text; | ||
}; | ||
} | ||
@@ -212,3 +278,3 @@ _generate_sentence() { | ||
return sentence; | ||
}; | ||
} | ||
@@ -215,0 +281,0 @@ } |
const Nonsensical = require("./nonsensical"); | ||
const nonsensical = new Nonsensical(); | ||
global.window = { | ||
fetch: (path)=> { | ||
return new Promise(function(resolve, reject){ | ||
require("fs").readFile(path, "utf8", function(err, data){ | ||
if(err){ | ||
fetch: (path) => { | ||
return new Promise(function (resolve, reject) { | ||
require("fs").readFile(path, "utf8", function (err, data) { | ||
if (err) { | ||
reject(err); | ||
}else{ | ||
} else { | ||
resolve({ | ||
json: ()=> JSON.parse(data) | ||
json: () => JSON.parse(data) | ||
}); | ||
@@ -24,4 +24,4 @@ } | ||
}; | ||
nonsensical.load(data_file_paths, function(){ | ||
nonsensical.load(data_file_paths, function () { | ||
console.log(nonsensical.generateSentence()); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35869283
21582
151
2
11