Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Segmenter | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
segmentSentences | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
evaluateHash | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Wikispeech\Segment; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | /** |
12 | * Used for dividing text into segments, that can then be sent to the |
13 | * Speechoid service. Also calculates values for variables that are needed |
14 | * for highlighting. |
15 | * |
16 | * @since 0.1.10 |
17 | */ |
18 | abstract class Segmenter { |
19 | |
20 | /** |
21 | * Divide a cleaned content array into segments, one for each sentence. |
22 | * |
23 | * @since 0.1.10 |
24 | * @param SegmentContent[] $cleanedContent An array of items returned by `Cleaner::cleanHtml()`. |
25 | * @return Segment[] An array of segments, each containing the `CleanedText's in that segment. |
26 | */ |
27 | abstract public function segmentSentences( array $cleanedContent ): array; |
28 | |
29 | /** |
30 | * Used to evaluate hash of segments, the primary key for stored utterances. |
31 | * |
32 | * @since 0.1.10 |
33 | * @param Segment $segment The segment to be evaluated. |
34 | * @return string SHA256 message digest |
35 | */ |
36 | public function evaluateHash( Segment $segment ): string { |
37 | $context = hash_init( 'sha256' ); |
38 | foreach ( $segment->getContent() as $part ) { |
39 | hash_update( $context, $part->getString() ); |
40 | hash_update( $context, "\n" ); |
41 | } |
42 | return hash_final( $context ); |
43 | // Uncommenting below block can be useful during creation of |
44 | // new test cases as you might need to figure out hashes. |
45 | //LoggerFactory::getInstance( 'Segmenter' ) |
46 | // ->info( __METHOD__ . ': {segement} : {hash}', [ |
47 | // 'segment' => $segment, |
48 | // 'hash' => $hash |
49 | // ] ); |
50 | } |
51 | |
52 | } |