SlideShare a Scribd company logo
1 of 4
Download to read offline
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>

More Related Content

What's hot

Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
brian d foy
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
elliando dias
 
Document
DocumentDocument
Document
viwviw
 

What's hot (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
 

Viewers also liked (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 to C A S Sample Php

Php code for online quiz
Php code for online quizPhp code for online quiz
Php code for online quiz
hnyb1002
 
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
Masahiro Nagano
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
Hung-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 about
Tatsuhiko Miyagawa
 

Similar to 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
 

More from 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>