public static function getDAG($sentence, $options = array())
{
$defaults = array('mode' => 'default');
$options = array_merge($defaults, $options);
$N = mb_strlen($sentence, 'UTF-8');
$i = 0;
$j = 0;
$DAG = array();
$word_c = array();
while ($i < $N) {
$c = mb_substr($sentence, $j, 1, 'UTF-8');
if (count($word_c) == 0) {
$next_word_key = $c;
} else {
$next_word_key = implode('.', $word_c) . '.' . $c;
}
if (self::$trie->exists($next_word_key)) {
array_push($word_c, $c);
$next_word_key_value = self::$trie->get($next_word_key);
if ($next_word_key_value == array("end" => "") || isset($next_word_key_value["end"]) || isset($next_word_key_value[0]["end"])) {
if (!isset($DAG[$i])) {
$DAG[$i] = array();
}
array_push($DAG[$i], $j);
}
$j += 1;
if ($j >= $N) {
$word_c = array();
$i += 1;
$j = $i;
}
} else {
$word_c = array();
$i += 1;
$j = $i;
}
}
for ($i = 0; $i < $N; $i++) {
if (!isset($DAG[$i])) {
$DAG[$i] = array($i);
}
}
return $DAG;
}