1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL; |
4
|
|
|
|
5
|
|
|
use SMW\ParserData; |
6
|
|
|
use SMW\Subobject; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @license GNU GPL v2+ |
11
|
|
|
* @since 1.0 |
12
|
|
|
* |
13
|
|
|
* @author mwjames |
14
|
|
|
*/ |
15
|
|
|
class LanguageLinkAnnotator { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ParserData |
19
|
|
|
*/ |
20
|
|
|
private $parserData; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @param ParserData $parserData |
26
|
|
|
*/ |
27
|
14 |
|
public function __construct( ParserData $parserData ) { |
28
|
14 |
|
$this->parserData = $parserData; |
29
|
14 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @since 1.0 |
33
|
|
|
* |
34
|
|
|
* @param InterlanguageLink $interlanguageLink |
35
|
|
|
* |
36
|
|
|
* @return boolean |
37
|
|
|
*/ |
38
|
9 |
|
public function hasDifferentLanguageAnnotation( InterlanguageLink $interlanguageLink ) { |
39
|
|
|
|
40
|
9 |
|
$propertyValues = $this->parserData->getSemanticData()->getPropertyValues( |
41
|
9 |
|
new DIProperty( PropertyRegistry::SIL_CONTAINER ) |
42
|
9 |
|
); |
43
|
|
|
|
44
|
9 |
|
foreach ( $propertyValues as $value ) { |
45
|
2 |
|
if ( $value->getSubobjectname() !== $interlanguageLink->getContainerId() ) { |
46
|
2 |
|
return true; |
47
|
|
|
} |
48
|
8 |
|
} |
49
|
|
|
|
50
|
8 |
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @since 1.2 |
55
|
|
|
* |
56
|
|
|
* @return boolean |
57
|
|
|
*/ |
58
|
8 |
|
public function canAddAnnotation() { |
59
|
8 |
|
return method_exists( $this->parserData, 'canModifySemanticData' ) ? $this->parserData->canModifySemanticData() : true; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @since 1.0 |
64
|
|
|
* |
65
|
|
|
* @param InterlanguageLink $interlanguageLink |
66
|
|
|
*/ |
67
|
8 |
|
public function addAnnotationForInterlanguageLink( InterlanguageLink $interlanguageLink ) { |
68
|
|
|
|
69
|
8 |
|
$subobject = new Subobject( $this->parserData->getTitle() ); |
70
|
8 |
|
$subobject->setEmptyContainerForId( $interlanguageLink->getContainerId() ); |
71
|
|
|
|
72
|
8 |
|
$subobject->getSemanticData()->addDataValue( |
73
|
8 |
|
$interlanguageLink->newLanguageDataValue() |
74
|
8 |
|
); |
75
|
|
|
|
76
|
8 |
|
$subobject->getSemanticData()->addDataValue( |
77
|
8 |
|
$interlanguageLink->newLinkReferenceDataValue() |
78
|
8 |
|
); |
79
|
|
|
|
80
|
8 |
|
$this->parserData->getSemanticData()->addPropertyObjectValue( |
81
|
8 |
|
$interlanguageLink->newContainerProperty(), |
82
|
8 |
|
$subobject->getContainer() |
83
|
8 |
|
); |
84
|
|
|
|
85
|
8 |
|
$this->parserData->pushSemanticDataToParserOutput(); |
86
|
8 |
|
$this->parserData->setSemanticDataStateToParserOutputProperty(); |
87
|
8 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @since 1.0 |
91
|
|
|
* |
92
|
|
|
* @param InterwikiLanguageLink $interwikiLanguageLink |
93
|
|
|
*/ |
94
|
3 |
|
public function addAnnotationForInterwikiLanguageLink( InterwikiLanguageLink $interwikiLanguageLink ) { |
95
|
|
|
|
96
|
2 |
|
$subobject = new Subobject( $this->parserData->getTitle() ); |
97
|
2 |
|
$subobject->setEmptyContainerForId( $interwikiLanguageLink->getContainerId() ); |
98
|
|
|
|
99
|
2 |
|
$subobject->getSemanticData()->addDataValue( |
100
|
2 |
|
$interwikiLanguageLink->newLanguageDataValue() |
101
|
2 |
|
); |
102
|
|
|
|
103
|
2 |
|
$subobject->getSemanticData()->addDataValue( |
104
|
2 |
|
$interwikiLanguageLink->newInterwikiReferenceDataValue() |
105
|
2 |
|
); |
106
|
|
|
|
107
|
2 |
|
$this->parserData->getSemanticData()->addPropertyObjectValue( |
108
|
2 |
|
$interwikiLanguageLink->newContainerProperty(), |
109
|
2 |
|
$subobject->getContainer() |
110
|
2 |
|
); |
111
|
|
|
|
112
|
2 |
|
$this->parserData->pushSemanticDataToParserOutput(); |
113
|
3 |
|
$this->parserData->setSemanticDataStateToParserOutputProperty(); |
114
|
2 |
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|