Skip to content

Instantly share code, notes, and snippets.

@hemant-tivlabs
Last active April 9, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemant-tivlabs/39c04adaf7ad1138ca22979563237fff to your computer and use it in GitHub Desktop.
Save hemant-tivlabs/39c04adaf7ad1138ca22979563237fff to your computer and use it in GitHub Desktop.
The "SpinerMan" PHP class is capable of processing a nested spintax (spinner text) and retrieve statistical information like max number of variations, holes, min and max words, and much more.

SpinerMan, the spintax processor

A spintax (or simply spinner text) is a specially formatted text that is capable of generating a unique articles (unique combination of words) everytime it is executed and is used popularly as an SEO measure.

SpinerMan is a PHP Class that is capable of processing a spintax and retrieve statistical information like maximum number of variations, holes, minimum and maximum number of words, and much more. It supports nested blocks and parses the input into a tree with details available at every node.

NOTE: This script was written by an unknown JavaScript developer somewhere near 2014, when spintax was a very popular thing. I'm not the original author of this wonderful script. Instead, I have merely converted the script into a PHP class and made it available to the world (thanks to GitHub!).

Member functions

buildTree()

The buildTree() function takes a spintax as an input and converts it into a tree of block nodes at every level of nesting.

The following are a couple of spintax examples that can be used as input:

Example 1

{This is|That is|It is {a|an interestingly|a surprizingly}} simple example of a {spintax|spinner text}

Total possible variations: 10

Example 2

{a|b {c|d|e} {f|g}|h|{i|j|k|l} {m|n} {o|p|q} {r {s|t|u} v|w} x} y

Total possible variations: 104

getAllVariations()

The function accepts the spintax tree (generated by the buildTree function) as an input and generates all the possible variations.

getVariation()

This special function is capable of providing a specific variation by index. It accepts the spintax tree and the index number as parameters.

getStats()

The function provides all form of statistical information about the spintax tree that it acceps as input. Following is the list of details it provides:

  • totalResults - the total number of possible spins
  • totalHoles = the total number of holes
  • totalVariations - total number of choices / remplacements
  • minWords - the minimum number of words
  • maxWords - the maximum number of words
  • avgWords - the average number of words
  • minLength - the minimum length of generated result
  • maxLength - the maximum length of generated result
  • avgLength - the average length of generated result
  • calculationOverflow - a boolean flag to indicate that the number of possible spins is close to infinity
<?php
define('CLOSETOINFINITY', pow(10, 308));
class SpinerMan {
private static $closeToInfinity = CLOSETOINFINITY;
public static function getText($q, $p) {
$c = [];
$b = "";
$g = [];
$h = 0;
$f = 0;
$e = 0;
$d = 0;
$n = 0;
$o = 1;
$m = $q->c;
$a = "";
for($h = 0; $h < strlen($q->h->c); $h++) {
$a = "{".$h."}";
$f = 0;
$d = floor($p / $o) % $q->h->r[$h];
$e = $q->h->c[$h][$f]->r;
while(floor($p / $o) % $q->h->r[$h] >= $e) {
$d -= $q->h->c[$h][$f]->r;
$f++;
$e += $q->h->c[$h][$f]->r;
}
$o = $o * $q->h->r[$h];
$b = self::getText($q->h->c[$h][$f], $d);
$n = array_search($a, $m);
$m = substr($m, 0, $n).$b.substr($m, $n + strlen($a));
}
return $m;
}
public static function buildTree($text, $g = 0) {
$q = "";
$p = "";
$a = 0;
$h = 0;
$t = json_decode(
'{'
.' "c": "",' // (String) S
.' "h": { "c": [], "r": [] },' // c: (String), r: (Number/Array of Numbers)
.' "d": '.(!$g ? 0 : $g).',' // (Number)
.' "r": 1,' // (Number)
.' "s": {' // (Object)
.' "l": 0,' // (Number)
.' "w": 0,' // (Number)
.' "h": 0,' // (Number)
.' "r": 0,' // (Number)
.' "wmin": 0,' // (Number)
.' "wmax": 0,' // (Number)
.' "lmin": 0,' // (Number)
.' "lmax": 0' // (Number)
.' }'
.'}'
); //self::debug($t); exit();
$d = array();
$m = 0;
$b = 0;
$o = 0;
$s = "";
$f = false;
$e = false;
$n = 0;
$k = 0;
if(strpos($text, "{") < 0) {
$t->c = $text;
$t->s->w = self::countWords($text);
$t->s->l = strlen($text);
$t->s->wmin = $t->s->w;
$t->s->wmax = $t->s->w;
$t->s->lmin = $t->s->l;
$t->s->lmax = $t->s->l;
return $t;
}
for($h = 0; $h < strlen($text); $h++) {
$p = $text[$h];
if($p === "{") {
if($a === 0) {
$s .= $q;
$t->c = $t->c.$q;
$q = "";
} else {
$q = $q.$p;
}
$a++;
} else {
if($p === "|") {
if($a === 1) {
$q = self::buildTree($q, $t->d + 1);
if($q === false) {
return false;
}
$m += $q->r;
$b += $q->s->l;
$o += $q->s->w;
$t->s->h += $q->s->h;
$t->s->r += max(1, $q->s->r);
$f = $f === false ? $q->s->wmin : min($f, $q->s->wmin);
$e = $e === false ? $q->s->lmin : min($e, $q->s->lmin);
$n = max($n, $q->s->wmax);
$k = max($k, $q->s->lmax);
array_push($d, $q);
$q = "";
} else {
$q = $q.$p;
}
} else {
if ($p === "}") {
if ($a === 1) {
$q = self::buildTree($q, $t->d + 1);
if($q === false) {
return false;
}
$t->c = $t->c."{".count($t->h->c)."}";
array_push($d, $q);
$m += $q->r;
$b += $q->s->l;
$o += $q->s->w;
$t->s->h += $q->s->h + 1;
$t->s->r += max(1, $q->s->r);
$t->s->w = $o * $t->r + $t->s->w * $m;
$t->s->l = $b * $t->r + $t->s->l * $m;
$t->s->wmin += $f === false ? $q->s->wmin : min($f, $q->s->wmin);
$t->s->lmin += $e === false ? $q->s->lmin : min($e, $q->s->lmin);
$t->s->wmax += max($n, $q->s->wmax);
$t->s->lmax += max($k, $q->s->lmax);
$f = false;
$e = false;
$n = 0;
$k = 0;
$t->r = $t->r * $m;
$t->h->r[count($t->h->c)] = $m;
$m = 0;
$b = 0;
$o = 0;
array_push($t->h->c, $d);
$d = array();
$q = "";
} else {
$q = $q.$p;
}
$a--;
} else {
$q = $q.$p;
}
}
}
}
if($a !== 0) {
if($a > 0) {
throw new Exception('Missing }');
} else {
throw new Exception('Missing {');
}
return false;
}
if($q !== "") {
$s .= $q;
$t->c = $t->c.$q;
}
$o = self::countWords($s);
$t->s->l += $t->r * strlen($s);
$t->s->w += $t->r * $o;
$t->s->wmin += $o;
$t->s->wmax += $o;
$t->s->lmin += strlen($s);
$t->s->lmax += strlen($s);
return $t;
}
public static function getVariation($tree, $index) {
$c = array();
$b = "";
$g = array();
$h = 0;
$f = 0;
$e = 0;
$d = 0;
$n = 0;
$o = 1;
$m = $tree->c;
$a = "";
for($h = 0; $h < count($tree->h->c); $h++) {
$a = "{".$h."}";
$f = 0;
$d = floor($index / $o) % $tree->h->r[$h];
$e = $tree->h->c[$h][$f]->r;
while(floor($index / $o) % $tree->h->r[$h] >= $e) {
$d -= $tree->h->c[$h][$f]->r;
$f++;
$e += $tree->h->c[$h][$f]->r;
}
$o = $o * $tree->h->r[$h];
$b = self::getVariation($tree->h->c[$h][$f], $d);
$n = strpos($m, $a);
$m = substr($m, 0, $n).$b.substr($m, $n + strlen($a));
}
return $m;
}
public static function getAllVariations($tree) {
$aResult = array();
for($i = 0; $i < $tree->r; $i++) {
array_push($aResult, self::getVariation($tree, $i));
}
return $aResult;
}
public static function getStats($tree) {
$calculationOverflow = false;
if(true !== is_finite($tree->r)) {
$tree->r = self::$closeToInfinity;
$calculationOverflow = true;
}
$result = new stdClass();
$result->totalResults = $tree->r; // ie. total of possible spuns
$result->totalHoles = $tree->s->h;
$result->totalVariations = $tree->s->r; // ie. total number of choices / remplacements
$result->minWords = $tree->s->wmin;
$result->maxWords = $tree->s->wmax;
$result->avgWords = $tree->r > 0 ? ($tree->s->w / $tree->r) : 0;
$result->minLength = $tree->s->lmin;
$result->maxLength = $tree->s->lmax;
$result->avgLength = $tree->r > 0 ? ($tree->s->l / $tree->r) : 0;
$result->calculationOverflow = $calculationOverflow;
if(!is_numeric($result->avgWords) || true !== is_finite($result->avgWords)) {
$result->avgWords = ($result->minWords + $result->maxWords) / 2;
}
if(!is_numeric($result->avgLength) || true !== is_finite($result->avgLength)) {
$result->avgLength = ($result->minLength + $result->maxLength) / 2;
}
return $result;
}
public static function countWords($e) {
$regex = '/[^A-Za-z\xc2\xaa\xc2\xb5\xc2\xba\xc3\x80\x2d\xc3\x96\xc3\x98\x2d\xc3\xb6\xc3\xb8\x2d\xcb\x81\xcb\x86\x2d\xcb\x91\xcb\xa0\x2d\xcb\xa4\xcb\xac\xcb\xae\xcd\xb0\x2d\xcd\xb4\xcd\xb6\xcd\xb7\xcd\xba\x2d\xcd\xbd\xce\x86\xce\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x9f\xea\x9c\xa2\x2d\xea\x9e\x88\xea\x9e\x8b\xea\x9e\x8c\xea\x9f\xbb\x2d\xea\xa0\x81\xea\xa0\x83\x2d\xea\xa0\x85\xea\xa0\x87\x2d\xea\xa0\x8a\xea\xa0\x8c\x2d\xea\xa0\xa2\xea\xa1\x80\x2d\xea\xa1\xb3\xea\xa2\x82\x2d\xea\xa2\xb3\xea\xa3\xb2\x2d\xea\xa3\xb7\xea\xa3\xbb\xea\xa4\x8a\x2d\xea\xa4\xa5\xea\xa4\xb0\x2d\xea\xa5\x86\xea\xa5\xa0\x2d\xea\xa5\xbc\xea\xa6\x84\x2d\xea\xa6\xb2\xea\xa7\x8f\xea\xa8\x80\x2d\xea\xa8\xa8\xea\xa9\x80\x2d\xea\xa9\x82\xea\xa9\x84\x2d\xea\xa9\x8b\xea\xa9\xa0\x2d\xea\xa9\xb6\xea\xa9\xba\xea\xaa\x80\x2d\xea\xaa\xaf\xea\xaa\xb1\xea\xaa\xb5\xea\xaa\xb6\xea\xaa\xb9\x2d\xea\xaa\xbd\xea\xab\x80\xea\xab\x82\xea\xab\x9b\x2d\xea\xab\x9d\xea\xaf\x80\x2d\xea\xaf\xa2\xea\xb0\x80\x2d\xed\x9e\xa3\xed\x9e\xb0\x2d\xed\x9f\x86\xed\x9f\x8b\x2d\xed\x9f\xbb\xef\xa4\x80\x2d\xef\xa8\xad\xef\xa8\xb0\x2d\xef\xa9\xad\xef\xa9\xb0\x2d\xef\xab\x99\xef\xac\x80\x2d\xef\xac\x86\xef\xac\x93\x2d\xef\xac\x97\xef\xac\x9d\xef\xac\x9f\x2d\xef\xac\xa8\xef\xac\xaa\x2d\xef\xac\xb6\xef\xac\xb8\x2d\xef\xac\xbc\xef\xac\xbe\xef\xad\x80\xef\xad\x81\xef\xad\x83\xef\xad\x84\xef\xad\x86\x2d\xef\xae\xb1\xef\xaf\x93\x2d\xef\xb4\xbd\xef\xb5\x90\x2d\xef\xb6\x8f\xef\xb6\x92\x2d\xef\xb7\x87\xef\xb7\xb0\x2d\xef\xb7\xbb\xef\xb9\xb0\x2d\xef\xb9\xb4\xef\xb9\xb6\x2d\xef\xbb\xbc\xef\xbc\xa1\x2d\xef\xbc\xba\xef\xbd\x81\x2d\xef\xbd\x9a\xef\xbd\xa6\x2d\xef\xbe\xbe\xef\xbf\x82\x2d\xef\xbf\x87\xef\xbf\x8a\x2d\xef\xbf\x8f\xef\xbf\x92\x2d\xef\xbf\x97\xef\xbf\x9a\x2d\xef\xbf\x9c]+/ui'; // match latin characters
$f = preg_replace($regex, " ", $e);
$f = preg_replace('/^ +/', '', $f);
$f = preg_replace('/ +$/', '', $f);
$d = 0;
if($f !== "") {
$d = count(explode(" ", $f));
}
return $d;
}
public static function debug($data) {
echo '<pre>'.print_r($data, true).'</pre>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment