<?php
Class Segmentation {
var $options = array (' lowercase ' => TRUE,
' Segment_english ' => FALSE);
var $dict _name = ' Unknown ';
var $dict _words = Array ();
function Setlowercase ($value) {
if ($value) {
$this->options[' lowercase '] = TRUE;
} else {
$this->options[' lowercase '] = FALSE;
}
return TRUE;
}
function Setsegmentenglish ($value) {
if ($value) {
$this->options[' segment_english '] = TRUE;
} else {
$this->options[' segment_english '] = FALSE;
}
return TRUE;
}
function load ($dict _file) {
if (!file_exists ($dict _file)) {
return FALSE;
}
$fp = fopen ($dict _file, ' R ');
$temp = fgets ($fp, 1024);
if ($temp = = FALSE) {
return FALSE;
} else {
if (Strpos ($temp, "T")!== FALSE) {
List ($dict _type, $dict _name) = Explode ("T", trim ($temp));
} else {
$dict _type = Trim ($temp);
$dict _name = ' Unknown ';
}
$this->dict_name = $dict _name;
if ($dict _type!== ' Dict_word_w ') {
return FALSE;
}
}
while (!feof ($fp)) {
$this->dict_words[rtrim (Fgets ($FP, 32))] = 1;
}
Fclose ($FP);
return TRUE;
}
function Getdictname () {
return $this->dict_name;
}
function segmentstring ($STR) {
if (count ($this->dict_words) = = 0) {
return FALSE;
}
$lines = Explode ("n", $str);
return $this->_segmentlines ($lines);
}
function Segmentfile ($filename) {
if (count ($this->dict_words) = = 0) {
return FALSE;
}
$lines = file ($filename);
return $this->_segmentlines ($lines);
}
function _segmentlines ($lines) {
$contents _segmented = ';
foreach ($lines as $line) {
$contents _segmented. = $this->_segmentline (RTrim ($line)). "N";
}
do {
$contents _segmented = Str_replace (', ', $contents _segmented);
while (Strpos ($contents _segmented, ')!== FALSE);
return $contents _segmented;? >