NGramsTrait::setNgram()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\phpngrams;
6
7
/**
8
 * Trait NGramsTrait.
9
 */
10
trait NGramsTrait
11
{
12
    /**
13
     * @var \drupol\phpngrams\NGramsInterface
14
     */
15
    private $ngrams;
16
17
    /**
18
     * @param \Generator $ngrams
19
     * @param array $subset
20
     *
21
     * @return float|int
22
     */
23
    public function frequency(\Generator $ngrams, array $subset)
24
    {
25
        return $this->getNGrams()->frequency($ngrams, $subset);
26
    }
27
28
    /**
29
     * @return \drupol\phpngrams\NGramsInterface
30
     */
31
    public function getNGrams(): NGramsInterface
32
    {
33
        return $this->ngrams;
34
    }
35
36
    /**
37
     * @param array|string $data
38
     * @param int $n
39
     *
40
     * @return bool|\Generator
41
     */
42
    public function ngrams(array $data, int $n = 1)
43
    {
44
        return $this->getNGrams()->ngrams($data, $n);
45
    }
46
47
    /**
48
     * @param \drupol\phpngrams\NGramsInterface $ngrams
49
     */
50
    public function setNgram(NGramsInterface $ngrams): void
51
    {
52
        $this->ngrams = $ngrams;
53
    }
54
}
55