function load() { $file = fopen(ConfPath::replyList($this->name), "r"); while ($line = fgets($file)) { $line = rtrim($line); $cells = mb_split(',', $line); $sample = array('from' => array_shift($cells), 'to' => array_shift($cells), 'dimension' => $cells); $this->list[] = $sample; } fclose($file); }
protected function initLearn() { if ($this->initialized) { return; } $this->state = new BlockState(); $this->state->loadMatrix(ConfPath::stateMatrix($this->name)); $this->state->loadText2id(ConfPath::stateTexts($this->name)); $this->keywords = KeywordsTable::singleton(); $this->keywords->loadTable(ConfPath::keywords()); $this->filter = new IpcaImage(); $this->filter->load_1Line1Element(ConfPath::keywordsFilter(), 0, 1); $this->ipca = Ipca::singleton(); $this->ipca->load(3); $this->initialized = true; }
private function scanReplies() { $keys = array_keys($this->threads); $loader = new TwitterLog(); foreach (glob(ConfPath::rawStatusList()) as $path) { $loader->open($path); while ($loader->read1Line()) { $info = $loader->getArray(); $id = $info['id']; if (in_array($id, $keys)) { $this->replyState->learn($this->pickupText($info['text']), $this->threads[$id]['to']); } } $loader->close(); } }
function mark(array $users) { $counters = array(); $in = fopen(ConfPath::statusList(), 'r'); $out = fopen(ConfPath::statusListMarked(), 'w'); while ($line = fgets($in)) { $line = rtrim($line); $cells = mb_split(',', $line); $uid = $cells[self::UID_COL]; if ($users[$uid]) { $line .= "," . $users[$uid]; $counters[$users[$uid]]++; } fwrite($out, $line . "\n"); } fclose($in); fclose($out); var_dump($counters); }
function save() { arsort($this->scores); $path = ConfPath::scoreUser($this->target); $file = fopen($path, "w"); $lsstText = ''; foreach ($this->scores as $tid => $score) { $info = $this->infos[$tid]; if ($lastText == $info['text']) { continue; } $lastText = $info['text']; $list = array(); foreach ($info as $key => $value) { $list[] = $key . "=" . $value; } fprintf($file, "score=%f,%s\n", $score, implode(",", $list)); } fclose($file); }
function loadReflect($target) { $path = ConfPath::reflectUser($target); if (!is_file($path)) { return null; } $fin = fopen($path, "r"); $reflect = array(); while ($line = fgets($fin)) { $cells = mb_split(",", $line); if (count($cells) != 2) { continue; } $reflect[(int) $cells[0]] = (double) $cells[1]; } fclose($fin); if (count($reflect) < self::ITEM_LENGTH / 2) { print "WARNING! reflect file.\n"; return null; } return $reflect; }
function load() { $this->state->loadMatrix(ConfPath::stateMatrix($this->name)); $this->state->loadText2id(ConfPath::stateTexts($this->name)); }
$max = 1; $min = 1; foreach ($this->m_Keywords->m_Table as $word => $record) { if ($this->isIgnored($record)) { continue; } $count = $record['count']; if ($max < $count) { $max = $count; } } foreach ($this->m_Keywords->m_Table as $word => $record) { if ($this->isIgnored($record)) { continue; } $index = $record['index']; $count = $record['count']; if (!$index || !$count) { continue; } $rate = log($max / $count) / log($max / $min); fprintf($f, "%d,%f,%s\n", $index, $rate, $word); } fclose($f); } } $keywords = KeywordsTable::singleton(); $keywords->loadTable(ConfPath::keywords()); $instance = new MakeFilter(array('Keywords' => $keywords)); $instance->run_idf(ConfPath::keywordsFilter()); print "WARN: Add special person value, like hajimehoshi, shokos etc.";
<?php require_once '../configure.php'; require_once CONF_DIR . 'path.php'; require_once INCLUDE_DIR . 'keywords/KeywordsTable.class.php'; require_once INCLUDE_DIR . 'twitter/twitter.class.php'; $table = KeywordsTable::singleton(); $loader = new TwitterLog(); foreach (glob(ConfPath::rawStatusList()) as $path) { $loader->open($path); while ($loader->read1Line()) { $info = $loader->getArrayPassedMecab(); $table->addRecordByMecab($info['mecab']); } $loader->close(); } $table->saveTable(ConfPath::keywords());
if (!is_array($mecab) || count($mecab) == 0) { return; } $numbers = array(); foreach ($mecab as $item) { if ($item['keyword']) { $numbers[] = $item['keyword']; } } fprintf($this->file, "%s,%d,%d,%s\n", $info['id'], $info['user_id'], $info['reply_to'], implode(",", $numbers)); } public function close() { fclose($this->file); } } $table = KeywordsTable::singleton(); $table->loadTable(ConfPath::keywords()); $loader = new TwitterLog(); $numbering = new Numbering(); $numbering->open(ConfPath::statusList()); foreach (glob(ConfPath::rawStatusList()) as $path) { $loader->open($path); while ($loader->read1Line()) { $info = $loader->getArrayPassedMecab(); $mecab = $table->addKeywordIntoMecabInfo($info['mecab']); $numbering->write1Line($info, $mecab); } $loader->close(); } $numbering->close();