示例#1
0
 public function __construct( $data  = NULL, $options = NULL ){
     $options = new GLU( $options );
     if( $data instanceof iterator ) {
         $str = '';
         foreach($data as $v ) $str .= ' ' . $v;
         $data = $str;
     }
     if( is_array( $data ) ) $data = implode(' ', $data );
     $data = preg_split("/[\s,\.\:\/\\\]+/", trim(preg_replace('/[^a-z0-9\s,\.\:\/\\\]/i', '', strtolower($data))));
     $words = array();
     foreach( $data as $word ){
         if( strpos(self::$stopwords, $word . '|') !== FALSE ) continue;
         if( ! $options->disable_stemmer ) $word = PorterStemmer::stem( $word );
         $len = strlen( $word );
         if( $len < 3 || $len > 30 ) continue;
         if( strpos(self::$stopwords, $word . '|') !== FALSE ) continue;
         if( ! isset( $words[ $word ] ) ) $words[ $word ] = 0;
         $words[$word]++;
         if( $len < 6 || $options->disable_soundex ) continue;
         $word = soundex( $word );
         if( ! isset( $words[ $word ] ) ) $words[ $word ] = 0;
         $words[$word]++;
     }
     parent::__construct( $words );
 }
示例#2
0
文件: umwords.php 项目: philum/cms
function umwords_build($p, $o)
{
    $ratio = 50;
    $min = $p * $ratio;
    $limit = $min . ', ' . ($min + $ratio);
    $r = sql_inner('pub_art.id,msg', 'qda', 'qdm', 'id', 'kv', 'where nod="ummo" limit ' . $limit);
    if ($r) {
        foreach ($r as $k => $v) {
            $v = str_replace("'", ' ', $v);
            //$v=str_replace('-',' ',$v);
            $rb = str_word_count($v, 2);
            if ($rb) {
                foreach ($rb as $ka => $va) {
                    if ($va == strtoupper($va) && !umwords_dicos($va) && strlen($va) > 1) {
                        $rd[] = array($k, $va, $ka, soundex($va));
                        //idart,voc,pos,sound
                        $rc[$va] = array($k, $va, $ka, soundex($va));
                    }
                }
            }
        }
    }
    //if(auth(6))umwords_sav($rc);
    return $rd;
    $ret = count($rc);
    $ret .= make_table($rc);
    return $ret;
}
 function compare($debug = false)
 {
     $first = $this->str1;
     $second = $this->str2;
     $this->levenshtein = levenshtein($first, $second);
     $this->similarity['value'] = $sim = similar_text($first, $second, $perc);
     $this->similarity['percentage'] = $perc;
     if ($debug) {
         echo "{$first} | {$second}<br>";
         echo "leven: " . $this->levenshtein;
         echo '<br>similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $soundex1 = soundex($first);
     $soundex2 = soundex($second);
     $this->soundex['levenshtein'] = levenshtein($soundex1, $soundex2);
     $this->soundex['similarity'] = $sim = similar_text($soundex1, $soundex2, $perc);
     $this->soundex['percentage'] = $perc;
     if ($debug) {
         echo "Soundex: " . $soundex1 . ", " . $soundex2 . "<BR>";
         echo 'levenshtein: ' . $this->soundex['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br><br>';
     }
     $m1 = metaphone($first);
     $m2 = metaphone($second);
     $this->metaphone['levenshtein'] = levenshtein($m1, $m2);
     $this->metaphone['similarity'] = $sim = similar_text($m1, $m2, $perc);
     $this->metaphone['percentage'] = $perc;
     if ($debug) {
         echo "metaphone: " . $m1 . ", " . $m2 . "<br>";
         echo 'levenshtein: ' . $this->metaphone['levenshtein'] . '<br>';
         echo 'similarity: ' . $sim . ', ' . $perc . '%<br>';
         echo '<br>-------------------<br>';
     }
 }
 function search_items()
 {
     $search_string = $this->input->post('keyword');
     $search_string = preg_replace('/[^a-zA-Z0-9_ %\\[\\]\\.\\(\\)%&-]/s', '', $search_string);
     $words = explode(" ", $search_string);
     $data = $this->browse_gallery_model->get_all_search_strings();
     $row = 0;
     $row_array = array();
     $ad_array = array();
     foreach ($data as $text) {
         $text_word = explode("~", $text['Title_Text']);
         $ad_id = $text['ad_id'];
         $count = 0;
         foreach ($text_word as $single) {
             foreach ($words as $keyword) {
                 if (soundex(strtoupper($keyword)) == soundex(strtoupper($single)) || metaphone(strtoupper($keyword)) == metaphone(strtoupper($single))) {
                     $count = $count + 1;
                 }
             }
         }
         if (intval($count) > 0) {
             array_push($row_array, $ad_id);
         }
     }
     if (!empty($row_array)) {
         $data['ads'] = $this->browse_gallery_model->get_gallery_ads_by_adid($row_array);
         $data['top'] = $this->browse_gallery_model->get_top_categories();
         $this->load->view('search_items_view', $data);
     } else {
         $data['ads'] = NULL;
         $data['top'] = $this->browse_gallery_model->get_top_categories();
         $this->load->view('search_items_view', $data);
     }
 }
示例#5
0
function get_matches($rq)
{
    if (strtolower(trim($rq->artist)) != 'mokele') {
        return array();
    }
    if (soundex($rq->track) != soundex('hiding in your insides')) {
        return array();
    }
    $pi = new stdclass();
    $pi->artist = "Mokele";
    $pi->track = "Hiding In Your Insides";
    $pi->album = "You Yourself are Me Myself and I am in Love";
    $pi->source = "Mokele.co.uk";
    $pi->size = 4971780;
    $pi->bitrate = 160;
    $pi->duration = 248;
    $pi->extra_headers = array("X-Something: foo", "X-WTF: bar");
    // anything cURL supports:
    // NB this url should be url encoded properly:
    // $pi->url    = "ftp://*****:*****@ftp.example.com/foo/bar.mp3";
    // $pi->url    = "scp://10.180.255.129/home/rj/mp3/TomWaits/Time.mp3"; // if your curl supports it!
    // $pi->url    = "file:///home/rj/mp3/Zero 7 - The Garden/Zero 7 - 11 - Crosses.mp3";
    // $pi->url    = "http://*****:*****@www.playdar.org/secret/hiding.mp3";
    $pi->url = "http://play.mokele.co.uk/music/Hiding%20In%20Your%20Insides.mp3";
    $pi->score = (double) 1.0;
    return array($pi);
}
示例#6
0
 function create_sound_query($in)
 {
     $out = null;
     $in = explode(' ', $in);
     foreach ($in as $word) {
         $word = soundex($word);
         $out .= " OR (SUBSTRING(SOUNDEX(p.post_text), 1, 4)='{$word}')";
     }
     return '(' . substr($out, 4) . ')';
 }
示例#7
0
 public static function interpret($value, $config = null)
 {
     if (is_array($value)) {
         sort($value);
         $string = implode(" ", $value);
     } else {
         $string = (string) $value;
     }
     $soundex = soundex($string);
     return intval(ord(substr($soundex, 0, 1)) . substr($soundex, 1));
 }
 public function onAfterInit()
 {
     if (!Director::isDev()) {
         // Only on live site
         $errorcode = $this->owner->failover->ErrorCode ? $this->owner->failover->ErrorCode : 404;
         $extract = preg_match('/^([a-z0-9\\.\\_\\-\\/]+)/i', $_SERVER['REQUEST_URI'], $rawString);
         if ($errorcode == 404 && $extract) {
             $uri = preg_replace('/\\.(aspx?|html?|php[34]?)$/i', '', $rawString[0]);
             $parts = preg_split('/\\//', $uri, -1, PREG_SPLIT_NO_EMPTY);
             $page_key = array_pop($parts);
             $sounds_like = soundex($page_key);
             // extend ignored classes with child classes
             $ignoreClassNames = array();
             if ($configClasses = Config::inst()->get('Intelligent404', 'intelligent_404_ignored_classes')) {
                 foreach ($configClasses as $class) {
                     $ignoreClassNames = array_merge($ignoreClassNames, array_values(ClassInfo::subclassesFor($class)));
                 }
             }
             // get all pages
             $SiteTree = SiteTree::get()->exclude('ClassName', $ignoreClassNames);
             // Translatable support
             if (class_exists('Translatable')) {
                 $SiteTree = $SiteTree->filter('Locale', Translatable::get_current_locale());
             }
             // Multisites support
             if (class_exists('Multisites')) {
                 $SiteTree = $SiteTree->filter('SiteID', Multisites::inst()->getCurrentSiteId());
             }
             $ExactMatches = new ArrayList();
             $PossibleMatches = new ArrayList();
             foreach ($SiteTree as $page) {
                 if ($page->URLSegment == $page_key) {
                     $ExactMatches->push($page);
                 } elseif ($sounds_like == soundex($page->URLSegment)) {
                     $PossibleMatches->push($page);
                 }
             }
             $ExactCount = $ExactMatches->Count();
             $PossibleCount = $PossibleMatches->Count();
             $redirectOnSingleMatch = Config::inst()->get('Intelligent404', 'redirect_on_single_match');
             if ($ExactCount == 1 && $redirectOnSingleMatch) {
                 return $this->RedirectToPage($ExactMatches->First()->Link());
             } elseif ($ExactCount == 0 && $PossibleCount == 1 && $redirectOnSingleMatch) {
                 return $this->RedirectToPage($PossibleMatches->First()->Link());
             } elseif ($ExactCount > 1 || $PossibleCount > 1 || !$redirectOnSingleMatch) {
                 $ExactMatches->merge($PossibleMatches);
                 $content = $this->owner->customise(array('Pages' => $ExactMatches))->renderWith(array('Intelligent404Options'));
                 $this->owner->Content .= $content;
             }
         }
     }
 }
示例#9
0
 public static function existeInDBByEntreprise($nomTuteur, $idEntreprise)
 {
     $tuteursIdentique = [];
     // Order by est obligatoire !
     // Si un tuteur est créer entre temps, cela n'infue pas les id dans les formulaires des autres
     $tuteurs = Tuteur::where('idEntreprise', $idEntreprise)->orderBy('idUtilisateur')->get();
     foreach ($tuteurs as $tuteur) {
         if (soundex($nomTuteur) == soundex($tuteur->details->nom)) {
             array_push($tuteursIdentique, $tuteur);
         }
     }
     return $tuteursIdentique;
 }
示例#10
0
function compareSoundex($v1, $v2)
{
    $v1 = soundex($v1);
    $v2 = soundex($v2);
    $v1_major = (ord($v1[0]) - ord('A')) * 1000;
    $v2_major = (ord($v2[0]) - ord('A')) * 1000;
    $v1_minor = substr($v1, 1);
    $v2_minor = substr($v2, 1);
    // return similarity percentage
    $total_major = (ord('Z') - ord('A')) * 1000;
    $total_minor = 999;
    return ($total_major - abs($v2_major - $v1_major)) / $total_major * 50 + ($total_minor - abs($v2_minor - $v1_minor)) / $total_minor * 50;
}
示例#11
0
 public static function existeInDBByCP($nomEtablissement, $codePostal)
 {
     $entreprisesIdentique = [];
     // Order by est obligatoire !
     // Si une entreprise est créer entre temps, cela n'infue pas les id dans les formulaires des autres
     $entreprises = Entreprise::where('cp', $codePostal)->orderBy('id')->get();
     foreach ($entreprises as $entreprise) {
         if (soundex($nomEtablissement) == soundex($entreprise->nom)) {
             array_push($entreprisesIdentique, $entreprise);
         }
     }
     return $entreprisesIdentique;
 }
 public function wpshop_search_where_in_order($where)
 {
     global $wpdb;
     if (!empty($_GET) && !empty($_GET['s']) && !empty($_GET['post_type']) && $_GET['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_ORDER) {
         $where = "\tAND {$wpdb->posts}.post_type = '" . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . "'";
         if (!empty($_GET['s'])) {
             $s_soundex = soundex($_GET['s']);
             $s = strtoupper($_GET['s']);
             $where .= "AND (\n\t\t\t\t\t\t\t\t\t( \t\n\t\t\t\t\t\t\t\t\t\t{$wpdb->posts}.ID IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT PM.post_id AS ID\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->postmeta} AS PM\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\tPM.meta_key = '_order_postmeta'\n\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( PM.meta_value ) LIKE '%{$s}%'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\tPM.meta_key = '_order_info'\n\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( PM.meta_value ) LIKE '%{$s}%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( PM.meta_value ) = '{$s_soundex}'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t{$wpdb->posts}.post_author IN (\n\t\t\t\t\t\t\t\t\t\t\tSELECT U.ID\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->users} AS U\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN {$wpdb->usermeta} AS UM\n\t\t\t\t\t\t\t\t\t\t\tON ( UM.user_id = U.ID )\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\tUPPER( U.user_email ) LIKE '%{$s}%'\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( U.user_email ) = '{$s_soundex}'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\tUM.meta_key = 'first_name'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( UM.meta_value ) LIKE '%{$s}%'\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( UM.meta_value ) = '{$s_soundex}'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\tUM.meta_key = 'last_name'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( UM.meta_value ) LIKE '%{$s}%'\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( UM.meta_value ) = '{$s_soundex}'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)";
         }
         /*$metas_to_inspect = array( '_order_postmeta', '_order_info');
         			$first = $first_word = true;
         
         			$where .= ' OR ' .$wpdb->posts.'.post_type = "' .WPSHOP_NEWTYPE_IDENTIFIER_ORDER. '"';
         
         			$where .= ' AND ';
         
         
         			if ( !empty($_GET['entity_to_search']) &&  $_GET['entity_to_search'] == 'customer' ) {
         				$words = explode(' ', wpshop_tools::varSanitizer( addslashes($_GET['s']) ));
         				foreach ( $words as $word ) {
         					$first = true;
         					if ( !$first_word ) {
         						$where .= ' OR ';
         					}
         					$where .= '('.$wpdb->postmeta .'.meta_key = "_order_info" AND '.$wpdb->postmeta .'.meta_value LIKE "%' .$word. '%")';
         					$first_word = false;
         				}
         			}
         			else {
         				$word = wpshop_tools::varSanitizer( addslashes($_GET['s']) );
         				$where .= '('.$wpdb->postmeta .'.meta_key = "_order_postmeta" AND '.$wpdb->postmeta .'.meta_value LIKE "%' .$word. '%")';
         
         			}
         
         			add_filter('posts_join_request', array($this, 'wpshop_search_join'));
         		}*/
     }
     //echo '<pre>'; print_r($where); echo '</pre>'; exit();
     return $where;
 }
示例#13
0
 /**
  * @param $artist name or spotify uri
  * @param $album name
  * @return spotify:album:uri or false
  */
 function getAlbumId($artist, $album)
 {
     if (!is_spotify_uri($artist)) {
         $artist = $this->getArtistId($artist);
     }
     if (!$artist) {
         return false;
     }
     $disco = $this->getArtistAlbums($artist);
     foreach ($disco as $a) {
         if ($a['album'] == $album) {
             //d("exact match");
             return $a['id'];
         }
         if (soundex($a['album']) == soundex($album)) {
             //d("fuzzy match");
             return $a['id'];
         }
     }
     return false;
 }
示例#14
0
function pleac_Soundex_Matching()
{
    #-----------------------------
    $code = soundex($string);
    #-----------------------------
    $phoned_words = metaphone("Schwern");
    #-----------------------------
    // substitution function for getpwent():
    // returns an array of user entries,
    // each entry contains the username and the full name
    function getpwent()
    {
        $pwents = array();
        $handle = fopen("passwd", "r");
        while (!feof($handle)) {
            $line = fgets($handle);
            if (preg_match("/^#/", $line)) {
                continue;
            }
            $cols = explode(":", $line);
            $pwents[$cols[0]] = $cols[4];
        }
        return $pwents;
    }
    print "Lookup user: "******"/(\\w+)[^,]*\\b(\\w+)/", $fullname, $matches);
        list(, $firstname, $lastname) = $matches;
        if ($name_code == soundex($username) || $name_code == soundex($lastname) || $name_code == soundex($firstname)) {
            printf("%s: %s %s\n", $username, $firstname, $lastname);
        }
    }
    #-----------------------------
}
示例#15
0
 public function getPreMatched($lastname, $firstname, $gender, $email)
 {
     $matchedOrders = array();
     $sound_lastname = soundex($lastname);
     $sound_firstname = soundex($firstname);
     //        Mage::log("searching Match for ". $sound_firstname."  ".$sound_lastname."   ".$gender , null, 'xulin.log');
     $customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('firstname')->addAttributeToSelect('lastname')->addAttributeToSelect('gender')->addAttributeToSelect('email');
     $i = 0;
     foreach ($customers as $customer) {
         if ($email == $customer->getEmail()) {
             Mage::log("Email Matched", null, 'xulin.log');
             return array("status" => "emailmatched", "customerid" => $customer->getId());
         }
         if ($sound_firstname == soundex($customer->getFirstname()) && $sound_lastname == soundex($customer->getLastname()) && $gender == $customer->getGender()) {
             $matchedOrders[] = $customer->getId();
         }
         $i++;
     }
     Mage::log($matchedOrders, null, 'xulin.log');
     Mage::log("times: " . $i, null, 'xulin.log');
     return array("status" => "searching", "customerids" => $matchedOrders);
 }
示例#16
0
function update_db()
{
    global $_DB, $_STATE;
    $sql = "UPDATE " . $_DB->prefix . "c00_person\n\t\t\tSET lastname=:lastname, lastsoundex='" . soundex($_STATE->fields["Last Name"]->value()) . "',\n\t\t\tfirstname=:firstname";
    if ($_STATE->fields["Log ID"]->value() != "") {
        $sql .= ", loginname=:loginname";
    }
    if ($_STATE->fields["Password"]->value() != "") {
        $sql .= ", password=:password";
    }
    if ($_STATE->fields["Email"]->value() != "") {
        $sql .= ", email=:email";
    }
    $sql .= " WHERE person_id=" . $_STATE->record_id . ";";
    $stmt = $_DB->prepare($sql);
    $stmt->bindValue(':lastname', $_STATE->fields["Last Name"]->value(), PDO::PARAM_STR);
    $stmt->bindValue(':firstname', $_STATE->fields["First Name"]->value(), PDO::PARAM_STR);
    if ($_STATE->fields["Log ID"]->value() != "") {
        $stmt->bindValue(':loginname', $_STATE->fields["Log ID"]->value(), PDO::PARAM_STR);
    }
    if (PHP_VERSION_ID < 50500) {
        require_once "password.php";
    }
    if ($_STATE->fields["Password"]->value() != "") {
        $stmt->bindValue(':password', password_hash($_STATE->fields["Password"]->value(), PASSWORD_DEFAULT), PDO::PARAM_STR);
    }
    if ($_STATE->fields["Email"]->value() != "") {
        $stmt->bindValue(':email', $_STATE->fields["Email"]->value(), PDO::PARAM_STR);
    }
    $stmt->execute();
    $sql = "UPDATE " . $_DB->prefix . "c10_person_organization SET inactive_asof=:inactive\n\t\t\tWHERE person_organization_id=" . $_STATE->person_organization_id . ";";
    $stmt = $_DB->prepare($sql);
    if ($_STATE->fields["Inactive As Of"]->value() == "") {
        $stmt->bindValue(':inactive', NULL, db_connect::PARAM_DATE);
    } else {
        $stmt->bindValue(':inactive', $_STATE->fields["Inactive As Of"]->value(), db_connect::PARAM_DATE);
    }
    $stmt->execute();
}
示例#17
0
 public static function soundex_std($text)
 {
     $words = explode(' ', $text);
     $soundex_array = array();
     foreach ($words as $word) {
         $soundex = soundex($word);
         // Only return codes from recognisable sounds
         if ($soundex != '0000') {
             $soundex_array[] = $soundex;
         }
     }
     // Combine words, e.g. “New York” as “Newyork”
     if (count($words) > 1) {
         $soundex_array[] = soundex(strtr($text, ' ', ''));
     }
     // A varchar(255) column can only hold 51 4-character codes (plus 50 delimiters)
     $soundex_array = array_slice(array_unique($soundex_array), 0, 51);
     if ($soundex_array) {
         return implode(':', $soundex_array);
     } else {
         return null;
     }
 }
示例#18
0
 /**
  * Generate Russell soundex codes for a given text.
  *
  * @param $text
  *
  * @return null|string
  */
 public static function russell($text)
 {
     $words = preg_split('/\\s/', $text, -1, PREG_SPLIT_NO_EMPTY);
     $soundex_array = array();
     foreach ($words as $word) {
         $soundex = soundex($word);
         // Only return codes from recognisable sounds
         if ($soundex !== '0000') {
             $soundex_array[] = $soundex;
         }
     }
     // Combine words, e.g. “New York” as “Newyork”
     if (count($words) > 1) {
         $soundex_array[] = soundex(strtr($text, ' ', ''));
     }
     // A varchar(255) column can only hold 51 4-character codes (plus 50 delimiters)
     $soundex_array = array_slice(array_unique($soundex_array), 0, 51);
     if ($soundex_array) {
         return implode(':', $soundex_array);
     } else {
         return '';
     }
 }
 public function wpshop_search_where_in_customer($where)
 {
     if (is_admin() && (!empty($_GET['post_type']) && $_GET['post_type'] == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS) && (!empty($_GET['s']) || !empty($_GET['entity_filter']))) {
         global $wpdb;
         $where = "\tAND {$wpdb->posts}.post_type = '" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "'";
         if (!empty($_GET['entity_filter'])) {
             switch ($_GET['entity_filter']) {
                 case 'orders':
                     $operator = 'IN';
                     break;
                 case 'no_orders':
                     $operator = 'NOT IN';
                     break;
             }
             $where .= "\tAND (\t{$wpdb->posts}.post_author {$operator} (\r\n\t\t\t\t\t\t\t\t\t\tSELECT {$wpdb->posts}.post_author\r\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts}\r\n\t\t\t\t\t\t\t\t\t\tWHERE {$wpdb->posts}.post_type = '" . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . "'\r\n\t\t\t\t\t\t\t\t\t\tAND {$wpdb->posts}.post_status != 'auto-draft'\r\n\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t)";
         }
         if (!empty($_GET['s'])) {
             $s_soundex = soundex($_GET['s']);
             $s = strtoupper($_GET['s']);
             $where .= "\tAND ( \t{$wpdb->posts}.ID = '{$s}'\r\n\t\t\t\t\t\t\t\t\tOR UPPER( {$wpdb->posts}.post_title ) LIKE '%{$s}%'\r\n\t\t\t\t\t\t\t\t\tOR SOUNDEX( {$wpdb->posts}.post_title ) = '{$s_soundex}'\r\n\t\t\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t\t\t{$wpdb->posts}.post_author IN (\r\n\t\t\t\t\t\t\t\t\t\t\tSELECT U.ID\r\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->users} AS U\r\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN {$wpdb->usermeta} AS UM \r\n\t\t\t\t\t\t\t\t\t\t\tON ( UM.user_id = U.ID )\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tUPPER( U.user_email ) LIKE '%{$s}%'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( U.user_email ) = '{$s_soundex}'\r\n\t\t\t\t\t\t\t\t\t\t\t\t) \r\n\t\t\t\t\t\t\t\t\t\t\t\tOR\r\n\t\t\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tUM.meta_key = 'first_name'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( UM.meta_value ) LIKE '%{$s}%'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( UM.meta_value ) = '{$s_soundex}'\r\n\t\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t\t\tOR\r\n\t\t\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tUM.meta_key = 'last_name'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( UM.meta_value ) LIKE '%{$s}%'\r\n\t\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( UM.meta_value ) = '{$s_soundex}'\r\n\t\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\tOR (\r\n\t\t\t\t\t\t\t\t\t\t{$wpdb->posts}.post_author IN (\r\n\t\t\t\t\t\t\t\t\t\t\tSELECT P.post_author\r\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} AS P\r\n\t\t\t\t\t\t\t\t\t\t\tINNER JOIN {$wpdb->postmeta} AS PM\r\n\t\t\t\t\t\t\t\t\t\t\tON ( PM.post_id = P.ID )\r\n\t\t\t\t\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\t\t\t\t\tP.post_type = '" . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . "'\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND PM.meta_key = '_wpshop_address_metadata'\r\n\t\t\t\t\t\t\t\t\t\t\t\tAND UPPER( PM.meta_value ) LIKE '%{$s}%'\r\n\t\t\t\t\t\t\t\t\t\t\t\tOR SOUNDEX( PM.meta_value ) = '{$s_soundex}'\r\n\t\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t\t)\r\n\t\t\t\t\t\t\t\t)";
         }
     }
     return $where;
 }
示例#20
0
 /**
  * Retrieve region code from name
  * 
  * @param string $countryId
  * @param string $regionName
  * @param boolean $regionOnly
  * @return string|null
  */
 public static function getRegionCode($countryId, $regionName, $regionOnly = true)
 {
     $regions = self::getRegions($countryId);
     if (empty($regions)) {
         return null;
     }
     // cleanup entry skin
     $regionName = self::removeAccents($regionName);
     // search for strict matches
     foreach ($regions as $code => $name) {
         if (strcasecmp($regionName, $name) === 0) {
             // DE-BW or BW
             return $regionOnly ? substr($code, 3) : $code;
         }
     }
     // find similar matches
     foreach ($regions as $code => $name) {
         if (soundex($regionName) === soundex($name)) {
             // DE-BW or BW
             return $regionOnly ? substr($code, 3) : $code;
         }
     }
     return null;
 }
 /**
  * Return the soundex
  * @param string $token
  * @return string
  */
 public function transform($token)
 {
     return soundex($token);
 }
示例#22
0
 /**
  * Run the scripts
  *
  * @throws ScriptException
  */
 public function run()
 {
     if (!isset($_SERVER['argv'][1])) {
         $_SERVER['argv'][1] = 'commands';
     }
     $input = $_SERVER['argv'][1];
     // Try to dispatch the command
     foreach ($this->_commands as $command) {
         if ($command->hasIdentifier($input)) {
             return $this->dispatch($command);
         }
     }
     // Check for alternatives
     $available = [];
     foreach ($this->_commands as $command) {
         $providedCommands = $command->getCommands();
         foreach ($providedCommands as $alias) {
             $soundex = soundex($alias);
             if (!isset($available[$soundex])) {
                 $available[$soundex] = [];
             }
             $available[$soundex][] = $alias;
         }
     }
     // Show exception with/without alternatives
     $soundex = soundex($input);
     $message = sprintf('%s is not a recognized command.', $input);
     if (isset($available[$soundex])) {
         throw new ScriptException(sprintf('%s Did you mean: %s?', $message, join(' or ', $available[$soundex])));
     } else {
         throw new ScriptException($message);
     }
 }
示例#23
0
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     $imgContent = null;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             ob_start();
             $result = @imageGIF($tmp->target);
             $imgContent = ob_get_clean();
             break;
         case 'image/jpeg':
             ob_start();
             $result = @imageJPEG($tmp->target, null, ASIDO_GD_JPEG_QUALITY);
             $imgContent = ob_get_clean();
             break;
         case 'image/wbmp':
             ob_start();
             $result = @imageWBMP($tmp->target);
             $imgContent = ob_get_clean();
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             ob_start();
             $result = @imagePNG($tmp->target, null, ASIDO_GD_PNG_QUALITY);
             $imgContent = ob_get_clean();
             break;
     }
     if ($result) {
         jimport('joomla.filesystem.file');
         JFile::write($tmp->target_filename, $imgContent);
     }
     @$this->__destroy_source($tmp);
     @$this->__destroy_target($tmp);
     return $result;
 }
示例#24
0
 function resolve_keyword($keyword, $create = false)
 {
     debug("resolving keyword " . $keyword . ". Create=" . ($create ? "true" : "false"));
     $keyword = substr($keyword, 0, 100);
     # Trim keywords to 100 chars for indexing, as this is the length of the keywords column.
     global $quoted_string;
     if (!$quoted_string) {
         $keyword = normalize_keyword($keyword);
         debug("resolving normalized keyword " . $keyword . ".");
     }
     # Stemming support. If enabled and a stemmer is available for the current language, index the stem of the keyword not the keyword itself.
     # This means plural/singular (and other) forms of a word are treated as equivalents.
     global $stemming;
     if ($stemming && function_exists("GetStem")) {
         $keyword = GetStem($keyword);
     }
     # Returns the keyword reference for $keyword, or false if no such keyword exists.
     $return = sql_value("select ref value from keyword where keyword='" . trim(escape_check($keyword)) . "'", false);
     if ($return === false && $create) {
         # Create a new keyword.
         debug("Creating new keyword for " . $keyword);
         sql_query("insert into keyword (keyword,soundex,hit_count) values ('" . escape_check($keyword) . "',left('" . soundex(escape_check($keyword)) . "',10),0)");
         $return = sql_insert_id();
     }
     return $return;
 }
示例#25
0
 /** 
  * Executes the search.
  * 
  * @param string $_search
  * 
  * @return array
  */
 function search($_search)
 {
     $startTime = microtime(true);
     $this->searchString = trim(stripslashes($_search));
     $keywordCount = $this->parseSearchString($this->searchString);
     if (empty($this->searchString) or empty($this->searchArray)) {
         return array('count' => 0, 'hits' => array(), 'keywords' => array(), 'keywords' => '', 'sql' => 'No search performed.', 'blacklisted' => false, 'hash' => '', 'simwordsnewsearch' => '', 'simwords' => array(), 'time' => 0);
     }
     // ask cache
     if ($this->cache and $this->isCached($this->searchString)) {
         $this->cachedArray['time'] = microtime(true) - $startTime;
         if ($this->similarwords and $this->cachedArray['count'] > 0) {
             $this->storeKeywords($this->searchArray);
         }
         // EP registrieren
         rex_register_extension_point('A587_SEARCH_EXECUTED', $this->cachedArray);
         //var_dump($this->cachedArray['sql']);
         return $this->cachedArray;
     }
     $return = array();
     $return['simwordsnewsearch'] = '';
     $return['simwords'] = array();
     if ($this->similarwords) {
         $simwords = array();
         foreach ($this->searchArray as $keyword) {
             $sounds = array();
             if ($this->similarwordsMode & A587_SIMILARWORDS_SOUNDEX) {
                 $sounds[] = "soundex = '" . soundex($keyword['search']) . "'";
             }
             if ($this->similarwordsMode & A587_SIMILARWORDS_METAPHONE) {
                 $sounds[] = "metaphone = '" . metaphone($keyword['search']) . "'";
             }
             if ($this->similarwordsMode & A587_SIMILARWORDS_COLOGNEPHONE) {
                 $sounds[] = "colognephone = '" . $this->cologne_phone($keyword['search']) . "'";
             }
             $simwords[] = sprintf("\n          SELECT\n            GROUP_CONCAT(DISTINCT keyword SEPARATOR ' ') as keyword,\n            '%s' AS typedin,\n            SUM(count) as count\n          FROM `%s`\n          WHERE 1\n            %s\n            AND (%s)", $keyword['search'], $this->tablePrefix . '587_keywords', $this->clang !== false ? 'AND (clang = ' . intval($this->clang) . ' OR clang IS NULL)' : '', implode(' OR ', $sounds));
         }
         // simwords
         $simWordsSQL = new rex_sql();
         foreach ($simWordsSQL->getArray(sprintf("\n        %s\n        GROUP BY %s\n        ORDER BY SUM(count)", implode(' UNION ', $simwords), $this->similarwordsPermanent ? "''" : 'keyword, typedin')) as $simword) {
             $return['simwords'][$simword['typedin']] = array('keyword' => $simword['keyword'], 'typedin' => $simword['typedin'], 'count' => $simword['count']);
         }
         $newsearch = array();
         foreach ($this->searchArray as $keyword) {
             if (preg_match($this->encodeRegex('~\\s~is'), $keyword['search'])) {
                 $quotes = '"';
             } else {
                 $quotes = '';
             }
             if (array_key_exists($keyword['search'], $return['simwords'])) {
                 $newsearch[] = $quotes . $return['simwords'][$keyword['search']]['keyword'] . $quotes;
             } else {
                 $newsearch[] = $quotes . $keyword['search'] . $quotes;
             }
         }
         $return['simwordsnewsearch'] = implode(' ', $newsearch);
     }
     if ($this->similarwordsPermanent) {
         $keywordCount = $this->parseSearchString($this->searchString . ' ' . $return['simwordsnewsearch']);
     }
     $searchColumns = array();
     switch ($this->textMode) {
         case 'unmodified':
             $searchColumns[] = 'unchangedtext';
             break;
         case 'both':
             $searchColumns[] = 'plaintext';
             $searchColumns[] = 'unchangedtext';
             break;
         default:
             $searchColumns[] = 'plaintext';
     }
     $sql = new rex_sql();
     $Awhere = array();
     $Amatch = array();
     foreach ($this->searchArray as $keyword) {
         // build MATCH-Array
         $match = sprintf("(( MATCH (`%s`) AGAINST ('%s')) * %d)", implode('`,`', $searchColumns), $sql->escape($keyword['search']), $keyword['weight']);
         if ($this->searchEntities) {
             $match .= ' + ' . sprintf("(( MATCH (`%s`) AGAINST ('%s')) * %d)", implode('`,`', $searchColumns), $sql->escape(htmlentities($keyword['search'], ENT_COMPAT, 'UTF-8')), $keyword['weight']);
         }
         $Amatch[] = $match;
         // build WHERE-Array
         if ($this->searchMode == 'match') {
             $AWhere[] = $match;
         } else {
             $tmpWhere = array();
             foreach ($searchColumns as $searchColumn) {
                 $tmpWhere[] = sprintf("(`%s` LIKE '%%%s%%')", $searchColumn, str_replace(array('%', '_'), array('\\%', '\\_'), $sql->escape($keyword['search'])));
                 if ($this->searchEntities) {
                     $tmpWhere[] = sprintf("(`%s` LIKE '%%%s%%')", $searchColumn, str_replace(array('%', '_'), array('\\%', '\\_'), $sql->escape(htmlentities($keyword['search'], ENT_COMPAT, 'UTF-8'))));
                 }
             }
             $AWhere[] = '(' . implode(' OR ', $tmpWhere) . ')';
         }
         /*if($this->logicalMode == ' AND ')
             $Awhere[] = '+*'.$keyword['search'].'*';
           else
             $AWhere[] = '*'.$keyword['search'].'*';*/
     }
     // build MATCH-String
     $match = '(' . implode(' + ', $Amatch) . ' + 1)';
     // build WHERE-String
     $where = '(' . implode($this->logicalMode, $AWhere) . ')';
     #$where = sprintf("( MATCH (%s) AGAINST ('%s' IN BOOLEAN MODE)) > 0",implode(',',$searchColumns),implode(' ',$Awhere));
     // language
     if ($this->clang !== false) {
         $where .= ' AND (clang = ' . intval($this->clang) . ' OR clang IS NULL)';
     }
     $AwhereToSearch = array();
     if (array_key_exists('articles', $this->searchInIDs) and count($this->searchInIDs['articles'])) {
         $AwhereToSearch[] = "texttype = 'article'";
         $AwhereToSearch[] = "(fid IN (" . implode(',', $this->searchInIDs['articles']) . "))";
     }
     if (array_key_exists('categories', $this->searchInIDs) and count($this->searchInIDs['categories'])) {
         $AwhereToSearch[] = "(catid IN (" . implode(',', $this->searchInIDs['categories']) . ") AND ftable = '" . $sql->escape($this->tablePrefix) . "article')";
     }
     if (array_key_exists('filecategories', $this->searchInIDs) and count($this->searchInIDs['filecategories'])) {
         $AwhereToSearch[] = "(catid IN (" . implode(',', $this->searchInIDs['filecategories']) . ") AND ftable = '" . $sql->escape($this->tablePrefix) . "file')";
     }
     if (array_key_exists('db_columns', $this->searchInIDs) and count($this->searchInIDs['db_columns'])) {
         $AwhereToSearch[] = "texttype = 'db_column'";
         $Acolumns = array();
         foreach ($this->searchInIDs['db_columns'] as $table => $colArray) {
             foreach ($colArray as $column) {
                 //$Acolumns[] = sprintf("(ftable = '%s' AND fcolumn = '%s' %s)", $table, $column, $strSearchArticles);
                 $Acolumns[] = sprintf("(ftable = '%s' AND fcolumn = '%s')", $table, $column);
             }
         }
         $AwhereToSearch[] = '(' . implode(' OR ', $Acolumns) . ')';
     }
     if (count($AwhereToSearch)) {
         if ($this->searchArticles) {
             $where .= " AND ((texttype = 'article') OR (" . implode(' AND ', $AwhereToSearch) . '))';
         } else {
             $where .= ' AND (' . implode(' AND ', $AwhereToSearch) . ')';
         }
     }
     if (!empty($this->where)) {
         $where .= ' AND (' . $this->where . ')';
     }
     // build ORDER-BY-String
     $Aorder = array();
     foreach ($this->order as $col => $dir) {
         $Aorder[] = $col . ' ' . $dir;
     }
     $selectFields = array();
     if ($this->groupBy) {
         $selectFields[] = sprintf('(SELECT SUM%s FROM `%s` summe WHERE summe.fid = r1.fid AND summe.ftable = r1.ftable) AS RELEVANCE587', $match, $this->tablePrefix . '587_searchindex');
         $selectFields[] = sprintf('(SELECT COUNT(*) FROM `%s` summe WHERE summe.fid = r1.fid AND (summe.ftable IS NULL OR summe.ftable = r1.ftable) AND (summe.fcolumn IS NULL OR summe.fcolumn = r1.fcolumn) AND summe.texttype = r1.texttype) AS COUNT587', $this->tablePrefix . '587_searchindex');
     } else {
         $selectFields[] = $match . ' AS RELEVANCE587';
     }
     $selectFields[] = '`id`';
     $selectFields[] = '`fid`';
     $selectFields[] = '`catid`';
     $selectFields[] = '`ftable`';
     $selectFields[] = '`fcolumn`';
     $selectFields[] = '`texttype`';
     $selectFields[] = '`clang`';
     $selectFields[] = '`unchangedtext`';
     $selectFields[] = '`plaintext`';
     $selectFields[] = '`teaser`';
     $selectFields[] = '`values`';
     $selectFields[] = '`filename`';
     $selectFields[] = '`fileext`';
     if ($this->groupBy) {
         $query = sprintf('
     SELECT SQL_CALC_FOUND_ROWS %s
     FROM `%s` r1
     WHERE (%s) AND (
       (
         %s = (SELECT MAX%s FROM `%s` r2 WHERE r1.ftable = r2.ftable AND r1.fid = r2.fid %s)
         AND fid IS NOT NULL
       ) OR
       ftable IS NULL
     )
     GROUP BY ftable,fid,clang
     ORDER BY %s
     LIMIT %d,%d', implode(",\n", $selectFields), $this->tablePrefix . '587_searchindex', $where, $match, $match, $this->tablePrefix . '587_searchindex', $this->clang !== false ? 'AND (clang = ' . intval($this->clang) . ' OR clang IS NULL)' : '', implode(",\n", $Aorder), $this->limit[0], $this->limit[1]);
     } else {
         $query = sprintf('
     SELECT SQL_CALC_FOUND_ROWS %s
     FROM `%s`
     WHERE %s
     ORDER BY %s
     LIMIT %d,%d', implode(",\n", $selectFields), $this->tablePrefix . '587_searchindex', $where, implode(",\n", $Aorder), $this->limit[0], $this->limit[1]);
     }
     #echo '<pre>'.$query.'</pre>';
     $sqlResult = $sql->getArray($query);
     $indexIds = array();
     $count = 0;
     $sqlResultCount = $sql->getArray('SELECT FOUND_ROWS() as count');
     $return['count'] = intval($sqlResultCount[0]['count']);
     // hits
     $return['hits'] = array();
     $i = 0;
     foreach ($sqlResult as $hit) {
         $indexIds[] = $hit['id'];
         $return['hits'][$i] = array();
         $return['hits'][$i]['id'] = $hit['id'];
         $return['hits'][$i]['fid'] = $hit['fid'];
         if (!is_numeric($hit['fid']) and !is_null($json_decode_fid = json_decode($hit['fid'], true))) {
             $return['hits'][$i]['fid'] = $json_decode_fid;
         }
         $return['hits'][$i]['table'] = $hit['ftable'];
         $return['hits'][$i]['column'] = $hit['fcolumn'];
         $return['hits'][$i]['type'] = $hit['texttype'];
         $return['hits'][$i]['clang'] = $hit['clang'];
         $return['hits'][$i]['unchangedtext'] = $hit['unchangedtext'];
         $return['hits'][$i]['plaintext'] = $hit['plaintext'];
         $return['hits'][$i]['teaser'] = $this->getTeaserText($hit['plaintext']);
         $return['hits'][$i]['highlightedtext'] = $this->getHighlightedText($hit['plaintext']);
         $return['hits'][$i]['article_teaser'] = $hit['teaser'];
         $return['hits'][$i]['values'] = a587_config_unserialize($hit['values']);
         $return['hits'][$i]['filename'] = $hit['filename'];
         $return['hits'][$i]['fileext'] = $hit['fileext'];
         $i++;
         if ($this->groupBy) {
             $count += $hit['COUNT587'];
         }
     }
     if ($this->groupBy) {
         $indexIds = array();
         foreach ($sql->getArray(sprintf('
         SELECT id
         FROM `%s`
         WHERE %s
         LIMIT %d,%d', $this->tablePrefix . '587_searchindex', $where, $this->limit[0], $count)) as $hit) {
             $indexIds[] = $hit['id'];
         }
     }
     // keywords, which were searched for
     $return['keywords'] = $this->searchArray;
     $return['searchterm'] = $this->searchString;
     // sql
     $return['sql'] = $query;
     // was any blacklisted word searched for?
     $return['blacklisted'] = false;
     if (count($this->blacklisted) > 0) {
         $return['blacklisted'] = $this->blacklisted;
     }
     $return['hash'] = $this->cacheHash($this->searchString);
     if ($this->similarwords and $i) {
         $this->storeKeywords($this->searchArray);
     }
     if ($this->cache) {
         $this->cacheSearch(serialize($return), $indexIds);
     }
     // EP registrieren
     rex_register_extension_point('A587_SEARCH_EXECUTED', $return);
     $return['time'] = microtime(true) - $startTime;
     return $return;
 }
示例#26
0
 public static function standardizeValues($label, $values)
 {
     $stdValues = array();
     if (is_array(@$values)) {
         foreach ($values as $value) {
             $stdValue = '';
             if (strpos($label, 'Surname') !== false || strpos($label, 'Given') !== false) {
                 $pieces = explode(' ', $value);
                 $sdxValue = '';
                 foreach ($pieces as $piece) {
                     $lowerPiece = mb_strtolower($piece);
                     if ($piece && $lowerPiece != 'unknown' && $lowerPiece != '?' && $lowerPiece != 'fnu' && $lowerPiece != 'lnu' && $lowerPiece != 'nn' && $lowerPiece != 'n.n.') {
                         if ($stdValue) {
                             $stdValue .= ' ';
                             $sdxValue .= ' ';
                         }
                         $stdValue .= $lowerPiece;
                         $sdxValue .= soundex($piece);
                     }
                 }
                 $stdValue .= '|' . $sdxValue;
             } else {
                 if (strpos($label, 'date') !== false) {
                     $stdValue = StructuredData::getDateKey($value);
                 } else {
                     if (strpos($label, 'place') !== false) {
                         $stdValue = StructuredData::getPlaceKey($value);
                         $pos = mb_strpos($stdValue, ', united states');
                         if ($pos !== false) {
                             $stdValue = mb_substr($stdValue, 0, $pos);
                             // remove united states for ,-check in scoreMatch below
                         }
                     } else {
                         if (strpos($label, 'ParentFamilyTitle') !== false || strpos($label, 'SpouseFamilyTitle') !== false) {
                             $pos = mb_strpos($value, '(');
                             if ($pos !== false) {
                                 $stdValue = mb_substr($value, 0, $pos);
                             } else {
                                 $stdValue = $value;
                             }
                             $stdValue = trim(mb_convert_case($stdValue, MB_CASE_LOWER));
                         } else {
                             $stdValue = $value;
                         }
                     }
                 }
             }
             if ($stdValue) {
                 $stdValues[] = $stdValue;
             }
         }
     } else {
         if ($label == 'childGedcomMatchTitle' && @$values) {
             // keep this for matching
             $stdValues[] = $values;
         }
     }
     return $stdValues;
 }
示例#27
0
 function str_similar($str1, $str2)
 {
     /*
         $count = 0;
        
         $str1 = ereg_replace("[^a-z]", ' ', strtolower($str1));
         while(strstr($str1, '  ')) {
             $str1 = str_replace('  ', ' ', $str1);
         }
         $str1 = explode(' ', $str1);
        
         $str2 = ereg_replace("[^a-z]", ' ', strtolower($str2));
         while(strstr($str2, '  ')) {
             $str2 = str_replace('  ', ' ', $str2);
         }
         $str2 = explode(' ', $str2);
        
         if(count($str1)<count($str2)) {
             $tmp = $str1;
             $str1 = $str2;
             $str2 = $tmp;
             unset($tmp);
         }
        
         for($i=0; $i<count($str1); $i++) {
             if(in_array($str1[$i], $str2)) {
                 $count++;
             }
         }
        
         return $count/count($str2)*100;
     */
     //      if (similar_text ($last, $category->title, $match) < 50)
     //      if (levenshtein ($last, $category->title) > 100)
     //      if (str_compare ($last, $category->title) < 50)
     $t = array();
     $t[] = explode(' ', $str1);
     $t[] = explode(' ', $str2);
     return !strncmp(soundex($t[0][0]), soundex($t[1][0]), 3);
 }
示例#28
0
 public static function soundex($str, $language = 'EN')
 {
     mb_internal_encoding("UTF-8");
     $str = mb_convert_case($str, MB_CASE_LOWER, "UTF-8");
     if ($language == 'RU') {
         //$str = mb_ereg_replace("[^а-яА-ЯЁё]", "", $str);
         return self::ruSoundex($str);
     } else {
         //$str = mb_ereg_replace("[^a-zA-Z]", "", $str);
         return soundex($str);
     }
 }
示例#29
0
 public function resolve($request)
 {
     if (strtolower(trim($request->artist)) != 'mokele') {
         return array();
     }
     if (soundex($request->track) != soundex('hiding in your insides')) {
         return array();
     }
     $pi = new stdclass();
     $pi->artist = "Mokele";
     $pi->track = "Hiding In Your Insides (php)";
     $pi->album = "You Yourself are Me Myself and I am in Love";
     $pi->source = "Mokele.co.uk";
     $pi->size = 4971780;
     $pi->bitrate = 160;
     $pi->duration = 248;
     // NB this url should be url encoded properly:
     $pi->url = "http://play.mokele.co.uk/music/Hiding%20In%20Your%20Insides.mp3";
     $pi->score = (double) 1.0;
     return array($pi);
 }
示例#30
0
     $fname_length = strlen($string[0]);
     $sname_length = strlen($string[$keyword_count - 1]);
     // exact match, fname AND sname
     if (strtolower($string[0] . ' ') == strtolower(substr($val["cli_fname"] . ' ', 0, $fname_length + 1)) && strtolower($string[$keyword_count - 1]) == strtolower(substr($val["cli_sname"], 0, $sname_length))) {
         $val['pos'] = "0";
         $results[0][] = $val;
     } elseif (strtolower($string[0]) == strtolower(substr($val["cli_fname"], 0, $fname_length)) && strtolower($string[$keyword_count - 1]) == strtolower(substr($val["cli_sname"], 0, $sname_length))) {
         $val['pos'] = "1";
         $results[1][] = $val;
     } elseif (strtolower(soundex($string[0])) == strtolower(soundex(substr($val["cli_fname"], 0, $fname_length))) && strtolower($string[$keyword_count - 1]) == strtolower(substr($val["cli_sname"], 0, $sname_length))) {
         $val['pos'] = "2";
         $results[2][] = $val;
     } elseif (strtolower($string[0]) == strtolower(substr($val["cli_fname"], 0, $fname_length)) && strtolower(soundex($string[$keyword_count - 1])) == strtolower(soundex(substr($val["cli_sname"], 0, $sname_length)))) {
         $val['pos'] = "3";
         $results[3][] = $val;
     } elseif (strtolower(soundex($string[0])) == strtolower(soundex(substr($val["cli_fname"], 0, $fname_length + 1))) && strtolower(soundex($string[$keyword_count - 1])) == strtolower(soundex(substr($val["cli_sname"], 0, $sname_length)))) {
         $val['pos'] = "4";
         $results[4][] = $val;
     } elseif (levenshtein($_GET["cli_name"], $val["cli_name"]) < 8) {
         $val['pos'] = "5";
         $val['score'] = levenshtein($_GET["cli_name"], $val["cli_name"]);
         $results[5][] = $val;
     }
 }
 if ($results) {
     // sort lev array by score
     if ($results[5]) {
         //print_r($results[5]);
         $results[5] = SortDataSet($results[5], 'score');
     }
     ksort($results);