WordRepository.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Word;
  4. use App\Models\Sentence;
  5. use Illuminate\Support\Facades\DB;
  6. class WordRepository extends ResourceRepository {
  7. public function __construct(Word $word,Sentence $sentence) {
  8. $this->word = $word;
  9. $this->sentence = $sentence;
  10. }
  11. public function getByWordId($word_id) {
  12. return $this->game->where('word_id', $word_id)->first();
  13. }
  14. public function get_number_tokens($corpus_is_training) {
  15. return($this->word->select(DB::raw('count(words.id) as count'))
  16. ->join('sentences', 'sentence_id', '=', 'sentences.id')
  17. ->join('corpora', 'corpus_id', '=', 'corpora.id')
  18. ->where('corpora.is_training','=',$corpus_is_training)
  19. ->where('corpora.id', '!=',324)
  20. ->where('corpora.id', '!=',322)
  21. ->first());
  22. }
  23. public function get_number_types($corpus_is_training) {
  24. return($this->word->select(DB::raw('count(distinct(value)) as count'))
  25. ->join('sentences', 'sentence_id', '=', 'sentences.id')
  26. ->join('corpora', 'corpus_id', '=', 'corpora.id')
  27. ->where('corpora.is_training','=',$corpus_is_training)->first());
  28. }
  29. public function get_total_number_tokens() {
  30. return($this->word->select(DB::raw('count(words.id) as count'))->first());
  31. }
  32. public function get_total_number_types() {
  33. return($this->word->select(DB::raw('count(distinct(value)) as count'))->first());
  34. }
  35. public function get_words_number($corpus_id) {
  36. return($this->word->select(DB::raw('count(words.id) as count'))
  37. ->join('sentences', 'sentence_id', '=', 'sentences.id')
  38. ->join('corpora', 'corpus_id', '=', 'corpora.id')
  39. ->where('corpora.id','=',$corpus_id)->first());
  40. }
  41. public function get_types_number($corpus_id) {
  42. return($this->word->select(DB::raw('count(distinct(words.value)) as count'))
  43. ->join('sentences', 'sentence_id', '=', 'sentences.id')
  44. ->join('corpora', 'corpus_id', '=', 'corpora.id')
  45. ->where('corpora.id','=',$corpus_id)->first());
  46. }
  47. public function get_sentences_number($corpus_id) {
  48. return($this->sentence->select(DB::raw('count(sentences.id) as count'))
  49. ->join('corpora', 'corpus_id', '=', 'corpora.id')
  50. ->where('corpora.id','=',$corpus_id)->first());
  51. }
  52. }