Services_Yahoo_JP
[ class tree: Services_Yahoo_JP ] [ index: Services_Yahoo_JP ] [ all elements ]

Source for file AbstractMA.php

Documentation is available at AbstractMA.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Abstract MA class
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to the New BSD license that is
  10.  * available through the world-wide-web at the following URI:
  11.  * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
  12.  * a copy of the New BSD License and are unable to obtain it through the web,
  13.  * please send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category  Services
  16.  * @package   Services_Yahoo_JP
  17.  * @author    Tetsuya Nakase <phpizer@gmail.com>
  18.  * @copyright 2008 Tetsuya Nakase
  19.  * @license   http://www.opensource.org/licenses/bsd-license.php BSD
  20.  * @version   CVS: $Id: AbstractMA.php,v 1.1 2008/04/28 15:59:30 tetsuya Exp $
  21.  * @link      http://pear.php.net/package/Services_Yahoo
  22.  */
  23.  
  24. require_once 'Services/Yahoo/JP/MA/Response.php';
  25. require_once 'HTTP/Request.php';
  26.  
  27. /**
  28.  * Abstract MA class
  29.  *
  30.  * This abstract class serves as the base class for all different
  31.  * types of categories that available through Services_Yahoo.
  32.  *
  33.  * @category  Services
  34.  * @package   Services_Yahoo_JP
  35.  * @author    Tetsuya Nakase <phpizer@gmail.com>
  36.  * @copyright 2008 Tetsuya Nakase
  37.  * @license   http://www.opensource.org/licenses/bsd-license.php BSD
  38.  * @version   Release: 0.0.1
  39.  * @link      http://phpize.net
  40.  */
  41. {
  42.     /**
  43.      * parameter
  44.      *
  45.      * @access protected
  46.      * @var    array 
  47.      */
  48.     protected $parameters = array('appid' => 'PEAR_Services_Y_JP');
  49.  
  50.     /**
  51.      * Submits the MA
  52.      *
  53.      * This method submits the MA and handles the response.  It
  54.      * returns an instance of Services_Yahoo_Result which may be used
  55.      * to further make use of the result.
  56.      *
  57.      * @return object Services_Yahoo_Response MA result
  58.      * @throws Services_Yahoo_Exception
  59.      */
  60.     public function submit()
  61.     {
  62.         $url $this->requestURL '?';
  63.  
  64.         foreach ($this->parameters as $key => $value{
  65.             if (is_array($value)) {
  66.                 foreach ($value as $value2{
  67.                     $url .= $key '=' urlencode($value2'&';
  68.                 }
  69.                 continue;
  70.             }
  71.  
  72.             $url .= $key '=' urlencode($value'&';
  73.         }
  74.  
  75.         $request = new HTTP_Request($url);
  76.  
  77.         $result $request->sendRequest();
  78.         if (PEAR::isError($result)) {
  79.             throw new Services_Yahoo_Exception($result->getMessage());
  80.         }
  81.  
  82.         return new Services_Yahoo_JP_MA_Response($request);
  83.     }
  84.  
  85.     /**
  86.      * Set Application ID
  87.      *
  88.      * An Application ID is a string that uniquely identifies your
  89.      * application. Think of it as like a User-Agent string. If you
  90.      * have multiple applications, you should use a different ID for
  91.      * each one. You can register your ID and make sure nobody is
  92.      * already using your ID on Yahoo's Application ID registration
  93.      * page.
  94.      *
  95.      * The ID defaults to "PEAR_Services_Y_JP", but you are free to
  96.      * change it to whatever you want.  Please note that the access
  97.      * to the Yahoo API is not limited via the Application ID but via
  98.      * the IP address of the host where the package is used.
  99.      *
  100.      * @param string $id Application ID
  101.      *
  102.      * @return void 
  103.      */
  104.     public function withAppID($id)
  105.     {
  106.         $this->parameters['appid'$id;
  107.     }
  108.  
  109.     /**
  110.      * Returns an element from the parameters
  111.      *
  112.      * @param string $name Name of the element
  113.      *
  114.      * @return string Value of the parameter
  115.      */
  116.     protected function getParameter($name)
  117.     {
  118.         if (isset($this->parameters[$name])) {
  119.             return $this->parameters[$name];
  120.         }
  121.  
  122.         return '';
  123.     }
  124.  
  125.     /**
  126.      * Set the Sentence
  127.      *
  128.      * @param string $sentence for Morphological Analysis
  129.      *
  130.      * @return void 
  131.      */
  132.     public function setSentence($sentence)
  133.     {
  134.         $this->parameters['sentence'$sentence;
  135.     }
  136.  
  137.     /**
  138.      * Set the type of result
  139.      *
  140.      * @param string $results type 'ma' or 'uniq'
  141.      *
  142.      * @return void 
  143.      */
  144.     public function setResults($results)
  145.     {
  146.         /* ma is default */
  147.         $this->parameters['results'$results === 'uniq''uniq' 'ma';
  148.     }
  149.  
  150.     /**
  151.      * Set the response field
  152.      *
  153.      * @param string $response field
  154.      *
  155.      * @return void 
  156.      */
  157.     public function setResponse($response)
  158.     {
  159.         $this->parameters['response'$response;
  160.     }
  161.  
  162.     /**
  163.      * Set the ma response field
  164.      *
  165.      * @param string $maresponse type of response
  166.      *
  167.      * @return void 
  168.      */
  169.     public function setMAResponse($maresponse)
  170.     {
  171.         $this->parameters['ma_response'$maresponse;
  172.     }
  173.  
  174.     /**
  175.      * Set the uniq response field
  176.      *
  177.      * @param string $uniqresponse tyep of response
  178.      *
  179.      * @return void 
  180.      */
  181.     public function setUniqResponse($uniqresponse)
  182.     {
  183.         $this->parameters['uniq_response'$uniqresponse;
  184.     }
  185.  
  186.     /**
  187.      * Set the filter
  188.      *
  189.      * @param string $filter filter type
  190.      *
  191.      * @return void 
  192.      */
  193.     public function setFileter($filter)
  194.     {
  195.         $this->parameters['filter'$filter;
  196.     }
  197.  
  198.     /**
  199.      * Set the MA filter
  200.      *
  201.      * @param string $mafilter ma filter type
  202.      *
  203.      * @return void 
  204.      */
  205.     public function setMAFileter($mafilter)
  206.     {
  207.         $this->parameters['ma_filter'$mafilter;
  208.     }
  209.  
  210.     /**
  211.      * Set the UNIQ filter
  212.      *
  213.      * @param string $uniqfilter uniq filter type
  214.      *
  215.      * @return void 
  216.      */
  217.     public function setUniqFileter($uniqfilter)
  218.     {
  219.         $this->parameters['uniq_filter'$uniqfilter;
  220.     }
  221.  
  222.     /**
  223.      * Set the Uniq_by_baseform
  224.      *
  225.      * @param string $ubbf uniq filter
  226.      *
  227.      * @return void 
  228.      */
  229.     public function setUniqByBaseform($ubbf)
  230.     {
  231.         $this->parameters['uniq_by_baseform'$ubbf;
  232.     }
  233. }
  234. ?>

Documentation generated on Fri, 19 Sep 2008 21:30:04 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.