restrict depth of word set calculation

This commit is contained in:
Sarah Hoffmann
2013-04-20 00:18:08 +02:00
parent 9e0a92a508
commit b4c87a09a1
2 changed files with 11 additions and 9 deletions

View File

@@ -165,18 +165,20 @@
}
function getWordSets($aWords)
function getWordSets($aWords, $iDepth)
{
$aResult = array(array(join(' ',$aWords)));
$sFirstToken = '';
while(sizeof($aWords) > 1)
{
$sWord = array_shift($aWords);
$sFirstToken .= ($sFirstToken?' ':'').$sWord;
$aRest = getWordSets($aWords);
foreach($aRest as $aSet)
if ($iDepth < 8) {
while(sizeof($aWords) > 1)
{
$aResult[] = array_merge(array($sFirstToken),$aSet);
$sWord = array_shift($aWords);
$sFirstToken .= ($sFirstToken?' ':'').$sWord;
$aRest = getWordSets($aWords, $iDepth+1);
foreach($aRest as $aSet)
{
$aResult[] = array_merge(array($sFirstToken),$aSet);
}
}
}
return $aResult;