Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
State | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addEdge | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
writeATT | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Wikimedia\LangConv\Construct; |
4 | |
5 | /** |
6 | * A state in a mutable FST. |
7 | */ |
8 | class State { |
9 | /** @var int */ |
10 | public $id; |
11 | /** @var array<?Edge> */ |
12 | public $edges = []; |
13 | /** @var bool */ |
14 | public $isFinal = false; |
15 | |
16 | /** |
17 | * Create a new state. |
18 | * @param int $id The index of this state in the parent MutableFST. |
19 | */ |
20 | public function __construct( int $id ) { |
21 | $this->id = $id; |
22 | } |
23 | |
24 | /** |
25 | * Add an edge from this state to another. |
26 | * @param string $upper The token on the upper side of the edge |
27 | * @param string $lower The token on the lower side of the edge |
28 | * @param State $to The destination of the edge |
29 | */ |
30 | public function addEdge( string $upper, string $lower, State $to ): void { |
31 | $this->edges[] = new Edge( $this, count( $this->edges ), $upper, $lower, $to ); |
32 | } |
33 | |
34 | /** |
35 | * Write the edges of this state to the given $handle as an AT&T format |
36 | * file. |
37 | * @param resource $handle |
38 | */ |
39 | public function writeATT( $handle ): void { |
40 | foreach ( $this->edges as $e ) { |
41 | $line = [ |
42 | strval( $e->from->id ), |
43 | strval( $e->to->id ), |
44 | $e->upper, $e->lower |
45 | ]; |
46 | fwrite( $handle, implode( "\t", $line ) . "\n" ); |
47 | } |
48 | } |
49 | } |