|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PPP\Wikidata\ValueParsers; |
|
4
|
|
|
|
|
5
|
|
|
use DataValues\Geo\Parsers\GlobeCoordinateParser; |
|
6
|
|
|
use ValueParsers\ParserOptions; |
|
7
|
|
|
use ValueParsers\ValueParser; |
|
8
|
|
|
use Wikibase\EntityStore\EntityStore; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Build a parser for Wikibase value |
|
12
|
|
|
* |
|
13
|
|
|
* @licence GPLv2+ |
|
14
|
|
|
* @author Thomas Pellissier Tanon |
|
15
|
|
|
*/ |
|
16
|
|
|
class WikibaseValueParserFactory { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string language code |
|
20
|
|
|
*/ |
|
21
|
|
|
private $languageCode; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var EntityStore |
|
25
|
|
|
*/ |
|
26
|
|
|
private $entityStore; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param $languageCode |
|
30
|
|
|
* @param EntityStore $entityStore |
|
31
|
|
|
*/ |
|
32
|
8 |
|
public function __construct($languageCode, EntityStore $entityStore) { |
|
33
|
8 |
|
$this->languageCode = $languageCode; |
|
34
|
8 |
|
$this->entityStore = $entityStore; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return WikibaseValueParser |
|
39
|
|
|
*/ |
|
40
|
8 |
|
public function newWikibaseValueParser() { |
|
41
|
|
|
return new WikibaseValueParser(array( |
|
42
|
|
|
'commonsMedia' => new StringParser(), |
|
43
|
|
|
'external-id' => new StringParser(), |
|
44
|
|
|
'globe-coordinate' => new GlobeCoordinateParser(), |
|
45
|
|
|
//TODO 'quantity' => , |
|
46
|
|
|
'monolingualtext' => new MonolingualTextParser(), |
|
47
|
|
|
'string' => new StringParser(), |
|
48
|
|
|
//TODO 'time' => , |
|
49
|
|
|
'url' => new StringParser(), |
|
50
|
8 |
|
'wikibase-item' => $this->newWikibaseEntityParser('item'), |
|
51
|
8 |
|
'wikibase-property' => $this->newWikibaseEntityParser('property') |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
private function newWikibaseEntityParser($type) { |
|
56
|
|
|
$parserOptions = new ParserOptions(array( |
|
57
|
|
|
ValueParser::OPT_LANG => $this->languageCode, |
|
58
|
|
|
WikibaseEntityIdParser::OPT_ENTITY_TYPE => $type |
|
59
|
|
|
)); |
|
60
|
|
|
|
|
61
|
|
|
return new WikibaseEntityIdParser( |
|
62
|
|
|
$this->entityStore, |
|
63
|
|
|
$parserOptions |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|