Index: trunk/extensions/Wikidata/OmegaWiki/Skel.php |
— | — | @@ -0,0 +1,25 @@ |
| 2 | +<?php |
| 3 | +# A very simple skeleton Wikidata script. |
| 4 | + |
| 5 | +define('MEDIAWIKI', true ); |
| 6 | + |
| 7 | +require_once("../../../../StartProfiler.php"); |
| 8 | +require_once("../../../../LocalSettings.php"); |
| 9 | +require_once("../../php-tools/ProgressBar.php"); |
| 10 | +require_once("DatabaseUtilities.php"); |
| 11 | +require_once("Setup.php"); |
| 12 | + |
| 13 | + |
| 14 | +global |
| 15 | +$beginTime, $wgCommandLineMode; |
| 16 | + |
| 17 | +$beginTime = time(); |
| 18 | +$wgCommandLineMode = true; |
| 19 | +$dc = "uw"; |
| 20 | + |
| 21 | +/* insert code here */ |
| 22 | + |
| 23 | +$endTime = time(); |
| 24 | +echo("\n\nTime elapsed: " . durationToString($endTime - $beginTime)); |
| 25 | + |
| 26 | +?> |
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php |
— | — | @@ -14,6 +14,7 @@ |
15 | 15 | |
16 | 16 | protected $record=null; |
17 | 17 | protected $definedMeaningID=null; |
| 18 | + protected $viewInformation=null; |
18 | 19 | |
19 | 20 | /** |
20 | 21 | *Construct a new DefinedMeaningModel for a particular defined meaning |
— | — | @@ -37,6 +38,7 @@ |
38 | 39 | $viewInformation->queryTransactionInformation= new QueryLatestTransactionInformation(); |
39 | 40 | } |
40 | 41 | |
| 42 | + $this->viewInformation=$viewInformation; |
41 | 43 | #wfDebug("definedMeaningId:$definedMeaningId, filterLanguageId:$viewInformation->filterLanguageId, possiblySynonymousRelationTypeId:$viewInformation->possiblySynonymousRelationTypeId, queryTransactionInformation:$viewInformation->queryTransactionInformation\n"); |
42 | 44 | $this->setDefinedMeaningID($definedMeaningId); |
43 | 45 | $record = new ArrayRecord($definedMeaningAttribute->type); |
— | — | @@ -66,13 +68,31 @@ |
67 | 69 | /* Sorry, don't know what horrible cannibalised hacks are. Therefore I cannot update code properly. |
68 | 70 | * Please check if it still works correctly. Peter-Jan Roes. |
69 | 71 | */ |
70 | | - /* :-D */ |
| 72 | + /* You are a wise man! :-D */ |
71 | 73 | public function save() { |
72 | 74 | initializeOmegaWikiAttributes($this->viewInformation); |
73 | 75 | initializeObjectAttributeEditors($this->viewInformation); |
74 | 76 | |
75 | | - $definedMeaningId = $this->getDefinedMeaningID(); |
| 77 | + # Nice try sherlock, but we really need to get our DMID from elsewhere |
| 78 | + #$definedMeaningId = $this->getDefinedMeaningID(); |
76 | 79 | |
| 80 | + #Need 3 steps: copy defining expression, create new dm, then update |
| 81 | + |
| 82 | + $expression=$this->dupDefiningExpression(); |
| 83 | + # to make the expression really work, we may need to call |
| 84 | + # more here? |
| 85 | + |
| 86 | + # shouldn't this stuff be protected? |
| 87 | + $expressionId=$expression->id; |
| 88 | + $languageId=$expression->languageId; |
| 89 | + $text="Copied Defined Meaning"; // this might work for now |
| 90 | + // but where to get useful |
| 91 | + // text? |
| 92 | + |
| 93 | + #here we assume the DM is not there yet.. not entirely wise |
| 94 | + #in the long run. |
| 95 | + $definedMeaningId=createNewDefinedMeaning($expressionId, $langaugeId, $text); |
| 96 | + |
77 | 97 | getDefinedMeaningEditor($this->viewInformation)->save( |
78 | 98 | $this->getIdStack($definedMeaningId), |
79 | 99 | $this->getRecord() |
— | — | @@ -95,6 +115,7 @@ |
96 | 116 | } |
97 | 117 | |
98 | 118 | /*horrible cannibalised hack. Use at own risk*/ |
| 119 | + /* this particular function doesn't actually work yet */ |
99 | 120 | public function saveWithinTransaction() { |
100 | 121 | global |
101 | 122 | $wgTitle, $wgUser, $wgRequest; |
— | — | @@ -126,6 +147,19 @@ |
127 | 148 | public function getDefinedMeaningID() { |
128 | 149 | return $this->definedMeaningID; |
129 | 150 | } |
| 151 | + |
| 152 | + /** Attempts to save defining expression if it does not exist "here" |
| 153 | + * (This works right now because we override the datasetcontext in |
| 154 | + * SaveDM.php . dc should be handled more solidly) */ |
| 155 | + protected function dupDefiningExpression() { |
130 | 156 | |
| 157 | + $record=$this->getRecord(); |
| 158 | + $expression=$record->getValue("defined-meaning-full-defining-expression"); |
| 159 | + |
| 160 | + $spelling=$expression->getValue("defined-meaning-defining-expression"); |
| 161 | + $language=$expression->getValue("language"); |
| 162 | + return findOrCreateExpression($spelling, $language); |
| 163 | + } |
| 164 | + |
131 | 165 | } |
132 | 166 | |
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php |
— | — | @@ -28,6 +28,15 @@ |
29 | 29 | return @$this->values[$attribute->id]; |
30 | 30 | } |
31 | 31 | |
| 32 | + /** |
| 33 | + * Obtains a value based on the provided key. |
| 34 | + * In future, this should check against an attributes global with string |
| 35 | + * lookup, and might even be smart. |
| 36 | + * For now, this just does a direct lookup. |
| 37 | + */ |
| 38 | + public function getValue ($key) { |
| 39 | + return @$this->values[$key]; |
| 40 | + } |
32 | 41 | |
33 | 42 | public function project(Structure $structure) { |
34 | 43 | $result = project($this, $structure); |
— | — | @@ -72,11 +81,12 @@ |
73 | 82 | $str=$this->getStructure(); |
74 | 83 | $type=$str->getStructureType(); |
75 | 84 | $rv.="$key:ArrayRecord(..., $type) {"; |
76 | | - $rv2=$rv; |
| 85 | + $comma=$rv; |
77 | 86 | foreach ($this->values as $key=>$value) { |
78 | | - $rv=$rv2; |
| 87 | + $rv=$comma; |
| 88 | + $repr="$key:$value"; |
| 89 | + #Duck typing (should refactor this to a has_attr() function); |
79 | 90 | $methods=get_class_methods(get_class($value)); |
80 | | - $repr="$key:$value"; |
81 | 91 | if (!is_null($methods)) { |
82 | 92 | if (in_array("tostring_indent",$methods)) { |
83 | 93 | $repr=$value->tostring_indent($depth+1,$key); |
— | — | @@ -84,8 +94,8 @@ |
85 | 95 | } |
86 | 96 | $rv.=$repr; |
87 | 97 | |
88 | | - $rv2=$rv; |
89 | | - $rv2.=", "; |
| 98 | + $comma=$rv; |
| 99 | + $comma.=", "; |
90 | 100 | } |
91 | 101 | $rv.="}"; |
92 | 102 | return $rv; |
Index: trunk/extensions/Wikidata/OmegaWiki/SaveDM.php |
— | — | @@ -51,8 +51,15 @@ |
52 | 52 | |
53 | 53 | $record=$model->getRecord(); |
54 | 54 | echo $record; |
55 | | -echo $record->getAttributeValue(new Attribute("defined-meaning-full-defining-expression")); |
| 55 | +$defexp=$record->getValue("defined-meaning-full-defining-expression"); |
| 56 | +echo $defexp."\n"; |
| 57 | +#$expid=$record->getAttributeValue(new Attribute("expression-id")); |
| 58 | +$id=$defexp->getValue("expression-id"); |
| 59 | +$spelling=$defexp->getValue("defined-meaning-defining-expression"); |
| 60 | +$language=$defexp->getValue("language"); |
56 | 61 | |
| 62 | +echo "id: $id, spelling:$spelling, language:$language"; |
| 63 | + |
57 | 64 | $endTime = time(); |
58 | 65 | echo("\n\nTime elapsed: " . durationToString($endTime - $beginTime)); |
59 | 66 | |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -154,10 +154,7 @@ |
155 | 155 | } |
156 | 156 | |
157 | 157 | function findExpression($spelling, $languageId) { |
158 | | - wfDebug( "findExpression $spelling" ); |
159 | 158 | if ($expressionId = getExpressionId($spelling, $languageId)){ |
160 | | - //wfDebug( "expression $spelling found in database" ); |
161 | | - //exit(); |
162 | 159 | return new Expression($expressionId, $spelling, $languageId); |
163 | 160 | } |
164 | 161 | else{ |
— | — | @@ -178,6 +175,8 @@ |
179 | 176 | return createExpression($spelling, $languageId); |
180 | 177 | } |
181 | 178 | |
| 179 | + |
| 180 | + |
182 | 181 | function getSynonymId($definedMeaningId, $expressionId) { |
183 | 182 | $dc=wdGetDataSetContext(); |
184 | 183 | $dbr =& wfGetDB(DB_SLAVE); |