Example #1
0
/**
 * function swapPerson()
 * @param array $convoArr
 * @param int $person
 * @param string $input
 * @return string $tmp
 **/
function swapPerson($convoArr, $person, $input)
{
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Person:{$person} In:{$input}", 4);
    $name = $convoArr['client_properties']['name'];
    $gender = isset($convoArr['client_properties']['gender']) ? $convoArr['client_properties']['gender'] : 'unknown';
    $tmp = trim($input);
    if (!isset($_SESSION['transform_list']) || $_SESSION['transform_list'] == NULL) {
        buildVerbList($name, $gender);
    }
    // <person2> = swap first with second poerson (e.g. I with you)
    // <person> swap with third person (e.g. I with he,she,it)
    switch ($gender) {
        case "male":
            $g1 = "his";
            //  Third person singular: masculine (Possessive pronoun)
            $g2 = "him";
            // Third person singular: masculine (object)
            $g3 = "he";
            // Third person singular: masculine (subject)
            $g4 = "his";
            // Third person singular: neutral (Possessive adjective)
            break;
        case "female":
            $g1 = "hers";
            //  Third person singular: feminine (Possessive pronoun)
            $g2 = "her";
            // Third person singular: feminine (object)
            $g3 = "she";
            // Third person singular: feminine (subject)
            $g4 = "her";
            // Third person singular: neutral (Possessive adjective)
            break;
        default:
            $g1 = "its";
            // Third person singular: neutral (Possessive pronoun)
            $g2 = "it";
            // Third person singular: neutral (object)
            $g3 = "it";
            // Third person singular: neutral (subject)
            $g4 = "its";
            // Third person singular: neutral (Possessive adjective)
    }
    # I am, am I, was I, I, my, mine, myself, me, ourselves, we, us, ours, our
    $simpleFirstPersonPatterns = array('/(\\bi am\\b)/ui', '/(\\bam i\\b)/ui', '/(\\bwas i\\b)/ui', '/(\\bi\\b)/ui', '/(\\bmy\\b)/ui', '/(\\bmine\\b)/ui', '/(\\bmyself\\b)/ui', '/(\\byour\\b)/ui', '/(\\bme\\b)/ui', '/(\\bourselves\\b)/ui', '/(\\bwe\\b)/ui', '/(\\bus\\b)/ui', '/(\\bours\\b)/ui', '/(\\bour\\b)/ui');
    $simpleSecondPersonKeyedReplacements = array('y%%ou are', 'are y%%ou', 'were y%%ou', 'y%%ou', 'yo%%ur', 'yo%%urs', 'y%%ourself', 'm%%y', 'y%%ou', 'y%%ourselves', 'y%%ou', 'y%%ou', 'y%%ours', 'y%%our');
    # you are, are you, were you, you, your, yours, yourself, thy, yourselves
    $simpleSecondPersonPatterns = array('/(\\bare you\\b)/ui', '/(\\byou are\\b)/ui', '/(\\bwere you\\b)/ui', '/(\\byou\\b)/ui', '/(\\byour\\b)/ui', '/(\\byours\\b)/ui', '/(\\byourself\\b)/ui', '/(\\bthy\\b)/ui', '/(\\byourselves\\b)/ui');
    $simpleFirstPersonKeyedReplacements = array('I%% am', 'am I%%', 'was I%%', 'I%%', 'm%%y', 'm%%ine', 'm%%yself', 'm%%y', 'o%%urselves');
    # I am, am I, will I, shall I, may I, might I, can I, could I, must I, should I, would I, need I, was I, ourselves, our, ours, I, me, my, mine, myself, we, us
    $simpleFirstToThirdPersonPatterns = array('/(\\bi am\\b)/ui', '/(\\bam i\\b)/ui', '/(\\bwill i\\b)/ui', '/(\\bshall i\\b)/ui', '/(\\bmay i\\b)/ui', '/(\\bmight i\\b)/ui', '/(\\bcan i\\b)/ui', '/(\\bcould i\\b)/ui', '/(\\bmust i\\b)/ui', '/(\\bshould i\\b)/ui', '/(\\bwould i\\b)/ui', '/(\\bneed i\\b)/ui', '/(\\bwas i\\b)/ui', '/(\\bourselves\\b)/ui', '/(\\bour\\b)/ui', '/(\\bours\\b)/ui', '/(\\bme\\b)/ui', '/(\\bi\\b)/ui', '/(\\bmy\\b)/ui', '/(\\bmine\\b)/ui', '/(\\bmyself\\b)/ui', '/(\\bwe\\b)/ui', '/(\\bud\\b)/ui');
    $simpleThirdPersonReplacements = array("{$g3} is", "is {$g3}", 'will ' . $g3, 'shall ' . $g3, 'may ' . $g3, 'might ' . $g3, 'can ' . $g3, 'could ' . $g3, 'must ' . $g3, 'should ' . $g3, 'would ' . $g3, 'need ' . $g3, 'was ' . $g3, 'themselves', 'their', 'theirs', "{$g2}", "{$g3}", "{$g4}", "{$g1}", "{$g2}" . 'self', 'they', 'them');
    if ($person == 2) {
        //      $tmp = preg_replace('/\byou and me\b/ui', 'you and IzI', $tmp);// fix the "Me and you" glitch
        $tmp = preg_replace($simpleFirstPersonPatterns, $simpleSecondPersonKeyedReplacements, $tmp);
        // simple first to keyed second transform
        $tmp = preg_replace($simpleSecondPersonPatterns, $simpleFirstPersonKeyedReplacements, $tmp);
        // "simple" second to keyed first transform
        $tmp = preg_replace($_SESSION['transform_list']['secondPersonPatterns'], $_SESSION['transform_list']['firstPersonReplacements'], $tmp);
        // second to first transform
    } elseif ($person == 3) {
        // first to third transform
        $tmp = preg_replace($simpleFirstToThirdPersonPatterns, $simpleThirdPersonReplacements, $tmp);
        // "simple" first to third transform
        $tmp = preg_replace($_SESSION['transform_list']['firstPersonPatterns'], $_SESSION['transform_list']['thirdPersonReplacements'], $tmp);
    }
    $tmp = str_replace('%%', '', $tmp);
    // remove token
    //debug
    // if (RUN_DEBUG) runDebug(4, __FILE__, __FUNCTION__, __LINE__,"<br>\nTransformation complete. was: $input, is: $tmp");
    return $tmp;
    //return
}
Example #2
0
/**
 * function swapPerson()
 * @param array $convoArr
 * @param int $person
 * @param string $in
 * @return the tranformed string
**/
function swapPerson($convoArr, $person = 2, $in)
{
    //2 = swap first with second poerson // otherwise swap with third person
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Person:{$person} In:{$in}", 4);
    $name = get_convo_var($convoArr, 'client_properties', 'name');
    $gender = get_convo_var($convoArr, 'client_properties', 'gender');
    $tmp = trim($in);
    if (!isset($_SESSION['transform_list']) || $_SESSION['transform_list'] == NULL) {
        buildVerbList($name, $gender);
    }
    switch ($gender) {
        case "male":
            $g1 = "his";
            $g2 = "him";
            $g3 = "he";
            break;
        case "female":
            $g1 = "hers";
            $g2 = "her";
            $g3 = "she";
            break;
        default:
            $g1 = "theirs";
            $g2 = "them";
            $g3 = "they";
    }
    // the "simple" transform arrays - more for exceptions to the above rules than for anything "simple" :)
    $simpleFirstPersonPatterns = array('/(\\bi am\\b)/i', '/(\\bam i\\b)/i', '/(\\bi\\b)/i', '/(\\bmy\\b)/i', '/(\\bmine\\b)/i', '/(\\bmyself\\b)/i', '/(\\bcan i\\b)/i');
    $simpleSecondPersonKeyedReplacements = array('you are', 'are you', 'you', 'your', 'yours', 'yourself', 'can you');
    $simpleFirstToThirdPersonPatterns = array('/(\\bi am\\b)/i', '/(\\bam i\\b)/i', '/(\\bi\\b)/i', '/(\\bmy\\b)/i', '/(\\bmine\\b)/i', '/(\\bmyself\\b)/i', '/(\\bwill i\\b)/i', '/(\\bshall i\\b)/i', '/(\\bmay i\\b)/i', '/(\\bmight i\\b)/i', '/(\\bcan i\\b)/i', '/(\\bcould i\\b)/i', '/(\\bmust i\\b)/i', '/(\\bshould i\\b)/i', '/(\\bwould i\\b)/i', '/(\\bneed i\\b)/i', '/(\\bam i\\b)/i', '/(\\bwas i\\b)/i');
    $simpleThirdPersonReplacements = array("{$g3} is", "is {$g3}", "{$g3}", "{$g1}", "{$g1}", "{$g2}" . 'self', 'will ' . $g3, 'shall ' . $g3, 'may ' . $g3, 'might ' . $g3, 'can ' . $g3, 'could ' . $g3, 'must ' . $g3, 'should ' . $g3, 'would ' . $g3, 'need ' . $g3, 'is ' . $g3, 'was ' . $g3);
    $simpleSecondPersonPatterns = array('/(\\bhelp you\\b)/i', '/(\\bwill you\\b)/i', '/(\\bshall you\\b)/i', '/(\\bmay you\\b)/i', '/(\\bmight you\\b)/i', '/(\\bcan you\\b)/i', '/(\\bcould you\\b)/i', '/(\\bmust you\\b)/i', '/(\\bshould you\\b)/i', '/(\\bwould you\\b)/i', '/(\\bneed you\\b)/i', '/(\\bare you\\b)/i', '/(\\bwere you\\b)/i', '/(\\byour\\b)/i', '/(\\byours\\b)/i', '/(\\byourself\\b)/i', '/(\\bthy\\b)/i');
    # will, shall, may, might, can, could, must, should, would, need
    $simpleFirstPersonReplacements = array('help m e', 'will @II', 'shall @II', 'may @II', 'might @II', 'can @II', 'could @II', 'must @II', 'should @II', 'would @II', 'need @II', 'am @II', 'was @II', 'my', 'mine', 'myself', 'my');
    if ($person == 2) {
        $tmp = preg_replace('/\\bare you\\b/i', 'am @II', $tmp);
        // simple second to first transform
        $tmp = preg_replace('/\\byou and i\\b/i', 'y ou and @II', $tmp);
        // fix the "Me and you" glitch
        $tmp = preg_replace($simpleSecondPersonPatterns, $simpleFirstPersonReplacements, $tmp);
        // "simple" second to keyed first transform
        $tmp = preg_replace($simpleFirstPersonPatterns, $simpleSecondPersonKeyedReplacements, $tmp);
        // simple first to keyed second transform
        $tmp = preg_replace($_SESSION['transform_list']['secondPersonPatterns'], $_SESSION['transform_list']['firstPersonReplacements'], $tmp);
        // second to first transform
        $tmp = preg_replace('/\\bme\\b/i', 'you', $tmp);
        // simple second to first transform (me)
        #$tmp = preg_replace('/\bi\b/i', 'y ou', $tmp);                                              // simple second to first transform (I)
        $tmp = preg_replace('/\\byou\\b/i', 'me', $tmp);
        // simple second to first transform
        $tmp = str_replace('you', 'you', $tmp);
        // replace second person key (y ou) with non-keyed value (you)
        $tmp = str_replace(' me', ' me', $tmp);
        // replace first person key (m e) with non-keyed value (me)
        $tmp = str_replace(' my', ' my', $tmp);
        // replace first person key (m e) with non-keyed value (me)
        $tmp = str_replace('my ', 'my ', $tmp);
        // replace first person key (m e) with non-keyed value (me)
        $tmp = str_replace(' mine', ' mine', $tmp);
        // replace first person key (m e) with non-keyed value (me)
        $tmp = str_replace('mine ', 'mine ', $tmp);
        // replace first person key (m e) with non-keyed value (me)
        $tmp = str_replace(' @II ', ' I ', $tmp);
        // replace first person key (@I) with non-keyed value (I)
        $tmp = str_replace('@II ', 'I ', $tmp);
        // replace first person key (@I) with non-keyed value (I)
        $tmp = str_replace(' @II', ' I', $tmp);
        // replace first person key (@I) with non-keyed value (I)
        $tmp = str_replace('@you', 'I', $tmp);
        // replace first person key (@I) with non-keyed value (I)
        #$tmp = ucfirst(  $tmp);
    } elseif ($person == 3) {
        $tmp = preg_replace($_SESSION['transform_list']['firstPersonPatterns'], $_SESSION['transform_list']['thirdPersonReplacements'], $tmp);
        // first to third transform, but only when specifically needed
        $tmp = preg_replace('/(\\byour gender\\b)/i', $g3, $tmp);
        $tmp = preg_replace('/(\\bthey\\b)/i', $g3, $tmp);
        $tmp = preg_replace('/(\\bi\\b)/i', $g3, $tmp);
        $tmp = preg_replace('/(\\bme\\b)/i', $g3, $tmp);
    }
    //debug
    // if (RUN_DEBUG) runDebug(4, __FILE__, __FUNCTION__, __LINE__,"<br>\nTransformation complete. was: $in, is: $tmp");
    return $tmp;
    //return
}