Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ImportIntentConcepts | |
0.00% |
0 / 38 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
12 | |||
findConcept | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @ingroup Maintenance |
19 | */ |
20 | |
21 | use MediaWiki\Extension\MathSearch\Graph\Map; |
22 | |
23 | require_once __DIR__ . '/../../../maintenance/Maintenance.php'; |
24 | |
25 | class ImportIntentConcepts extends Maintenance { |
26 | private const URL = 'https://raw.githubusercontent.com/davidcarlisle/mathml-docs/main/_data/core.yml'; |
27 | /** @var bool */ |
28 | private $overwrite; |
29 | |
30 | public function __construct() { |
31 | parent::__construct(); |
32 | $this->addDescription( 'Batch imports definitions from a folder.' . |
33 | " \n Processes mathosphere files that follow the naming convention: \n *.json" ); |
34 | $this->addArg( 'url', 'The URL to to be read. Defaults to ', false ); |
35 | $this->addOption( |
36 | 'overwrite', 'Overwrite existing definitions with the same name.', false, false, "o" |
37 | ); |
38 | $this->setBatchSize( 100 ); |
39 | $this->requireExtension( 'MathSearch' ); |
40 | } |
41 | |
42 | public function execute() { |
43 | $url = $this->getArg( 0, self::URL ); |
44 | $this->overwrite = $this->getOption( 'overwrite' ); |
45 | if ( $this->overwrite ) { |
46 | $this->output( "Loaded with option overwrite enabled .\n" ); |
47 | } |
48 | $res = yaml_parse_url( $url ); |
49 | |
50 | $concepts = $this->findConcept( [], $res ); |
51 | $partitions = array_chunk( $concepts, $this->getBatchSize(), true ); |
52 | $jobname = 'concepts' . date( 'ymdhms' ); |
53 | $graphMap = new Map(); |
54 | $segment = 0; |
55 | foreach ( $partitions as $chunk ) { |
56 | $this->output( "Push jobs to segment $segment.\n" ); |
57 | $graphMap->pushJob( |
58 | $chunk, |
59 | $segment++, |
60 | 'MediaWiki\Extension\MathSearch\Graph\Job\MathMLIntents', |
61 | [ 'jobname' => $jobname ] ); |
62 | } |
63 | $this->output( "Pushed $segment segments.\n" ); |
64 | } |
65 | |
66 | public function findConcept( $context, $content ) { |
67 | $concepts = []; |
68 | foreach ( $content as $key => $value ) { |
69 | if ( $key === 'concept' ) { |
70 | $concepts[$value] = [ |
71 | 'context' => $context, |
72 | 'content' => $content |
73 | ]; |
74 | return $concepts; |
75 | } |
76 | if ( is_array( $value ) ) { |
77 | $concepts += $this->findConcept( [ ...$context, $key ], $value ); |
78 | } |
79 | } |
80 | return $concepts; |
81 | } |
82 | } |
83 | |
84 | $maintClass = ImportIntentConcepts::class; |
85 | /** @noinspection PhpIncludeInspection */ |
86 | require_once RUN_MAINTENANCE_IF_MAIN; |