r24142 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24141‎ | r24142 | r24143 >
Date:01:26, 16 July 2007
Author:kim
Status:old
Tags:
Comment:
http://xkcd.com/c208.html :-D

Modified OmegaWikiAttributes using regexps and a slightly broken FSA
(much better on ye olde wrists ;-) )

New system works fine, and ... immediately caught 2 new bugs.
I *think* I made the right corrections, please check.

Now to implement in other files.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/small/replace_attribs.pl (added) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -30,9 +30,8 @@
3131 * to talk directly with the DB layer.
3232 * -this is what RecordHelpers are for.
3333 */
34 -
3534 function initializeOmegaWikiAttributes(ViewInformation $viewInformation){
36 - global
 35+ global
3736 $omegaWikiAttributes; // It would be even better if this was
3837 // passed to objects explicitly
3938 // but one step at a time...
@@ -374,57 +373,278 @@
375374
376375 global
377376 $wgLanguageAttributeName, $wgSpellingAttributeName, $wgTextAttributeName;
378 -
 377+
379378 $t->language = new Attribute("language", $wgLanguageAttributeName, "language");
380379 $t->spelling = new Attribute("spelling", $wgSpellingAttributeName, "spelling");
381 - $t->text= new Attribute("text", $wgTextAttributeName, "text");
 380+ $t->text = new Attribute("text", $wgTextAttributeName, "text");
382381
383 - /*
384 - $a->definedMeaningAttributes = new Attribute("defined-meaning-attributes", $wgDefinedMeaningAttributesAttributeName, "will-be-specified-below");
385 - $a["objectAttributes"] = new Attribute("object-attributes", $wgAnnotationAttributeName, "will-be-specified-below");
386 -
387 - # TODO replace with i18n
388382 global
389 - $expressionIdAttribute, $identicalMeaningAttribute;
 383+ $wgDefinedMeaningAttributesAttributeName,
 384+ $wgDefinedMeaningAttributesAttributeName, $wgDefinedMeaningAttributesAttributeId, $wgAnnotationAttributeName;
390385
391 - $a["expressionId"] = new Attribute("expression-id", "Expression Id", "expression-id");
392 - $a["identicalMeaning"] = new Attribute("indentical-meaning", $wgIdenticalMeaningAttributeName, "boolean");
 386+ $t->definedMeaningAttributes = new Attribute("defined-meaning-attributes", $wgDefinedMeaningAttributesAttributeName, "will-be-specified-below");
 387+ $t->objectAttributes = new Attribute("object-attributes", $wgAnnotationAttributeName, "will-be-specified-below");
393388
394 - #TODO replace with i18n
395389 global
396 - $wgExpressionAttributeName;
 390+ $wgIdenticalMeaningAttributeName;
 391+
 392+ $t->expressionId = new Attribute("expression-id", "Expression Id", "expression-id");
 393+ $t->identicalMeaning = new Attribute("indentical-meaning", $wgIdenticalMeaningAttributeName, "boolean");
397394
 395+ global
 396+ $wgExpressionAttributeName;
 397+
398398 if ($viewInformation->filterOnLanguage())
399 - $a["expression"] = new Attribute("expression", $wgSpellingAttributeName, "spelling");
 399+ $t->expression = new Attribute("expression", $wgSpellingAttributeName, "spelling");
400400 else {
401 - $a["expressionStructure"] = new Structure("expression", $this->language, $this->spelling);
402 - $a["expression"] = new Attribute(null, $wgExpressionAttributeName, $expressionStructure);
 401+ $t->expressionStructure = new Structure("expression", $t->language, $t->spelling);
 402+ $t->expression = new Attribute(null, $wgExpressionAttributeName, $t->expressionStructure);
403403 }
404404
 405+ $t->definedMeaningId = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id");
 406+ $t->definedMeaningDefiningExpression = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text");
 407+
 408+ $t->definedMeaningCompleteDefiningExpressionStructure =
 409+ new Structure("defined-meaning-full-defining-expression",
 410+ $t->definedMeaningDefiningExpression,
 411+ $t->expressionId,
 412+ $t->language
 413+ );
 414+
 415+ $t->definedMeaningCompleteDefiningExpression=new Attribute(null, "Defining expression", $t->definedMeaningCompleteDefiningExpressionStructure);
 416+
 417+
 418+
405419 global
406 - $definedMeaningIdAttribute, $definedMeaningDefiningExpressionAttribute,
407 - $definedMeaningCompleteDefiningExpressionStructure,
408 - $definedMeaningCompleteDefiningExpressionAttribute;
 420+ $definedMeaningReferenceType, $wgDefinedMeaningReferenceAttributeName;
 421+
 422+ $t->definedMeaningLabel = new Attribute("defined-meaning-label", "Defined meaning label", "short-text");
 423+ $t->definedMeaningReferenceStructure = new Structure("defined-meaning", $t->definedMeaningId, $t->definedMeaningLabel, $t->definedMeaningDefiningExpression);
 424+
 425+ $definedMeaningReferenceType = $t->definedMeaningReferenceStructure;
 426+ $t->definedMeaningReference = new Attribute(null, $wgDefinedMeaningReferenceAttributeName, $definedMeaningReferenceType);
409427
410 - $a["definedMeaningId"] = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id");
411 - $a["definedMeaningDefiningExpression"] = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text");
 428+ global
 429+ $wgCollectionAttributeName, $wgSourceIdentifierAttributeName, $wgGotoSourceAttributeName;
 430+
 431+ $t->collectionId = new Attribute("collection", "Collection", "collection-id");
 432+ $t->collectionMeaning = new Attribute("collection-meaning", $wgCollectionAttributeName, $t->definedMeaningReferenceStructure);
 433+ $t->sourceIdentifier = new Attribute("source-identifier", $wgSourceIdentifierAttributeName, "short-text");
 434+ $t->gotoSourceStructure = new Structure("goto-source",$t->collectionId, $t->sourceIdentifier);
 435+ $t->gotoSource = new Attribute(null, $wgGotoSourceAttributeName, $t->gotoSourceStructure);
 436+
 437+ global
 438+ $wgCollectionMembershipAttributeName, $wgCollectionMembershipAttributeId;
 439+
 440+ $t->collectionMembershipStructure = new Structure("collection-membership",$t->collectionId, $t->collectionMeaning, $t->sourceIdentifier);
 441+ $t->collectionMembership = new Attribute(null, $wgCollectionMembershipAttributeName, $t->collectionMembershipStructure);
 442+
 443+ $t->classMembershipId = new Attribute("class-membership-id", "Class membership id", "integer");
 444+ $t->class = new Attribute("class", "Class", $t->definedMeaningReferenceStructure);
 445+
 446+ global
 447+ $wgClassMembershipAttributeName, $wgClassMembershipAttributeId;
 448+
 449+ $t->classMembershipStructure = new Structure("class-membership", $t->classMembershipId, $t->class);
 450+ $t->classMembership = new Attribute(null, $wgClassMembershipAttributeName, $t->classMembershipStructure);
 451+
 452+ global
 453+ $wgPossibleSynonymAttributeName,
 454+ $wgPossiblySynonymousAttributeName, $wgPossiblySynonymousAttributeId;
 455+
 456+ $t->possiblySynonymousId = new Attribute("possibly-synonymous-id", "Possibly synonymous id", "integer");
 457+ $t->possibleSynonym = new Attribute("possible-synonym", $wgPossibleSynonymAttributeName, $t->definedMeaningReferenceStructure);
 458+ # Bug found ... This never worked before: (!)
 459+ #$t->possiblySynonymousStructure = new Structure("possibly-synonymous", $t->possiblySynonymousId, $t->possiblySynonymous);
 460+ $t->possiblySynonymousStructure = new Structure("possibly-synonymous", $t->possiblySynonymousId, $t->possibleSynonym);
 461+ $t->possiblySynonymous = new Attribute(null, $wgPossiblySynonymousAttributeName, $t->possiblySynonymousStructure);
412462
413 - $a["definedMeaningCompleteDefiningExpressionStructure"] =
414 - new Structure("defined-meaning-full-defining-expression",
415 - $definedMeaningDefiningExpressionAttribute,
416 - $expressionIdAttribute,
417 - $
 463+ global
 464+ $relationTypeType,
 465+ $wgRelationTypeAttributeName, $wgOtherDefinedMeaningAttributeName;
 466+
 467+ $t->relationId = new Attribute("relation-id", "Relation identifier", "object-id");
 468+ $t->relationType = new Attribute("relation-type", $wgRelationTypeAttributeName, $t->definedMeaningReferenceStructure);
 469+ $t->otherDefinedMeaning = new Attribute("other-defined-meaning", $wgOtherDefinedMeaningAttributeName, $definedMeaningReferenceType);
 470+
 471+ global
 472+ $wgRelationsAttributeName, $wgIncomingRelationsAttributeName, $wgRelationsAttributeId, $wgIncomingRelationsAttributeId ;
 473+
 474+ $t->relationStructure = new Structure("relations", $t->relationId, $t->relationType, $t->otherDefinedMeaning, $t->objectAttributes);
 475+ $t->relations = new Attribute(null, $wgRelationsAttributeName, $t->relationStructure);
 476+ $t->reciprocalRelations = new Attribute("reciprocal-relations", $wgIncomingRelationsAttributeName, $t->relationStructure);
 477+
 478+ $t->translatedTextId = new Attribute("translated-text-id", "Translated text ID", "integer");
 479+ $t->translatedTextStructure = new Structure("translated-text", $t->language, $t->text);
 480+
 481+ global
 482+ $wgAlternativeDefinitionAttributeName, $wgSourceAttributeName;
 483+
 484+ $t->definitionId = new Attribute("definition-id", "Definition identifier", "integer");
 485+
 486+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
 487+ $t->alternativeDefinition = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, "text");
 488+ else
 489+ $t->alternativeDefinition = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, $t->translatedTextStructure);
 490+
 491+ $t->source = new Attribute("source-id", $wgSourceAttributeName, $definedMeaningReferenceType);
 492+
 493+ global
 494+ $wgAlternativeDefinitionsAttributeName, $wgAlternativeDefinitionsAttributeId;
 495+
 496+ $t->alternativeDefinitionsStructure = new Structure("alternative-definitions", $t->definitionId, $t->alternativeDefinition, $t->source);
 497+
 498+ $t->alternativeDefinitions = new Attribute(null, $wgAlternativeDefinitionsAttributeName, $t->alternativeDefinitionsStructure);
 499+
 500+ global
 501+ $wgSynonymsAttributeName, $wgSynonymsAndTranslationsAttributeName, $wgSynonymsAndTranslationsAttributeId;
 502+
 503+ if ($viewInformation->filterOnLanguage())
 504+ $synonymsAndTranslationsCaption = $wgSynonymsAttributeName;
 505+ else
 506+ $synonymsAndTranslationsCaption = $wgSynonymsAndTranslationsAttributeName;
 507+
 508+ $t->syntransId = new Attribute("syntrans-id", "$synonymsAndTranslationsCaption identifier", "integer");
 509+ $t->synonymsTranslationsStructure = new Structure("synonyms-translations", $t->syntransId, $t->expression, $t->identicalMeaning, $t->objectAttributes);
 510+ $t->synonymsAndTranslations = new Attribute(null, "$synonymsAndTranslationsCaption", $t->synonymsTranslationsStructure);
 511+
 512+ global
 513+ $wgTranslatedTextAttributeValuesAttributeName, $wgTranslatedTextAttributeAttributeName, $wgTranslatedTextAttributeValueAttributeName;
 514+
 515+ $t->translatedTextAttributeId = new Attribute("translated-text-attribute-id", "Attribute identifier", "object-id");
 516+ $t->translatedTextAttributeObject = new Attribute("translated-text-attribute-object-id", "Attribute object", "object-id");
 517+ $t->translatedTextAttribute = new Attribute("translated-text-attribute", $wgTranslatedTextAttributeAttributeName, $definedMeaningReferenceType);
 518+ $t->translatedTextValueId = new Attribute("translated-text-value-id", "Translated text value identifier", "translated-text-value-id");
 519+
 520+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
 521+ $t->translatedTextValue = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, "text");
 522+ else
 523+ $t->translatedTextValue = new Attribute("translated-text", $wgTranslatedTextAttributeValueAttributeName, $t->translatedTextStructure);
 524+
 525+ $t->translatedTextAttributeValuesStructure = new Structure("translated-text-attribute-values",$t->translatedTextAttributeId, $t->translatedTextAttributeObject, $t->translatedTextAttribute, $t->translatedTextValueId, $t->translatedTextValue, $t->objectAttributes);
 526+ $t->translatedTextAttributeValues = new Attribute(null, $wgTranslatedTextAttributeValuesAttributeName, $t->translatedTextAttributeValuesStructure);
 527+
 528+ global
 529+ $wgTextAttributeValuesAttributeName, $wgTextAttributeAttributeName;
 530+
 531+ $t->textAttributeId = new Attribute("text-attribute-id", "Attribute identifier", "object-id");
 532+ $t->textAttributeObject = new Attribute("text-attribute-object-id", "Attribute object", "object-id");
 533+ $t->textAttribute = new Attribute("text-attribute", $wgTextAttributeAttributeName, $t->definedMeaningReferenceStructure);
 534+ $t->textAttributeValuesStructure = new Structure("text-attribute-values", $t->textAttributeId, $t->textAttributeObject, $t->textAttribute, $t->text, $t->objectAttributes);
 535+ $t->textAttributeValues = new Attribute(null, $wgTextAttributeValuesAttributeName, $t->textAttributeValuesStructure);
 536+
 537+ global
 538+ $wgLinkAttributeValuesAttributeName, $wgLinkAttributeAttributeName;
 539+
 540+ $t->linkLabel = new Attribute("label", "Label", "short-text");
 541+ $t->linkURL = new Attribute("url", "URL", "url");
 542+ $t->link = new Attribute("link", "Link", new Structure($t->linkLabel, $t->linkURL));
 543+
 544+ $t->linkAttributeId = new Attribute("link-attribute-id", "Attribute identifier", "object-id");
 545+ $t->linkAttributeObject = new Attribute("link-attribute-object-id", "Attribute object", "object-id");
 546+ $t->linkAttribute = new Attribute("link-attribute", $wgLinkAttributeAttributeName, $t->definedMeaningReferenceStructure);
 547+ $t->linkAttributeValuesStructure = new Structure("link-attribute-values", $t->linkAttributeId, $t->linkAttributeObject, $t->linkAttribute, $t->link, $t->objectAttributes);
 548+ $t->linkAttributeValues = new Attribute(null, $wgLinkAttributeValuesAttributeName, $t->linkAttributeValuesStructure);
 549+
 550+ global
 551+ $wgOptionAttributeAttributeName, $wgOptionAttributeOptionAttributeName, $wgOptionAttributeValuesAttributeName;
 552+
 553+ $t->optionAttributeId = new Attribute('option-attribute-id', 'Attribute identifier', 'object-id');
 554+ $t->optionAttributeObject = new Attribute('option-attribute-object-id', 'Attribute object', 'object-id');
 555+ $t->optionAttribute = new Attribute('option-attribute', $wgOptionAttributeAttributeName, $definedMeaningReferenceType);
 556+ $t->optionAttributeOption = new Attribute('option-attribute-option', $wgOptionAttributeOptionAttributeName, $definedMeaningReferenceType);
 557+ $t->optionAttributeValuesStructure = new Structure('option-attribute-values', $t->optionAttributeId, $t->optionAttribute, $t->optionAttributeObject, $t->optionAttributeOption, $t->objectAttributes);
 558+ $t->optionAttributeValues = new Attribute(null, $wgOptionAttributeValuesAttributeName, $t->optionAttributeValuesStructure);
 559+
 560+ global
 561+ $wgOptionAttributeOptionsAttributeName;
 562+
 563+ $t->optionAttributeOptionId = new Attribute('option-attribute-option-id', 'Option identifier', 'object-id');
 564+ $t->optionAttributeOptionsStructure = new Structure('option-attribute-options', $t->optionAttributeOptionId, $t->optionAttribute, $t->optionAttributeOption, $t->language);
 565+ $t->optionAttributeOptions = new Attribute(null, $wgOptionAttributeOptionsAttributeName, $t->optionAttributeOptionsStructure);
 566+
 567+ global
 568+ $wgDefinitionAttributeName, $wgTranslatedTextAttributeName;
 569+
 570+ if ($viewInformation->filterOnLanguage() && !$viewInformation->hasMetaDataAttributes())
 571+ $t->translatedText = new Attribute("translated-text", $wgTextAttributeName, "text");
 572+ else
 573+ $t->translatedText = new Attribute(null, $wgTranslatedTextAttributeName, $t->translatedTextStructure);
 574+
 575+ $t->definition = new Attribute(null, $wgDefinitionAttributeName, new Structure("definition", $t->translatedText, $t->objectAttributes));
 576+
 577+ global
 578+ $wgClassAttributeAttributeAttributeName, $wgClassAttributeLevelAttributeName,
 579+ $wgClassAttributeTypeAttributeName, $wgClassAttributesAttributeName, $wgClassAttributesAttributeId;
 580+
 581+ $t->classAttributeId = new Attribute("class-attribute-id", "Class attribute identifier", "object-id");
 582+ $t->classAttributeAttribute = new Attribute("class-attribute-attribute", $wgClassAttributeAttributeAttributeName, $t->definedMeaningReferenceStructure);
 583+ $t->classAttributeLevel = new Attribute("class-attribute-level", $wgClassAttributeLevelAttributeName, $t->definedMeaningReferenceStructure);
 584+ $t->classAttributeType = new Attribute("class-attribute-type", $wgClassAttributeTypeAttributeName, "short-text");
 585+ $t->classAttributesStructure = new Structure("class-attributes", $t->classAttributeId, $t->classAttributeAttribute, $t->classAttributeLevel, $t->classAttributeType, $t->optionAttributeOptions);
 586+ $t->classAttributes = new Attribute(null, $wgClassAttributesAttributeName, $t->classAttributesStructure);
 587+
 588+ global
 589+ $wgDefinedMeaningAttributeName;
 590+
 591+ $t->definedMeaning = new Attribute(null, $wgDefinedMeaningAttributeName,
 592+ new Structure(
 593+ "defined-meaning",
 594+ $t->definition,
 595+ $t->classAttributes,
 596+ $t->alternativeDefinitions,
 597+ $t->synonymsAndTranslations,
 598+ $t->relations,
 599+ $t->reciprocalRelations,
 600+ $t->classMembership,
 601+ $t->collectionMembership,
 602+ $t->definedMeaningAttributes)
418603 );
419 - $a["definedMeaningCompleteDefiningExpression"]=new Attribute(null, "Defining expression", $definedMeaningCompleteDefiningExpressionStructure);
 604+
 605+ global
 606+ $wgExactMeaningsAttributeName, $wgApproximateMeaningsAttributeName;
 607+
 608+ $t->expressionMeaningStructure = new Structure("expression-exact-meanings", $t->definedMeaningId, $t->text, $t->definedMeaning);
 609+ $t->expressionExactMeanings = new Attribute(null, $wgExactMeaningsAttributeName, $t->expressionMeaningStructure);
 610+ $t->expressionApproximateMeanings = new Attribute("expression-approximate-meanings", $wgApproximateMeaningsAttributeName, $t->expressionMeaningStructure);
 611+
 612+ global
 613+ $wgExpressionMeaningsAttributeName, $wgExpressionsAttributeName;
 614+
 615+ # bug found here also: $t->expressionAoproximateMeaning_S_
 616+ $t->expressionMeaningsStructure = new Structure("expression-meanings", $t->expressionExactMeanings, $t->expressionApproximateMeanings);
 617+ $t->expressionMeanings = new Attribute(null, $wgExpressionMeaningsAttributeName, $t->expressionMeaningsStructure);
 618+
 619+ $t->expressionsStructure = new Structure("expressions", $t->expressionId, $t->expression, $t->expressionMeanings);
 620+ $t->expressions = new Attribute(null, $wgExpressionsAttributeName, $t->expressionsStructure);
 621+
 622+ global
 623+ $wgAnnotationAttributeName;
 624+
 625+ $t->objectId = new Attribute("object-id", "Object identifier", "object-id");
 626+ $t->objectAttributesStructure = new Structure("object-attributes", $t->objectId, $t->textAttributeValues, $t->translatedTextAttributeValues, $t->optionAttributeValues);
 627+ $t->objectAttributes->setAttributeType($t->objectAttributesStructure);
 628+ $t->definedMeaningAttributes->setAttributeType($t->objectAttributesStructure);
 629+
 630+ $t->annotatedAttributes = array(
 631+ $t->definition,
 632+ $t->synonymsAndTranslations,
 633+ $t->relations,
 634+ $t->reciprocalRelations
420635 );
421 - */
 636+
 637+ foreach ($viewInformation->getPropertyToColumnFilters() as $propertyToColumnFilter) {
 638+ $attribute = $propertyToColumnFilter->getAttribute();
 639+ $attribute->setAttributeType($t->objectAttributesStructure);
 640+
 641+ foreach ($t->annotatedAttributes as $annotatedAttribute)
 642+ $annotatedAttribute->type->addAttribute($attribute);
 643+ }
422644 }
423645
424 -
425646 protected function __set($key,$value) {
426647 $attributes=&$this->attributes;
427648 $attributes[$key]=$value;
428 -
429649 }
430650
431651 public function __get($key) {
Index: trunk/extensions/Wikidata/OmegaWiki/small/replace_attribs.pl
@@ -0,0 +1,30 @@
 2+#!/usr/bin/perl
 3+
 4+# seeks out the attributes globals and replaces them with rather more sane code
 5+# (currently only used on OmegaWikiAttributes)
 6+# still leaves a small amount of mess at times (since I'm running line-by line, which I really
 7+# probably shouldn't, should probably go statement-by-statement instead)
 8+
 9+
 10+$global=0; # state variable: are we inside a (multiline?) php 'global' statement?
 11+
 12+while(<>) {
 13+ if (/global/) {
 14+ $global=1; #start of global statement
 15+ }
 16+
 17+ if ($global) {
 18+ s/\$(\w+)(Attributes?|Structure)\;/;/g;
 19+ s/\$(\w+)(Attributes?|Structure)\W//g;
 20+ s/^\s*$//; # remove empty lines
 21+ }
 22+
 23+ if (/\;/) {
 24+ $global=0; # end of global statement
 25+ }
 26+
 27+ s/\$(\w+)Attribute(\W)/\$t\-\>$1$2/g;
 28+ s/\$(\w+)Attributes(\W)/\$t\-\>$1Attributes$2/g;
 29+ s/\$(\w+)Structure(\W)/\$t\-\>$1Structure$2/g;
 30+ print
 31+}
Property changes on: trunk/extensions/Wikidata/OmegaWiki/small/replace_attribs.pl
___________________________________________________________________
Added: svn:executable
132 + *

Status & tagging log