SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
index.php:

<?php
/* Sample Code for Y! CAS Open API
 *
 * Author: Chloris Kuo    菲芳郭
 * 2009/10/17    Y! Open Hack TW 2009
 */

  if(!isset($content))   $content = $_GET['c'];
  echo <<<END
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<meta http-equiv='Content-Language' content='zh-TW'>
<TITLE>CAS demo</TITLE>
<FRAMESET COLS='50%,50%'>
<FRAME NAME='left' SRC="left.php?content=$content">
<FRAME NAME='right' SRC="test.php?content=$content">
</FRAMESET>
END;
?>



left.php:

<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
</head>


<body>
<center>
<form action="test.php"    method="POST" target="right">
&nbsp
<h2>CAS Demo</h2>
<p>
<TEXTAREA rows="20" cols="50" name="content">
肉豬凍冷良優是我哈哈
</TEXTAREA>
&nbsp
<p>
method:<select name="method" onchange="this.form.submit();">
<option value="ws" selected>Word Segmentation</option>
<option value="ke">Keyword Extraction</option>
</select>


<p>
<p>
<input type="submit" value="SUBMIT">
<input type="reset" value="RESET">
</form>
</body>
</html>


test.php:

<html>
<head></head>
<body>
<center>
<?php
/* Sample Code for Y! CAS Open API
 *
 * Author: Chloris Kuo    菲芳郭
 * 2009/10/17     Y! Open Hack TW 2009
 */


      $appid = ''; // Your appid here
      $casapi= 'http://asia.search.yahooapis.com/cas/v1/';


      $content = $_POST['content'];
      $method = $_POST['method'];

      $url = $casapi.$method;


      //echo "method: $method, content: $content, url: $url <p>";
$data = array('appid' => $appid, 'content' => $content);


$color = array(
  'ADVERB'=>'00CC00',
     'PRONOUN'=>'00CCCC',
     'VERB'=>'CC0033',
     'NOUN_VERBAL'=>'CC33FF',
     'NOUN'=>'FF6600',
     'PROPER_NOUN'=>'9933CC',
     'PREPOSITION'=>'3399CC',
     'NUMERAL'=>'FF99FF',
     'NOUN_TIME'=>'00CC66',
     'QUANTIFIER'=>'6600FF',
     'POSTPOSITION'=>'6666CC',
     'ADJECTIVE'=> '009999',
     'CONJUNCTION'=>'CC9933',
     'PARTICLE'=>'FF00FF',
     'DETERMINER'=>'333300',
);


$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_TIMEOUT, _DCP_TIMEOUT_);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($curl);
curl_close($curl);


$parser = xml_parser_create("UTF-8");
xml_parse_into_struct($parser, $result, $XML, $index);
xml_parser_free($parser);
//var_dump($result);
if($method == 'ws'){
   echo "&nbsp<p><h2>Segmentation Result</h2>";
     echo "<table border=0 width=90%><tr><td>";
foreach($index as $key=>$val){
            if($key == "TOKEN"){
                 foreach($val as $i => $idx){
                    $pos = $XML[$idx+4]['value'];
                  // echo "'$pos':";
                     if($pos != '' && $pos != null){
                        if($pos == 'NOUN'){
                           echo "<u>";
                         }
                         echo "<font color=#".$color[$pos].">";
                         echo $XML[$idx]['value']."</font>";
                         //echo "<font size='8pt'>".$pos."&nbsp;&nbsp;</font>";
                         if($pos == 'NOUN'){
                            echo "</u>";
                         }
                         echo "&nbsp;";
                     }
                 }
             }
         }
         echo "</td></tr></table>";
     }
     else{
        echo "&nbsp<p><h2>Keyword Extraction Result</h2>&nbsp<p>";
         foreach($index as $key=>$val){
             if($key == "TOKEN"){
                 foreach($val as $i => $idx){
                    $score = $XML[$idx+1]['value'];
                     echo $XML[$idx]['value']."&nbsp;Score:$score<br>";
                 }
             }
         }
         //var_dump($result);
     }
?>
</body>
</html>

Más contenido relacionado

La actualidad más candente

Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trialbrian d foy
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directorisfrankiejol
 
DEV Čtvrtkon #76 - Fluent Interface
DEV Čtvrtkon #76 - Fluent InterfaceDEV Čtvrtkon #76 - Fluent Interface
DEV Čtvrtkon #76 - Fluent InterfaceCtvrtkoncz
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysNicholas Dionysopoulos
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui documentRazvan Raducanu, PhD
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Document
DocumentDocument
Documentviwviw
 
Not Really PHP by the book
Not Really PHP by the bookNot Really PHP by the book
Not Really PHP by the bookRyan Kilfedder
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
 
TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !Matheus Marabesi
 

La actualidad más candente (19)

5. hello popescu
5. hello popescu5. hello popescu
5. hello popescu
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directoris
 
DEV Čtvrtkon #76 - Fluent Interface
DEV Čtvrtkon #76 - Fluent InterfaceDEV Čtvrtkon #76 - Fluent Interface
DEV Čtvrtkon #76 - Fluent Interface
 
Php
PhpPhp
Php
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Hidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeysHidden in plain site – joomla! hidden secrets for code monkeys
Hidden in plain site – joomla! hidden secrets for code monkeys
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
M.php
M.phpM.php
M.php
 
6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document6. Php MongoDB adaugarea unui document
6. Php MongoDB adaugarea unui document
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Document
DocumentDocument
Document
 
Not Really PHP by the book
Not Really PHP by the bookNot Really PHP by the book
Not Really PHP by the book
 
TICT #13
TICT #13TICT #13
TICT #13
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !TDC2015 Porto Alegre - Automate everything with Phing !
TDC2015 Porto Alegre - Automate everything with Phing !
 
TICT #11
TICT #11 TICT #11
TICT #11
 

Destacado

2009 Hackday Taiwan Yui
2009 Hackday Taiwan Yui2009 Hackday Taiwan Yui
2009 Hackday Taiwan YuiJH Lee
 
Tw Mail Open Hack Day 1
Tw Mail Open Hack Day 1Tw Mail Open Hack Day 1
Tw Mail Open Hack Day 1JH Lee
 
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017JH Lee
 
Tw Mail Open Hack Day 2
Tw Mail Open Hack Day 2Tw Mail Open Hack Day 2
Tw Mail Open Hack Day 2JH Lee
 
Y Boss External 20091017
Y Boss External 20091017Y Boss External 20091017
Y Boss External 20091017JH Lee
 
Search Monkey
Search MonkeySearch Monkey
Search MonkeyJH Lee
 

Destacado (6)

2009 Hackday Taiwan Yui
2009 Hackday Taiwan Yui2009 Hackday Taiwan Yui
2009 Hackday Taiwan Yui
 
Tw Mail Open Hack Day 1
Tw Mail Open Hack Day 1Tw Mail Open Hack Day 1
Tw Mail Open Hack Day 1
 
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017
K+ Open Api For 2009 Yahoo! Open Hack Day By Sc@20091017
 
Tw Mail Open Hack Day 2
Tw Mail Open Hack Day 2Tw Mail Open Hack Day 2
Tw Mail Open Hack Day 2
 
Y Boss External 20091017
Y Boss External 20091017Y Boss External 20091017
Y Boss External 20091017
 
Search Monkey
Search MonkeySearch Monkey
Search Monkey
 

Similar a C A S Sample Php

8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会Yusuke Ando
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with ExtbaseJochen Rau
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quizhnyb1002
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?Radek Benkel
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.jsWebsecurify
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介純生 野田
 

Similar a C A S Sample Php (20)

Php
PhpPhp
Php
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会8時間耐久CakePHP2 勉強会
8時間耐久CakePHP2 勉強会
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?[PL] Jak nie zostać "programistą" PHP?
[PL] Jak nie zostać "programistą" PHP?
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
Php functions
Php functionsPhp functions
Php functions
 
Daily notes
Daily notesDaily notes
Daily notes
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
My shell
My shellMy shell
My shell
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介次世代版 PowerCMS 開発プロジェクトのご紹介
次世代版 PowerCMS 開発プロジェクトのご紹介
 
PowerCMS X
PowerCMS XPowerCMS X
PowerCMS X
 
Php 101: PDO
Php 101: PDOPhp 101: PDO
Php 101: PDO
 

Más de JH Lee

Cas Open Api 2009 Hack Day
Cas Open Api 2009 Hack DayCas Open Api 2009 Hack Day
Cas Open Api 2009 Hack DayJH Lee
 
2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api2009 Tw Oh Wretch Api
2009 Tw Oh Wretch ApiJH Lee
 
Yql V8
Yql V8Yql V8
Yql V8JH Lee
 
Erikeldridge Yos V9
Erikeldridge Yos V9Erikeldridge Yos V9
Erikeldridge Yos V9JH Lee
 
TWOHD_Search Monkey
TWOHD_Search MonkeyTWOHD_Search Monkey
TWOHD_Search MonkeyJH Lee
 
TWOHD_Wretch API
TWOHD_Wretch APITWOHD_Wretch API
TWOHD_Wretch APIJH Lee
 
TWOHD_K+ API
TWOHD_K+ APITWOHD_K+ API
TWOHD_K+ APIJH Lee
 
TWOHD_Blueprint
TWOHD_BlueprintTWOHD_Blueprint
TWOHD_BlueprintJH Lee
 

Más de JH Lee (8)

Cas Open Api 2009 Hack Day
Cas Open Api 2009 Hack DayCas Open Api 2009 Hack Day
Cas Open Api 2009 Hack Day
 
2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api2009 Tw Oh Wretch Api
2009 Tw Oh Wretch Api
 
Yql V8
Yql V8Yql V8
Yql V8
 
Erikeldridge Yos V9
Erikeldridge Yos V9Erikeldridge Yos V9
Erikeldridge Yos V9
 
TWOHD_Search Monkey
TWOHD_Search MonkeyTWOHD_Search Monkey
TWOHD_Search Monkey
 
TWOHD_Wretch API
TWOHD_Wretch APITWOHD_Wretch API
TWOHD_Wretch API
 
TWOHD_K+ API
TWOHD_K+ APITWOHD_K+ API
TWOHD_K+ API
 
TWOHD_Blueprint
TWOHD_BlueprintTWOHD_Blueprint
TWOHD_Blueprint
 

C A S Sample Php

  • 1. index.php: <?php /* Sample Code for Y! CAS Open API * * Author: Chloris Kuo 菲芳郭 * 2009/10/17 Y! Open Hack TW 2009 */ if(!isset($content)) $content = $_GET['c']; echo <<<END <meta http-equiv='Content-Type' content='text/html;charset=utf-8'> <meta http-equiv='Content-Language' content='zh-TW'> <TITLE>CAS demo</TITLE> <FRAMESET COLS='50%,50%'> <FRAME NAME='left' SRC="left.php?content=$content"> <FRAME NAME='right' SRC="test.php?content=$content"> </FRAMESET> END; ?> left.php: <html> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> </head> <body> <center> <form action="test.php" method="POST" target="right"> &nbsp <h2>CAS Demo</h2> <p> <TEXTAREA rows="20" cols="50" name="content"> 肉豬凍冷良優是我哈哈 </TEXTAREA>
  • 2. &nbsp <p> method:<select name="method" onchange="this.form.submit();"> <option value="ws" selected>Word Segmentation</option> <option value="ke">Keyword Extraction</option> </select> <p> <p> <input type="submit" value="SUBMIT"> <input type="reset" value="RESET"> </form> </body> </html> test.php: <html> <head></head> <body> <center> <?php /* Sample Code for Y! CAS Open API * * Author: Chloris Kuo 菲芳郭 * 2009/10/17 Y! Open Hack TW 2009 */ $appid = ''; // Your appid here $casapi= 'http://asia.search.yahooapis.com/cas/v1/'; $content = $_POST['content']; $method = $_POST['method']; $url = $casapi.$method; //echo "method: $method, content: $content, url: $url <p>";
  • 3. $data = array('appid' => $appid, 'content' => $content); $color = array( 'ADVERB'=>'00CC00', 'PRONOUN'=>'00CCCC', 'VERB'=>'CC0033', 'NOUN_VERBAL'=>'CC33FF', 'NOUN'=>'FF6600', 'PROPER_NOUN'=>'9933CC', 'PREPOSITION'=>'3399CC', 'NUMERAL'=>'FF99FF', 'NOUN_TIME'=>'00CC66', 'QUANTIFIER'=>'6600FF', 'POSTPOSITION'=>'6666CC', 'ADJECTIVE'=> '009999', 'CONJUNCTION'=>'CC9933', 'PARTICLE'=>'FF00FF', 'DETERMINER'=>'333300', ); $curl = curl_init($url); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_TIMEOUT, _DCP_TIMEOUT_); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $result = curl_exec($curl); curl_close($curl); $parser = xml_parser_create("UTF-8"); xml_parse_into_struct($parser, $result, $XML, $index); xml_parser_free($parser); //var_dump($result); if($method == 'ws'){ echo "&nbsp<p><h2>Segmentation Result</h2>"; echo "<table border=0 width=90%><tr><td>";
  • 4. foreach($index as $key=>$val){ if($key == "TOKEN"){ foreach($val as $i => $idx){ $pos = $XML[$idx+4]['value']; // echo "'$pos':"; if($pos != '' && $pos != null){ if($pos == 'NOUN'){ echo "<u>"; } echo "<font color=#".$color[$pos].">"; echo $XML[$idx]['value']."</font>"; //echo "<font size='8pt'>".$pos."&nbsp;&nbsp;</font>"; if($pos == 'NOUN'){ echo "</u>"; } echo "&nbsp;"; } } } } echo "</td></tr></table>"; } else{ echo "&nbsp<p><h2>Keyword Extraction Result</h2>&nbsp<p>"; foreach($index as $key=>$val){ if($key == "TOKEN"){ foreach($val as $i => $idx){ $score = $XML[$idx+1]['value']; echo $XML[$idx]['value']."&nbsp;Score:$score<br>"; } } } //var_dump($result); } ?> </body> </html>