@_zaphod/scribejs 中文文档教程

发布于 4年前 浏览 28 项目主页 更新于 3年前

ScribeJS ????

ScribeJS 是一个包,允许您通过提供值和数据集来创建随机生成的句子 指定您希望随机化句子的哪些部分。

Syntax

Defining datasets

您的所有数据集都应该是数组,它们包含的值应该是字符串。\ 然后,这些数据集应全部放置在一个对象中,然后该对象可以传递给 ScribeJS 以供使用。

示例:

{
  "animals": ["cat", "dog", "cow", "pig", "monkey"],
  "names": ["Sylvan", "Kieran", "Tej", "Jon", "AJ"],
  "places": ["London", "Birmingham", "Telford", "Liverpool"],
  "objects": ["cup", "pen", "keyboard", "glass"]
}

Defining datasets in sentences

要指定您希望随机化句子中的哪些词以及它们应该使用哪个数据集,您只需写下 你的数据集是这样的:|animals| 并将其嵌入到句子中你希望它从中生成单词的地方 数据集。

句子示例:Hello my name is |names|

API

generator(sentence: string): string

  • Takes in a sentence that contains dataset references
  • Returns the sentence with the dataset references replaced with randomised values from that dataset.

Example

下面的示例展示了您可能如何实现 ScribeJS:

// Import the package into our JS file.
import Scribe from "scribejs";

// Define an array with datasets that we want to use.
const datasets = {
  animal: ["cat", "dog", "cow", "pig", "monkey"],
  person: ["Sylvan", "Kieran", "Tej", "Jon", "AJ"]
};

// Initalise ScribeJS and pass in the datasets.
const scribe = new Scribe(datasets);

// Call the generator function and pass in the sentence we want to randomise.
const result = scribe.generator("|person| went to the park. At the park they saw a |animal|!");

上面示例的潜在结果包括:

Sylvan went to the park. At the park he saw a cat!
Kieran went to the park. At the park he saw a dog!
AJ went to the park. At the park he saw a cow!
Sylvan went to the park. At the park he saw a monkey!
ect...

ScribeJS ????

ScribeJS is a package that allows you to create randomly generated sentences by providing datasets of values and specifying which parts of a sentence you wish to randomise.

Syntax

Defining datasets

All of your datasets should be arrays and the values that they contain should be strings.\ These datasets should then all be placed within an object that can then be passed to ScribeJS to be used.

Example:

{
  "animals": ["cat", "dog", "cow", "pig", "monkey"],
  "names": ["Sylvan", "Kieran", "Tej", "Jon", "AJ"],
  "places": ["London", "Birmingham", "Telford", "Liverpool"],
  "objects": ["cup", "pen", "keyboard", "glass"]
}

Defining datasets in sentences

To specify what words in a sentence you wish to randomise and which dataset they should use you simply write the name of your dataset like this: |animals| and embed it into the sentence where ever you want it to generate a word from that dataset.

Example in sentence: Hello my name is |names|

API

generator(sentence: string): string

  • Takes in a sentence that contains dataset references
  • Returns the sentence with the dataset references replaced with randomised values from that dataset.

Example

The example below shows how you might implement ScribeJS:

// Import the package into our JS file.
import Scribe from "scribejs";

// Define an array with datasets that we want to use.
const datasets = {
  animal: ["cat", "dog", "cow", "pig", "monkey"],
  person: ["Sylvan", "Kieran", "Tej", "Jon", "AJ"]
};

// Initalise ScribeJS and pass in the datasets.
const scribe = new Scribe(datasets);

// Call the generator function and pass in the sentence we want to randomise.
const result = scribe.generator("|person| went to the park. At the park they saw a |animal|!");

Potential outcomes for the example above include:

Sylvan went to the park. At the park he saw a cat!
Kieran went to the park. At the park he saw a dog!
AJ went to the park. At the park he saw a cow!
Sylvan went to the park. At the park he saw a monkey!
ect...
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文