Ejemplo n.º 1
0
function createRegex($inputText)
{
    /*
     * Create a PCRE regular expression from $inputText. 
     */
    $words = explode(" ", standardizeText($inputText));
    array_map("sanitizeRegex", $words);
    //sanitize each word
    //glue words together and build the regex
    $regex = "/(" . implode(")( )*(", $words) . ")/is";
    return $regex;
}
Ejemplo n.º 2
0
function selectSubstringRandom($inputText, $substringLength)
{
    $split = explode(" ", standardizeText($inputText));
    //split standardized string into words
    $pos = rand(0, strlen($inputText) - $substringLength);
    //get a random position
    $substring = implode(" ", array_slice($split, $pos, $substringLength));
    while (inRepository($substring)) {
        //while the chosen substring is found in the repository
        $pos = rand(0, strlen($inputText) - $substringLength);
        //get a random position
        $substring = implode(" ", array_slice($split, $pos, $substringLength));
        //pull out the random substring
    }
    return $substring;
}
Ejemplo n.º 3
0
function repositoryScore($substring)
{
    //TODO: Correct SQL statement, probably wrong
    //need standardizeText() here?
    $words = explode(" ", standardizeText($substring));
    $score = 0;
    /*
    		foreach ($words as $word){
    			$query = "SELECT $word FROM table";
    			$score += queryDatabase($query);
    		}*/
    return $score;
}
Ejemplo n.º 4
0
function inFile($path, $substring)
{
    /*
     * If substring is found in the specified file, return True.
     * Otherwise, return false. 
     * 
     * Possibly rewrite this to pass a string that we build a 
     * regular expression from, and place in common.php?
     */
    $file = fopen($path, 'r') or die("inFile(): can't open {$path}");
    $text = fread($file, filesize($path));
    fclose($file);
    $standardText = standardizeText($text);
    //if substring is found within the file, flag
    if (strripos($standardText, $substring)) {
        return True;
    }
    return False;
}