|
| 1 | +<?php |
| 2 | + |
| 3 | +include 'test_utils.php'; |
| 4 | + |
| 5 | +//importing |
| 6 | +if (!class_exists('BigML\BigML')) { |
| 7 | + include '../bigml/bigml.php'; |
| 8 | +} |
| 9 | + |
| 10 | +if (!class_exists('BigML\TopicModel')) { |
| 11 | + include '../bigml/topicmodel.php'; |
| 12 | +} |
| 13 | + |
| 14 | +use BigML\BigML; |
| 15 | +use BigML\BigMLRequest; |
| 16 | +use BigML\TopicModel; |
| 17 | + |
| 18 | +class BigMLTestBoostedEnsemble extends PHPUnit_Framework_TestCase |
| 19 | +{ |
| 20 | + protected static $username; # "you_username" |
| 21 | + protected static $api_key; # "your_api_key" |
| 22 | + protected static $api; |
| 23 | + protected static $project; |
| 24 | + |
| 25 | + public static function setUpBeforeClass() { |
| 26 | + print __FILE__; |
| 27 | + self::$api = new BigML(self::$username, self::$api_key, false); |
| 28 | + ini_set('memory_limit', '512M'); |
| 29 | + $test_name=basename(preg_replace('/\.php$/', '', __FILE__)); |
| 30 | + self::$api->delete_all_project_by_name($test_name); |
| 31 | + self::$project=self::$api->create_project(array('name'=> $test_name)); |
| 32 | + } |
| 33 | + |
| 34 | + public static function tearDownAfterClass() { |
| 35 | + self::$api->delete_all_project_by_name(basename(preg_replace('/\.php$/', '', __FILE__))); |
| 36 | + } |
| 37 | + |
| 38 | + // Successfully creating a distribution from a Topic Model |
| 39 | + |
| 40 | + |
| 41 | + public function test_scenario2() { |
| 42 | + |
| 43 | + $data = array(array("filename" => 'data/spam.csv', |
| 44 | + "topic_model_name" => 'my new topic model name', |
| 45 | + "params" => array("fields"=> |
| 46 | + array("000001"=> |
| 47 | + array("optype"=> "text", |
| 48 | + "term_analysis"=> array("case_sensitive" => true, |
| 49 | + "stem_words" => true, |
| 50 | + "use_stopwords" => false, |
| 51 | + "language" => "en")))))); |
| 52 | + |
| 53 | + foreach($data as $item) { |
| 54 | + print "\nGiven I create a data source uploading a data file\n"; |
| 55 | + $source = self::$api->create_source($item["filename"], $options=array('name'=>'local_test_source', 'project'=> self::$project->resource)); |
| 56 | + $this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code); |
| 57 | + $this->assertEquals(1, $source->object->status->code); |
| 58 | + |
| 59 | + print "And I wait until the source is ready\n"; |
| 60 | + $resource = self::$api->_check_resource($source->resource, null, 3000, 30); |
| 61 | + $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); |
| 62 | + |
| 63 | + print "And I update the source\n"; |
| 64 | + $updated_source = self::$api->update_source($source->resource, $item["params"], 3000, 30); |
| 65 | + |
| 66 | + print "And I create a dataset\n"; |
| 67 | + $dataset = self::$api->create_dataset($updated_source->resource); |
| 68 | + $this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code); |
| 69 | + $this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code); |
| 70 | + |
| 71 | + print "And I wait until the dataset is ready\n"; |
| 72 | + $resource = self::$api->_check_resource($dataset->resource, null, 3000, 30); |
| 73 | + $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); |
| 74 | + |
| 75 | + print "And I create topic model from a dataset\n"; |
| 76 | + $topicmodel = self::$api->create_topicmodel($dataset->resource); |
| 77 | + $this->assertEquals(BigMLRequest::HTTP_CREATED, $topicmodel->code); |
| 78 | + |
| 79 | + print "And I wait until the topic model is ready\n"; |
| 80 | + $resource = self::$api->_check_resource($topicmodel->resource, null, 3000, 50); |
| 81 | + $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); |
| 82 | + |
| 83 | + print "And I update the topic model name to " . $item["topic_model_name"] . "\n"; |
| 84 | + $updated_topicmodel = self::$api->update_topicmodel($topicmodel->resource, array("name" => $item["topic_model_name"])); |
| 85 | + |
| 86 | + print "Then the topic model name is " . $item["topic_model_name"] . "\n"; |
| 87 | + $new_topicmodel=self::$api->get_topicmodel($updated_topicmodel->resource); |
| 88 | + $this->assertEquals($new_topicmodel->object->name, $item["topic_model_name"]); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | +?> |
0 commit comments