dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve some of the descriptions added in r68482
[lhc/web/wiklou.git]
/
includes
/
ZhClient.php
diff --git
a/includes/ZhClient.php
b/includes/ZhClient.php
index
0451ce8
..
a04220c
100644
(file)
--- a/
includes/ZhClient.php
+++ b/
includes/ZhClient.php
@@
-1,12
+1,8
@@
<?php
<?php
-/**
- * @package MediaWiki
- */
/**
* Client for querying zhdaemon
*
/**
* Client for querying zhdaemon
*
- * @package MediaWiki
*/
class ZhClient {
var $mHost, $mPort, $mFP, $mConnected;
*/
class ZhClient {
var $mHost, $mPort, $mFP, $mConnected;
@@
-16,7
+12,7
@@
class ZhClient {
*
* @access private
*/
*
* @access private
*/
- function
ZhClien
t($host, $port) {
+ function
__construc
t($host, $port) {
$this->mHost = $host;
$this->mPort = $port;
$this->mConnected = $this->connect();
$this->mHost = $host;
$this->mPort = $port;
$this->mConnected = $this->connect();
@@
-24,8
+20,6
@@
class ZhClient {
/**
* Check if connection to zhdaemon is successful
/**
* Check if connection to zhdaemon is successful
- *
- * @access public
*/
function isconnected() {
return $this->mConnected;
*/
function isconnected() {
return $this->mConnected;
@@
-38,9
+32,10
@@
class ZhClient {
*/
function connect() {
wfSuppressWarnings();
*/
function connect() {
wfSuppressWarnings();
+ $errno = $errstr = '';
$this->mFP = fsockopen($this->mHost, $this->mPort, $errno, $errstr, 30);
wfRestoreWarnings();
$this->mFP = fsockopen($this->mHost, $this->mPort, $errno, $errstr, 30);
wfRestoreWarnings();
- if
(!$this->mFP
) {
+ if
( !$this->mFP
) {
return false;
}
return true;
return false;
}
return true;
@@
-52,8
+47,9
@@
class ZhClient {
* @access private
*/
function query($request) {
* @access private
*/
function query($request) {
- if
(!$this->mConnected)
+ if
( !$this->mConnected ) {
return false;
return false;
+ }
fwrite($this->mFP, $request);
fwrite($this->mFP, $request);
@@
-73,41
+69,42
@@
class ZhClient {
$data .= $str;
}
//data should be of length $len. otherwise something is wrong
$data .= $str;
}
//data should be of length $len. otherwise something is wrong
- if
(strlen($data) != $len)
+ if
( strlen($data) != $len ) {
return false;
return false;
+ }
return $data;
}
/**
* Convert the input to a different language variant
*
return $data;
}
/**
* Convert the input to a different language variant
*
- * @param
string $text
input text
- * @param
string $tolang
language variant
+ * @param
$text string:
input text
+ * @param
$tolang string:
language variant
* @return string the converted text
* @return string the converted text
- * @access public
*/
function convert($text, $tolang) {
$len = strlen($text);
$q = "CONV $tolang $len\n$text";
$result = $this->query($q);
*/
function convert($text, $tolang) {
$len = strlen($text);
$q = "CONV $tolang $len\n$text";
$result = $this->query($q);
- if
(!$result)
+ if
( !$result ) {
$result = $text;
$result = $text;
+ }
return $result;
}
/**
* Convert the input to all possible variants
*
return $result;
}
/**
* Convert the input to all possible variants
*
- * @param
string $text
input text
+ * @param
$text string:
input text
* @return array langcode => converted_string
* @return array langcode => converted_string
- * @access public
*/
function convertToAllVariants($text) {
$len = strlen($text);
$q = "CONV ALL $len\n$text";
$result = $this->query($q);
*/
function convertToAllVariants($text) {
$len = strlen($text);
$q = "CONV ALL $len\n$text";
$result = $this->query($q);
- if
(!$result)
+ if
( !$result ) {
return false;
return false;
+ }
list($infoline, $data) = explode('|', $result, 2);
$info = explode(";", $infoline);
$ret = array();
list($infoline, $data) = explode('|', $result, 2);
$info = explode(";", $infoline);
$ret = array();
@@
-115,7
+112,6
@@
class ZhClient {
foreach($info as $variant) {
list($code, $len) = explode(' ', $variant);
$ret[strtolower($code)] = substr($data, $i, $len);
foreach($info as $variant) {
list($code, $len) = explode(' ', $variant);
$ret[strtolower($code)] = substr($data, $i, $len);
- $r = $ret[strtolower($code)];
$i+=$len;
}
return $ret;
$i+=$len;
}
return $ret;
@@
-123,27
+119,23
@@
class ZhClient {
/**
* Perform word segmentation
*
/**
* Perform word segmentation
*
- * @param
string $text
input text
+ * @param
$text string:
input text
* @return string segmented text
* @return string segmented text
- * @access public
*/
function segment($text) {
$len = strlen($text);
$q = "SEG $len\n$text";
$result = $this->query($q);
*/
function segment($text) {
$len = strlen($text);
$q = "SEG $len\n$text";
$result = $this->query($q);
- if
(!$result
) {// fallback to character based segmentation
- $result =
ZhClientFake::
segment($text);
+ if
( !$result
) {// fallback to character based segmentation
+ $result =
$this->
segment($text);
}
return $result;
}
/**
* Close the connection
}
return $result;
}
/**
* Close the connection
- *
- * @access public
*/
function close() {
fclose($this->mFP);
}
}
*/
function close() {
fclose($this->mFP);
}
}
-?>
\ No newline at end of file