SentenceRepository.php 946 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Sentence;
  4. use App\Models\Word;
  5. use DB;
  6. class SentenceRepository extends ResourceRepository
  7. {
  8. //protected $user;
  9. public function __construct(Sentence $sentence)
  10. {
  11. $this->sentence = $sentence;
  12. }
  13. public function all()
  14. {
  15. return $this->sentence->all();
  16. }
  17. public function getWordNotPunctCount($sentence_id)
  18. {
  19. return Sentence::join('words','sentence_id','=','sentences.id')
  20. ->select(DB::raw('count(*) as word_not_punct_count, value'))
  21. ->where('sentence_id',$sentence_id)
  22. ->whereRaw("value NOT REGEXP '^([[:punct:]]|„|“)$'")->first();
  23. }
  24. public function getWords($sentence_id)
  25. {
  26. return Sentence::select('words.id')
  27. ->join('words','words.sentence_id','=','sentences.id')
  28. ->where('sentence_id',$sentence_id)->toArray();
  29. }
  30. }