Skip to content

Spintaxkt is a Kotlin library for parsing spintax strings and generating all possible combinations of sentences.

License

Notifications You must be signed in to change notification settings

JamshedAlamQaderi/spintaxkt

Repository files navigation

Maven Central

CodeFactor codecov

CI Analyse Publish

Spintaxkt

Spintaxkt is a Kotlin library for parsing spintax strings and generating all possible combinations of sentences.

What is spintax?

Spintax, short for "spin syntax," is a format for representing alternative versions of a piece of text within a single string. It is commonly used in content generation, such as in article spinning software or email marketing templates.

In spintax, alternative versions of a piece of text are enclosed in curly braces {} and separated by a vertical bar |. For example, the spintax string "{Hello|Hi} {world|there}" has two choices, each with two alternatives. When expanded, this spintax string generates four possible sentences:

  • "Hello world"
  • "Hello there"
  • "Hi world"
  • "Hi there"

Spintax can also be nested, allowing for more complex combinations of alternatives.

Setup

Maven Central

To use Spintaxkt in your project, add the following dependency to your build.gradle file:

// see above maven central badge for get the latest version 
dependencies {
    implementation("com.jamshedalamqaderi.spintaxkt:spintaxkt:<spintaxkt_version>")
}

Usage

To parse a spintax string and generate all possible combinations of sentences, you can use the SpintaxkUtils object as follows:

import com.jamshedalamqaderi.kotlin.spintaxkt.SpintaxkUtils

val spintax = "{Hello|Hi} {world|there}"
val parser = spintax.parser()
val sentences = parser.sentences()
// sentences == listOf("Hello world", "Hello there", "Hi world", "Hi there")

You can also use the variations() method to get the total number of variations:

val variations = parser.variations()
// variations == 4

Or use the sentence() method to get a random sentence:

val sentence = parser.sentence()
// sentence == "Hello world" (or any other combination)

Contributing

We welcome contributions to Spintaxkt! If you have an idea for a new feature or bug fix, please open an issue or pull request.

Support

If you found Spintaxkt useful and would like to support its development, you can donate via Patreon by clicking on the button below:

Support via Patreon

Credits

Spintaxkt was developed by JamshedAlamQaderi.

License

Spintaxkt is licensed under the Apache License 2.0.

Copyright 2023 Jamshed Alam Qaderi

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Spintaxkt is a Kotlin library for parsing spintax strings and generating all possible combinations of sentences.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published