コード例 #1
0
ファイル: JentiCrawler.php プロジェクト: lupaelma/jenti
 /**
  * Execute the word discovery process.
  *
  *    within a data source
  *      get words from word list that have not been acquired from source
  *      for each word
  *        get word definitions from source
  *        add word to database
  *        add more words to word list   
  * 
  * @param array $word_array optional list of words 
  */
 public function crawl($word_array = null)
 {
     // prepare for long processing time
     ini_set('default_socket_timeout', 36000);
     ini_set('max_execution_time', 36000);
     $jrequest = $this->create_request();
     $jword = new JentiWord($this->config);
     if ($word_array == null) {
         $word_array = $jword->get_words_without_definition($jrequest);
         if ($jword->error) {
             echo $jword->error;
             return;
         }
     }
     // send every message to the browser immediately
     ob_implicit_flush(TRUE);
     $this->log_open();
     $msg = get_class($this) . ": processing " . count($word_array) . " words from " . $jrequest->service_name;
     $this->echo_msg_flush($msg);
     foreach ($word_array as $word) {
         $word = trim($word);
         $dictionary_word_array = $jrequest->get_word($word);
         if ($jrequest->error) {
             $this->echo_msg_flush($jrequest->error);
         } else {
             foreach ($dictionary_word_array as $word_info) {
                 if ($this->config["save_words"] == true) {
                     $jword->add_word($word_info);
                 }
                 $word_info["ERROR_ARRAY"] = $jword->error_array;
                 $this->echo_word_info($word_info);
             }
         }
         if (count($dictionary_word_array) == 0) {
             // data source cannot provide this word
             $avoid_info["WORD"] = $word;
             $avoid_info["LANGUAGE_CODE"] = $jrequest->language_code;
             $avoid_info["SOURCE_NAME"] = $jrequest->service_name;
             $jword->update_word_list_word($avoid_info);
             if ($jword->error) {
                 $this->echo_msg_flush($jword->error);
             }
         }
     }
     $this->log_close();
     ob_implicit_flush(FALSE);
 }
コード例 #2
0
ファイル: JentiSession.php プロジェクト: lupaelma/jenti
 /**
  * Save user feedback.
  * 
  * @param array $feedback_info the feedback information
  */
 public function save_user_feedback($feedback_info)
 {
     if (isset($feedback_info["LIKE"])) {
         $word = new JentiWord($this->config);
         if (!$word->error) {
             $word->update_likes($feedback_info);
         }
         $this->error = $word->error;
     }
     if (!$this->error && isset($feedback_info["FEEDBACK"])) {
         $user = new JentiUser($this->config);
         if (!$user->error) {
             $feedback_info["TYPE"] = ACTIVITY_FEEDBACK;
             if ($this->is_user_authenticated()) {
                 $feedback_info["EMAIL"] = $this->email;
             }
             $user->add_user_activity($feedback_info);
         }
         $this->error = $user->error;
     }
 }
コード例 #3
0
ファイル: JentiWordTest.php プロジェクト: lupaelma/jenti
<?php

require_once "../JentiConfig.php";
require_once "../JentiWord.php";
require_once "../JentiRequestWiktionary.php";
$jenti = new JentiWord($config);
$user_info["LANGUAGE_CODE"] = "it";
$word = $jenti->get_word(853);
echo "<PRE>" . print_r($word, true) . "</PRE>";
echo json_encode($word);
//$request = new JentiRequestWiktionary($config);
/*
$word_array = $request->get_word("bambino");
if ($request->error)
{
    echo($request->error);
    exit;
}
*/
/*
foreach ($word_array as $word_data)
{
    $jenti->add_word_and_definitions($word_data);
    if ($jenti->error)
    {
        echo($jenti->error);
    }
}
*/
//$word_array = $jenti->get_words_without_definition($request);
コード例 #4
0
ファイル: JentiCrawlerPage.php プロジェクト: eliasuardi/jenti
// output string to scrolling log
//////////////////////////////////////////////////////////////////////////
function echo_msg_flush($msg)
{
    echo '<script language="JavaScript" type="text/javascript">' . 'log_write( \'' . str_replace(array('\'', "\n", "\r"), array('"', "", ""), $msg) . '\');' . '</script>';
    for ($k = 0; $k < 50000; $k++) {
        echo ' ';
    }
    echo PHP_EOL;
}
// Turn off output buffering
ini_set('default_socket_timeout', 36000);
ini_set('max_execution_time', 36000);
$words = explode(PHP_EOL, "guerra\ncombattere\nsanguinoso");
$request = new JentiRequestWiktionary($config);
$jenti_word = new JentiWord($config);
ob_implicit_flush(TRUE);
$log = log_open();
foreach ($words as $word) {
    $word_array = $request->get_word($word);
    if ($request->error) {
        echo_msg_flush($request->error);
        log_writeln($log, $request->error);
        continue;
    }
    foreach ($word_array as $word_info) {
        $jenti_word->add_word_and_definitions($word_info);
        if (!$jenti_word->error) {
            echo_msg_flush(print_r($word_info, true));
            log_writeln($log, print_r($word_info, true));
        }