Advertisement
Guest User

Summarizer

a guest
Dec 11th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. <?php namespace App\Controllers\Trial;
  2.  
  3. use Sastrawi\Stemmer\StemmerFactory;
  4. use Nadar\Stemming\Stemm;
  5. use Sastrawi\StopWordRemover\StopWordRemoverFactory;
  6. use PhpScience\TextRank\TextRankFacade;
  7. use PhpScience\TextRank\Tool\StopWords\Indonesian;
  8. use PhpScience\TextRank\Tool\StopWords\English;
  9. use PhpScience\TextRank\Tool\Summarize;
  10.  
  11.  
  12. class Spell extends \CodeIgniter\Controller
  13. {
  14.  
  15. protected $text = "Objective structured clinical examinations can be used to understand students' care skill performance and to evaluate courses. Thus, identifying antecedents to improved skill performance in these examinations is crucial for improving students' future care ability. This study examined the antecedents of clinical skill performance in nursing students and determined whether perceived task load and anxiety mediate the relationships between task characteristics and skill performance. Methods A quantitative approach was conducted. The questionnaire for this study was comprised of five measures: Simulation Learning Effectiveness Scale, Task Characteristic Sub scale, Task Cognitive Loading Scale, State-Trait Anxiety Inventory, and a clinical practice examination. Finding Structural equation modeling revealed that students' simulation learning effectiveness was positively associated with three task characteristics during clinical examinations. Further, the effect of learning effectiveness on task feedback was greater than on task autonomy, variety, identity, and significance. In addition, task load mediated the relationship between task variety, identity, and significance and clinical examination performance, whereas anxiety mediated the relationships between all three task characteristics and clinical examination performance. Promoting nursing students' simulation learning effectiveness is crucial for improving feedback in regard to the task. Further, those who perceived the task as having more variety, identity, and significance were more likely to perceive the task as having a higher cognitive load and to experience anxiety, which, in turn, led to poorer performance. Interventions should, therefore, managers' aim to reduce students' perceived load and anxiety before they participate in clinical skill examinations.";
  16.  
  17. private function checkMissSpelled($source)
  18. {
  19. if ($source == '') {
  20. return ['count' => 0];
  21. }
  22.  
  23. $data = preg_replace("/[^A-Za-z\- ,.\'\"]/", " ", $source);
  24. if (is_array($data)) {
  25. $data = preg_replace("/\s+/", " ", trim($data[0]));
  26. } else {
  27. $data = preg_replace("/\s+/", " ", trim($data));
  28. }
  29. $data = preg_replace("/\-/", "", $data);
  30. $words = explode(' ', $data);
  31.  
  32. $suggest = [];
  33. $src = [];
  34. $rpl = [];
  35. $id = pspell_new('id');
  36. $en = pspell_new('en');
  37.  
  38. foreach ($words as $k => $word) {
  39. $word = trim(str_replace('"','',$word));
  40. if (!pspell_check($id, $word) && !pspell_check($en, $word)) {
  41. $suggest_id = pspell_suggest($id, $word);
  42. $suggest_en = pspell_suggest($en, $word);
  43. $src[$k] = $word;
  44. $rpl_id = $suggest_id[0]??'';
  45. $rpl_en = $suggest_en[0]??'';
  46. $lev_id = levenshtein($word, $rpl_id);
  47. $lev_en = levenshtein($word, $rpl_en);
  48. $rpl[$k] = ($lev_id > 2 && $lev_en > 2) ? $word : ($lev_id <= $lev_en ? $rpl_id : $rpl_en);
  49. $rpl[$k] = "{#".$rpl[$k]."#}";
  50. }
  51. }
  52.  
  53. return [str_replace($src, $rpl, $source), $src, $rpl];
  54. }
  55.  
  56. public function index()
  57. {
  58. $data['original'] = $this->text;
  59. $this->layout($data);
  60. }
  61.  
  62. public function post()
  63. {
  64.  
  65. $data['original'] = $this->request->getPost('txt');
  66. $data['keyword'] = $this->request->getPost('keyword');
  67. $data['lines'] = $this->request->getPost('lines');
  68. $data['lang'] = $this->request->getPost('lang');
  69.  
  70. if($data['original'] == null || $data['original'] ==''){
  71. $data['original'] = $this->text;
  72. }
  73.  
  74. if($data['keyword'] == null || $data['keyword'] ==0){
  75. $data['keyword'] = 5;
  76. }
  77.  
  78. if($data['lines'] == null || $data['lines'] ==0){
  79. $data['lines'] = 5;
  80. }
  81.  
  82. if($data['lang'] == null || $data['lang'] ==''){
  83. $data['lang'] = 'id';
  84. }
  85.  
  86. $txt = preg_replace("/\((.*?)\)/",'',$data['original']);
  87.  
  88. $spelcheck = $this->checkMissSpelled($txt);
  89. $data['spelcheck'] = $spelcheck[0];
  90.  
  91. $api = new TextRankFacade();
  92.  
  93. if($data['lang'] == 'id'){
  94. $sf = new StemmerFactory();
  95. $stem = $sf->createStemmer();
  96. $data['stemmed'] = $stem->stem($spelcheck[0]);
  97. $stopWords = new Indonesian();
  98. }else{
  99. $stem = new Stemm();
  100. $data['stemmed'] = $stem::stemPhrase($spelcheck[0],'en');
  101. $stopWords = new English();
  102. }
  103.  
  104. $api->setStopWords($stopWords);
  105.  
  106. $kw = [];
  107. foreach(array_slice($api->getOnlyKeywords($spelcheck[0]),0,$data['keyword']) as $k=>$v){
  108. $kw[] = $k;
  109. }
  110.  
  111. $data['keyWords'] = join($kw, '; ');
  112.  
  113. $data['summary'] = str_replace(['{#','#}'],['<mark>','</mark>'], join($api->summarizeTextFreely($spelcheck[0], $data['keyword'], $data['lines'], Summarize::GET_ALL_IMPORTANT),'. '));
  114.  
  115. $missSpelled = [];
  116. foreach($spelcheck[1] as $k=>$v){
  117. if($v != $spelcheck[2][$k] ){
  118. $missSpelled[] = $v ." => ". str_replace(['{#','#}'],['<mark>','</mark>'], $spelcheck[2][$k]);
  119. }
  120. }
  121.  
  122. $data['missSpelled'] = join($missSpelled, '<br>');
  123.  
  124. $data['mainSentence'] = join($api->summarizeTextFreely($spelcheck[0], $data['keyword'], 1, Summarize::GET_ALL_IMPORTANT),'');
  125.  
  126. $pos = strripos($spelcheck[0], $data['mainSentence']);
  127. $last = strlen($spelcheck[0])-strlen($data['mainSentence'])-$pos;
  128.  
  129. $data['paragraphType'] = ($pos > $last ? 'induktif':'deduktif');
  130. $this->layout($data);
  131. }
  132.  
  133. private function layout($data)
  134. {
  135. echo view('Header');
  136. echo view('Spell/Show',['data' =>$data]);
  137. echo view('Footer');
  138. }
  139. }
  140.  
  141. /*
  142. sudo apt-get install libstemmer-dev
  143. git clone https://github.com/jbboehr/php-stemmer.git
  144. cd php-stemmer
  145. phpize
  146. ./configure
  147. make
  148. # make test
  149. sudo make install
  150. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement