Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
Query | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
getQueryFromConfig | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getQueryFromProfileType | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getQidFromDe | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getResults | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\MathSearch\Graph; |
4 | |
5 | use MediaWiki\MediaWikiServices; |
6 | use ToolsParser; |
7 | |
8 | class Query { |
9 | public static function getQueryFromConfig( string $type, int $offset, int $limit ) { |
10 | global $wgMathProfileQueries; |
11 | return <<<SPARQL |
12 | PREFIX wdt: <https://portal.mardi4nfdi.de/prop/direct/> |
13 | PREFIX wd: <https://portal.mardi4nfdi.de/entity/> |
14 | SELECT ?qid WHERE { |
15 | BIND (REPLACE(STR(?item), "^.*/Q([^/]*)$", "$1") as ?qid) |
16 | ${wgMathProfileQueries[$type]} |
17 | } |
18 | LIMIT $limit |
19 | OFFSET $offset |
20 | SPARQL; |
21 | } |
22 | |
23 | public static function getQueryFromProfileType( string $type, int $offset, int $limit ) { |
24 | global $wgMathSearchPropertyProfileType, $wgMathProfileQIdMap; |
25 | return <<<SPARQL |
26 | PREFIX wdt: <https://portal.mardi4nfdi.de/prop/direct/> |
27 | PREFIX wd: <https://portal.mardi4nfdi.de/entity/> |
28 | SELECT ?qid WHERE { |
29 | BIND (REPLACE(STR(?item), "^.*/Q([^/]*)$", "$1") as ?qid) |
30 | ?item wdt:P$wgMathSearchPropertyProfileType wd:${wgMathProfileQIdMap[$type]} . |
31 | ?item wikibase:sitelinks ?sitelinks . |
32 | FILTER (?sitelinks < 1 ). |
33 | } |
34 | LIMIT $limit |
35 | OFFSET $offset |
36 | SPARQL; |
37 | } |
38 | |
39 | public static function getQidFromDe( string $des ) { |
40 | return /** @lang Sparql */ <<<SPARQL |
41 | SELECT |
42 | (REPLACE(STR(?item), ".*Q", "") AS ?qid) |
43 | ?de |
44 | WHERE { |
45 | VALUES ?de { $des } |
46 | ?item wdt:P1451 ?de |
47 | } |
48 | SPARQL; |
49 | } |
50 | |
51 | public static function getResults( string $query ) { |
52 | $configFactory = |
53 | MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'wgLinkedWiki' ); |
54 | $configDefault = $configFactory->get( "SPARQLServiceByDefault" ); |
55 | $arrEndpoint = ToolsParser::newEndpoint( $configDefault, null ); |
56 | $sp = $arrEndpoint["endpoint"]; |
57 | $rs = $sp->query( $query ); |
58 | if ( !$rs ) { |
59 | return []; |
60 | } else { |
61 | return $rs['result']['rows']; |
62 | } |
63 | } |
64 | } |