文で検索


/>WebMA />MECAPI
Search Keys [".implode("  ", $ws)."]"); YapiSearch($keys, 1, 20); } else { print("No Search Keys in [".$key."]"); } } else { print("文が入力されると、自動的に単語(名詞)だけ取り出し、それで検索します。"); } function WebmaWords($String){ $request = "http://jlp.yahooapis.jp/MAService/V1/parse?appid=THISISAPEN"; $request .= "&response=surface,pos&filter=9"; $request .= "&sentence=".urlencode($String); $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response, 'simple_xml_extended'); foreach ($parsed_xml->ma_result->word_list->word as $cur){ $words[] = $cur->surface; } return $words; } function MecapiWords($String){ $request = "http://mimitako.net/api/mecapi.cgi"; $request .= "?sentence=".urlencode($String); $request .= "&response=surface,count&filter=noun,uniq"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response, 'simple_xml_extended'); foreach ($parsed_xml->word as $cur){ $words[] = $cur->surface; } return $words; } function YapiSearch($Keywords, $Start, $Num){ $request = "http://search.yahooapis.jp/PremiumWebSearchService/V1/webSearch"; $request .= "?appid=7Zn3zoWxg66CnOswIYz1hO58Fk4MHDH24qZJ0_9b3XzGwHkZ2FJSRQoAjVIN4yU-&adult_ok=1&query=".urlencode($Keywords); $request .= "&start=".$Start."&results=".$Num; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response, 'simple_xml_extended'); printYapiSearchResults($parsed_xml); } class simple_xml_extended extends SimpleXMLElement { // ref. http://www.php.net/manual/ja/function.simplexml-load-string.php public function Attribute($name) { foreach($this->Attributes() as $key=>$val) { if($key == $name) return (string)$val; } } } function printYapiSearchResults($parsed_xml){ $rslt_total = $parsed_xml->Attribute('totalResultsAvailable'); $rslt_returned = $parsed_xml->Attribute('totalResultsReturned'); $rslt_first = $parsed_xml->Attribute('firstResultPosition'); print(" → Total Results : ".$rslt_total."
"); if ($rslt_returned > 0){ $count = 0; foreach ($parsed_xml->Result as $cur){ $count = 1 - $count; print("
" ."" ."
".$cur->Summary."
" ."
"); } } } ?>
Web Services by Yahoo! JAPAN / NLP by WebMA or MECAPI
b_entry.gif livedoor clip newsing it! Yahoo!ブックマークに登録