Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
Query | |
0.00% |
0 / 45 |
|
0.00% |
0 / 8 |
90 | |
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 | |||
getQidFromConcept | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getResults | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
getQueryForDoi | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getQueryForWdId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getQueryEndpoint | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
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 getQidFromConcept( string $concepts ) { |
52 | return /** @lang Sparql */ <<<SPARQL |
53 | SELECT |
54 | (REPLACE(STR(?item), ".*Q", "") AS ?qid) |
55 | ?de |
56 | WHERE { |
57 | VALUES ?de { $concepts } |
58 | ?item wdt:P1511 ?de |
59 | } |
60 | SPARQL; |
61 | } |
62 | |
63 | public static function getResults( string $query ) { |
64 | $configFactory = |
65 | MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'wgLinkedWiki' ); |
66 | $configDefault = $configFactory->get( "SPARQLServiceByDefault" ); |
67 | $arrEndpoint = ToolsParser::newEndpoint( $configDefault, null ); |
68 | $sp = $arrEndpoint["endpoint"]; |
69 | $rs = $sp->query( $query ); |
70 | if ( !$rs ) { |
71 | return []; |
72 | } else { |
73 | return $rs['result']['rows']; |
74 | } |
75 | } |
76 | |
77 | public static function getQueryForDoi( int $offset, int $limit ) { |
78 | global $wgMathSearchPropertyDoi; |
79 | return <<<SPARQL |
80 | PREFIX wdt: <https://portal.mardi4nfdi.de/prop/direct/> |
81 | SELECT ?qid ?doi WHERE { |
82 | BIND (REPLACE(STR(?item), "^.*/Q([^/]*)$", "$1") as ?qid) . |
83 | ?item wdt:P$wgMathSearchPropertyDoi ?doi . |
84 | FILTER REGEX(?doi, "[a-z]") |
85 | } |
86 | LIMIT $limit |
87 | OFFSET $offset |
88 | SPARQL; |
89 | } |
90 | |
91 | public static function getQueryForWdId(): string { |
92 | return <<<SPARQL |
93 | PREFIX wdt: <https://portal.mardi4nfdi.de/prop/direct/> |
94 | PREFIX wikidata_wdt: <http://www.wikidata.org/prop/direct/> |
95 | |
96 | SELECT DISTINCT |
97 | (REPLACE(STR(?mardi_item), ".*Q", "") AS ?qid) |
98 | (REPLACE(STR(?wikidata), ".*Q", "Q") AS ?P12) |
99 | WHERE { |
100 | SERVICE bd:sample { ?mardi_item wdt:P27 ?doi . bd:serviceParam bd:sample.limit 10000 } |
101 | BIND(UCASE(?doi) AS ?DOI) |
102 | FILTER NOT EXISTS { ?mardi_item wdt:P12 ?WikidataQID } |
103 | service <https://query.wikidata.org/sparql> { |
104 | ?wikidata wikidata_wdt:P356 ?DOI |
105 | } |
106 | } |
107 | SPARQL; |
108 | } |
109 | |
110 | public static function getQueryEndpoint( $config = null ) { |
111 | $configFactory = $config ?? |
112 | MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'wgLinkedWiki' ); |
113 | $configDefault = $configFactory->get( "SPARQLServiceByDefault" ); |
114 | $arrEndpoint = ToolsParser::newEndpoint( $configDefault, null ); |
115 | return $arrEndpoint["endpoint"]; |
116 | } |
117 | |
118 | } |