PHP Classes

File: demo_multilingual.php

Recommend this page to a friend!
  Classes of Philipp Strazny   Fuzzy Index   demo_multilingual.php   Download  
File: demo_multilingual.php
Role: Example script
Content type: text/plain
Description: usage example
Class: Fuzzy Index
Index text for performing fuzzy search
Author: By
Last change:
Date: 11 years ago
Size: 12,292 bytes
 

Contents

Class file image Download
<?php include('FuzzyIndex.php'); $sentences = array( 'EN: * Euro holds above 3-1/2 month low versus dollar', 'EN: * Slight respite in Spain, Greek worries gives support but euro vulnerable', 'EN: * Euro near 3-1/2 year low vs sterling as BoE holds rates, QE', 'EN: The euro stayed close to a 3 1/2-month low against the dollar on Thursday and was expected to suffer further losses as political deadlock in Greece increased the risk of insolvency and a possible euro exit.', 'EN: The common currency gained a short-term reprive as stress in Spanish debt markets abated slightly and after Greece secured funds needed for bond repayments.', 'DE: Nach zwei gescheiterten Versuchen der stärksten Parteien ruhen die Hoffnungen nun auf Pasok-Parteichef Evangelos Venizelos.', 'DE: Der Sozialist kündigte am Donnerstag in Athen an, sich im "nationalen Interesse" an der schwierigen Aufgabe zu versuchen.', 'DE: Knackpunkt ist das mit den Geldgebern von EU und IWF vereinbarte Sparprogramm, für das es im Parlament keine Mehrheit mehr gibt.', 'DE: Die EZB machte deutlich, dass der Geldhahn bei einer Abkehr vom Sanierungskurs zugedreht wird:', 'DE: "Das Land kann keine weitere Hilfe erwarten, wenn es die Reformen nicht vorantreibt", mahnte EZB-Ratsmitglied Ewald Nowotny.', 'ES: José Ignacio Goirigolzarri, recién nombrado presidente ejecutivo de la nacionalizada Bankia y muy crítico con la reciente reforma bancaria del Gobierno, tendrá que coger el toro por los cuernos si quiere recuperar la confianza de los mercados internacionales en un banco saneado con dinero público.', 'ES: En febrero pasado, Goirigolzarri afirmó en su blog goirigolzarri.com que la reforma financiera aprobada en febrero por el Gobierno del Partido Popular no conllevaría un aumento del crédito.', 'ES: "(La) reforma del sistema financiero en nuestro país, no va a traer un crecimiento del crédito (por mucho que se proclame desde todas las instancias), sino que debemos ser más realistas y precisos en nuestros objetivos", dijo.', 'AR: والخام الأمريكي مكاسبها المتواضعة يوم الخميس بعدما أظهر تقريران تراجعا طفيفا لطلبات اعانة البطالة الأمريكية الأسبوع الماضي واتساع العجز التجاري الأمريكي بأكثر من المتوقع في مارس اذار.', 'AR: وارتفع برنت في العقود الاجلة تسليم يونيو حزيران 40 سنتا إلى 113.60 دولار للبرميل بحلول الساعة 1241 بتوقيت جرينتش بعد تداولات بين 112.57 و113.64 دولار للبرميل.', 'AR: وارتفعت العقود الاجلة للخام الأمريكي الخفيف تسليم يونيو 85 سنتا إلى 97.66 دولار بعد تداولات بين 96.08 و97.69 دولار للبرميل.', 'AR: (إعداد محمود عبد الجواد للنشرة العربية - تحرير عبد المنعم هيكل)', 'ZH: 业内人士表示,资本市场不景气、新基金销售低迷的双重影响下,基金公司也寄希望于更多的销售渠道,渴望与第三方支付企业合作,以带来更多客户资源.', 'ZH: 去年10月证监会对第三方基金销售平台进行开闸,汇付数据、通联支付、银联支付、易宝支付4家机构陆续获得基金第三方支付资格.', 'ZH: 支付宝公司成立於2004年,用户覆盖了整个C2C(个人对个人)、B2C及B2B(企业对企业)领域,根据其官方网站数据显示,截至2011年末,公司注册用户已突破6.5亿.', 'ZH: 支付宝的母公司--阿里巴巴集团是中国最大的电子商务集团,集团旗下B2B业务分支--阿里巴巴(1688.HK: 行情)已在香港上市.(完)', 'JP: [ウィーン 10日 ロイター] 欧州中央銀行(ECB)理事会メンバーであるオーストリア中銀のノボトニー総裁は、ユーロ圏からのギリシャ離脱の可能性を議論するには時期尚早だが、改革を進めることができなければ国外からの支援はこれ以上望めない、との見解を示した。', 'JP: 同総裁はギリシャ離脱の見通しに関する記者団の質問に「議論するには時期尚早だ」と指摘。', 'JP: 「現在議論しなければならないのは、状況を解決するため何に集中すればいいかということだ。解決の鍵となるのはギリシャ政府と政治システムだ」と述べた。', 'TH: อันดับ 5 นายภิมุข เทียมเศวต จากโรงเรียนเตรียมอุดมศึกษา ได้คะแนน 84.73 สอบได้คณะนิติศาสตร์ จุฬาลงกรณ์มหาวิทยาลัย อันดับ 6​ นางสาวศิริกาญจน์ วิโรจน์ศิริ จากโรงรียนสามเสนวิทยาลัย ได้คะแนน 83.75 สอบได้คณะสถาปัตยกรรมศาสตร์ จุฬาลงกรณ์มหาวิทยาลัย อันดับ 7 นายชนภัสส์ แสงสว่าง จากโรงเรียนสาธิต จุฬาลงกรณ์มหาวิทยาลัย ได้คะแนน 83.09 สอบได้คณะทันตแพทยศาสตร์ จุฬาลงกรณ์มหาวิทยาลัย อันดับ 8 นายมัคค์ วรสถิตย์ จากโรงเรียนเตรียมอุดมศึกษา ได้คะแนน 82.93 สอบได้คณะเศรษฐศาตร์ จุฬาลงกรณ์มหาวิทยาลัย และอันดับ 9 นางสาวนันทพัชร พนมยงค์ จากโรงเรียนสตรีวิทยา ได้คะแนน 82.02 สอบได้คณะพาณิชยศาสตร์และการบัญชี มหาวิทยาลัยธรรมศาสตร์', 'TH: ด้านผู้พิการทางสายตาที่ผ่านการสอบคัดเลือกในระบบกลางแอดมิชช่ั่น ปี 2555 มีจำนวน 2 คนได้แก่ 1. นายณัฐพนธ์ มูลมาตย์ จากโรงเรียนเซนต์คาเบรียล สอบได้คณะครุศาสตร์ มรภ.บ้านสมเด็จเจ้าพระยา 2. นายไพโรจน์ พันธุ์ทอง จากโรงเรียนหาดใหญ่วิทยาลัย สอบได้คณะมนุษยศาสตร์และสังคมศาสตร์ มรภ.บ้านสมเด็จเจ้าพระยา ขณะที่คณะ/สาขาที่มีผู้สมัครมากที่สุด 20 อันดับแรก สำหรับแอดมิชชั่นปี 2555 อันดับ 1 ได้แก่ วิทยาลัยพยาบาลตำรวจ วิทยาลัยพยาบาลตำรวจ จำนวนที่รับได้ 56 คน มีผู้สมัคร 2,850 คน คิดเป็นอัตราส่วน 1:51', 'TH: ด้านนายสมคิด เลิศไพฑูรย์ อธิการบดีมหาวิทยาลัยธรรมศาสตร์ (มธ.) ในฐานะประธานที่ประชุมอธิการบดีแห่งประเทศไทย (ทปอ.) และนายกสมาคมอธิการบดีแห่งประเทศไทย (สอท.) กล่าวด้วยว่า การประกาศผลทางเว็บไซต์นั้น จะมีข้อมูล ชื่อ-นามสกุล เลขที่สมัคร และรหัสคณะที่ผ่านการคัดเลือก แต่จะไม่มีข้อมูลสถานที่สอบสัมภาษณ์ วันและเวลาการสอบสัมภาษณ์ ดังนั้น เมื่อนักเรียนทราบผลการคัดเลือกแล้ว ให้นักเรียนจรวจสอบสถานที่ วัน และเวลาการสอบสัมภาษณ์ทางเว็บไซต์ของสมาคมอธิการบดีแห่งประเทศไทย และขอให้นักเรียนเดินทางไปสอบสัมภาษณ์ให้ตรงตามเวลา วันที่ และสถานที่ที่มหาวิทยาลัยกำหนดไว้ระหว่างวันที่ 14-16 พฤษภาคม 2555.', 'TR: Sivas’ta iki otomobilin çarpışması sonucu meydana gelen kazada 2 kişi yaralandı.', 'TR: Kazada çarpışmanın etkisi ile araçlardan birinin ortadan ikiye bölünmesi görenleri şaşırttı.', 'TR: Kaza, bugün sabah saatlerinde Şeyhşamil Mahallesi Türkmenistan Caddesi üzerindeki kavşakta meydana geldi.', 'TR: 20 yaşındaki Abdulmuttalip Öztürk yönetimindeki 58 NU 269 plakalı otomobil ile 19 yaşındaki Ömer Akpolat yönetimindeki 58 FE 554 plakalı otomobil aşırı hız nedeniyle çarpıştı.', 'TR: Çarpışmanın etkisiyle Ömer Akpolat yönetimindeki otomobil ikiye bölünerek savruldu.', 'TR: Akpolat ise otomobilin ikiye bölünmesi ile yola fırladı.', ); $heuristics = array( 'CharsHeuristic', 'LowercaseCharsHeuristic', 'WordCharsHeuristic', 'LowercaseWordCharsHeuristic', 'WordChunkHeuristic', 'LowercaseWordChunkHeuristic', 'WordHeuristic', 'LowercaseWordHeuristic' ); $stats = array(); $tmpfile = '/tmp/tmp.db'; foreach($heuristics as $heuristic){ print $heuristic."\n"; $stats[$heuristic] = array(); @unlink($tmpfile); $fi = new FuzzyIndex($tmpfile); $fi->setHeuristic($heuristic); $t1 = microtime(true); load_sentences($fi, $sentences); $t2 = microtime(true); $diff = $t2-$t1; $stats[$heuristic]['loadtime'] = $diff; $stats[$heuristic]['dbsize'] = filesize($tmpfile); $snippets = $fi->getHeuristic()->makeSnippets($sentences[3]); $stats[$heuristic]['snippets'] = implode(' ', $snippets); $t1 = microtime(true); $hits = lookupList($fi, $sentences); $t2 = microtime(true); $diff = $t2-$t1; $stats[$heuristic]['lookuptime'] = $diff; $stats[$heuristic]['combinedscore'] = getCombinedScore($hits); //exit; } print "heuristic \t loadtime (s) \t dbsize (KB) \t lookup 32 items (s) \t avg score (%)".$sentences[3]."\n"; foreach($stats as $key=>$info){ print $key."\t".round($info['loadtime'], 2)."\t".round($info['dbsize']/1000.0, 2)."\t".round($info['lookuptime'], 2)."\t".$info['combinedscore']."\t".$info['snippets']." \n"; } function load_sentences(&$fi, $sentences){ foreach($sentences as $s){ $string = substr($s, 4);//chop off language id $fi->insert_string($string, $s); } } function getCombinedScore($hits){ $num = count($hits); $sum=0; foreach($hits as $hit){ if ( is_string($hit)){ $parts = explode(' | ', $hit); if ( isset($parts[2])){ $sum += $parts[2]; } } } return round($sum*1.0/$num, 2); } function lookupList($fi, $list){ $besthits = array(); foreach($list as $item){ $item = substr($item, 0, 10).'EDIT'.substr($item, 10); // fuzzify //print "looking up $item\n"; $besthits[] = lookupItem($fi, $item); //print_r($besthits); } return $besthits; } function lookupItem($fi, $item){ //print "looking up item: $item\n"; $bestlocations = $fi->get_best_locations($item); $numloc = count($bestlocations); if ( $numloc && $numloc > 0 ){ $firstitem = array_shift($bestlocations); return $firstitem; // location, score //print $firstitem."\n"; } return array('', 0); //else{ //print "no match found\n"; //} //var_dump($bestlocations); } ?>