/**
  * @param Sentence $sentence
  *
  * @return string[]
  */
 public function detect(Sentence $sentence)
 {
     $thematics = [];
     foreach ($sentence->getWords() as $word) {
         if ($thematic = $this->detectWord($word)) {
             $thematics[] = $thematic;
         }
     }
     return $thematics;
 }
 /**
  * Generate and save randomization result (if need)
  */
 public function actionGenerate()
 {
     $random = [];
     foreach ($this->words as $position) {
         $random[] = $position[array_rand($position)];
     }
     list($a, $b, $c) = $random;
     $sentence = new Sentence();
     $sentence->varBody = $a . " make this " . $b . " test sentence " . $c;
     echo "Result: \n" . $sentence->varBody . "\n";
     if ($sentence->isUnique()) {
         $sentence->saveUnique();
     }
 }
Example #3
0
 public static function boot()
 {
     parent::boot();
     // Setup event bindings...
     Sentence::creating(function ($sentence) {
         echo ":3";
         if ($sentence->subject_url) {
             if ($sentence->object_url) {
                 SparqlData::postData("<" . $sentence->subject_url . "> <" . $sentence->action . "> <" . $sentence->object_url . ">", "http://example.com/graph");
             } else {
                 if ($sentence->location_url) {
                     SparqlData::postData("<" . $sentence->subject_url . "> <" . $sentence->action . "> <" . $sentence->location_url . ">", "http://example.com/graph");
                 } else {
                     if ($sentence->object) {
                         SparqlData::postData("<" . $sentence->subject_url . "> <" . $sentence->action . "> \"" . $sentence->object . "\"", "http://example.com/graph");
                     } else {
                         if ($sentence->location) {
                             SparqlData::postData("<" . $sentence->subject_url . "> <" . $sentence->action . "> \"" . $sentence->location . "\"", "http://example.com/graph");
                         }
                     }
                 }
             }
         }
     });
 }
Example #4
0
 private function createUserObjects()
 {
     /*
      * sentenceObject = {
      *  rid : {
      *      sentenceId : [
      *          {
      *              text : string, 
      *              opinions : [{
      *                  category : string,
      *                  polarity : string
      *              }]
      *          }
      *      ]
      *  }
      * }
      * */
     foreach ($this->sentenceObject as $rid => $s) {
         $user = new User($rid);
         foreach ($s as $sentenceId => $ss) {
             $sentence = new Sentence($sentenceId, $rid, $this->productId, $ss['text']);
             if (array_key_exists('opinions', $ss)) {
                 foreach ($ss['opinions'] as $o) {
                     $opinion = new Opinion($o['category'], $o['polarity']);
                     $sentence->addOpinion($opinion);
                 }
             }
             $user->addSentence($sentence);
         }
         $this->users[] = $user;
     }
     echo "User Object construction completed.\n";
 }
 public function show($id)
 {
     $sentence = Sentence::find($id);
     if ($sentence->subject_url && $sentence->subject_url != "") {
         $dbpedia_data = $sentence->json_data();
         $this->layout->content = View::make('dbpedia.show', array("dbpedia_data" => $dbpedia_data, "sentence" => $sentence));
     }
 }
Example #6
0
 /**
  * @covers Sentence::split
  */
 public function testSplitParenthesis()
 {
     $this->assertSame(array("You there (not here!).", " Mister Smith"), $this->object->split("You there (not here!). Mister Smith"));
     $this->assertSame(array("You (not him!) here.", " Mister Smith"), $this->object->split("You (not him!) here. Mister Smith"));
     $this->assertSame(array("(What!) you here.", " Mister Smith"), $this->object->split("(What!) you here. Mister Smith"));
     $this->assertSame(array("You there (not here).", " Mister Smith"), $this->object->split("You there (not here). Mister Smith"));
     $this->assertSame(array("You (not him) here.", " Mister Smith"), $this->object->split("You (not him) here. Mister Smith"));
     $this->assertSame(array("(What) you here.", " Mister Smith"), $this->object->split("(What) you here. Mister Smith"));
 }
Example #7
0
 public function parseRelations()
 {
     if ($this->response->status()) {
         $json_data = json_decode($this->response->response());
         if ($json_data && $json_data->status == "OK") {
             foreach ($json_data->relations as $relation) {
                 $object_data = "";
                 if (property_exists($relation, "object")) {
                     $object_data = $relation->object->text;
                 }
                 $action_data = "";
                 if (property_exists($relation, "action")) {
                     $action_data = $relation->action->text;
                 }
                 $location_data = "";
                 if (property_exists($relation, "location")) {
                     $location_data = $relation->location->text;
                 }
                 $sentence = new Sentence();
                 $sentence->full_text = $this->full_text;
                 $sentence->subject = $relation->subject->text;
                 $sentence->action = $action_data;
                 $sentence->object = $object_data;
                 $sentence->location = $location_data;
                 $sentence->subject_url = $relation->subject;
                 if ($object_data != "") {
                     $sentence->object_url = $relation->object;
                 }
                 if ($location_data != "") {
                     $sentence->location_url = $relation->location;
                 }
                 $sentence->save();
                 array_push($this->relations, $sentence);
             }
         }
     }
     return $this->relations;
 }
Example #8
0
 /**
  * Reorder the order of the Message's sentence if it
  * doesn't match its pattern
  *
  * @param Message $message The message to reorder
  */
 public static function reorder(Message $message)
 {
     if ($message->pattern == Sentence::asPattern($message)) {
         return $message;
     }
     // Transform the pattern into an array and reorder according to it
     preg_match_all('/([a-z]+[0-9]{0,}) ?/', $message->pattern, $pattern);
     foreach ($pattern[1] as $p) {
         $_sentence[$p] = $message->{$p};
     }
     // Update the message's pattern
     $message->sentence = $_sentence;
     return $message;
 }
 public function crawl()
 {
     if (!Input::has('url')) {
         return $this->layout->content = View::make('crawlurl');
     }
     $startURL = Input::get("url");
     $depth = Input::get("depth");
     $crawler = new crawler($startURL, $depth);
     //$crawler->setHttpAuth($username, $password);
     $crawler->run();
     $i = 0;
     echo sizeof($crawler->getSeen());
     foreach ($crawler->getSeen() as $url => $seen) {
         $archemy = new Archemy($url, 1);
         if ($archemy->status()) {
             $archemy->parseRelations();
             //array_merge($relations,);
         }
         echo $archemy->response();
         //echo $url."<br>";
     }
     $relations = Sentence::where("full_text", $startURL);
     $this->layout->content = View::make('archemy.show', array("response" => "", "relations" => $relations, "data" => $startURL));
 }
Example #10
0
 public function testGetSentenceParams()
 {
     $s = new Sentence('testSentenceId', 'testSentenceRid', 'testProductId', 'testText', 'testSId');
     $expected = array('s_id' => 'testSId', 'sentence_id' => 'testSentenceId', 'rid' => 'testSentenceRid', 'product_id' => 'testProductId', 'text' => 'testText');
     $this->assertEquals($expected, $s->getSentenceParams());
 }
Example #11
0
<?php

/**
 * Created by PhpStorm.
 * User: a34524
 * Date: 15/12/8
 * Time: 下午8:40
 */
require "foundation/Sentence.php";
$S = new Sentence();
$id = intval($_POST['id']);
$S->Update($id);
<?php

/**
 * Created by PhpStorm.
 * User: a34524
 * Date: 15/12/8
 * Time: 下午8:40
 */
require "foundation/Sentence.php";
$S = new Sentence();
//$jsonStr=$_POST['List'];
$S->GetSentenceNum();
 public function createSentence($paragraph, $order, $text, $idLanguage)
 {
     $sentence = new Sentence();
     if (substr($text, 0, 1) == ':') {
         $text = substr($text, 1);
     }
     $sentence->setText($text);
     $sentence->setParagraphOrder($order);
     $sentence->setIdParagraph($paragraph->getId());
     $sentence->setIdLanguage($idLanguage);
     $sentence->save();
     return $sentence;
 }
Example #14
0
<?php

/**
 * Created by PhpStorm.
 * User: a34524
 * Date: 15/12/8
 * Time: 下午8:40
 */
require "foundation/Sentence.php";
$S = new Sentence();
$jsonStr = $_POST['List'];
$S->Add($jsonStr);
Example #15
0
<?php

/**
 * Created by PhpStorm.
 * User: a34524
 * Date: 15/12/8
 * Time: 下午8:40
 */
require "foundation/Sentence.php";
$S = new Sentence();
//$jsonStr=$_POST['List'];
$S->Show();