r19774 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r19773‎ | r19774 | r19775 >
Date:00:35, 5 February 2007
Author:erik
Status:old
Tags:
Comment:
rename remaining files; move obsolete perl-tools to separate dir
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Import+WiktionaryZ.pl (deleted) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WiktionaryZ.php (deleted) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WiktionaryZ.pm (deleted) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WiktionaryZAttributes.php (deleted) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WiktionaryZEditors.php (deleted) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WiktionaryZRecordSets.php (deleted) (history)
  • /trunk/extensions/Wikidata/perl-tools (added) (history)
  • /trunk/extensions/Wikidata/perl-tools/Import+WiktionaryZ.pl (added) (history)
  • /trunk/extensions/Wikidata/perl-tools/README (added) (history)
  • /trunk/extensions/Wikidata/perl-tools/WiktionaryZ.pm (added) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/perl-tools/Import WiktionaryZ.pl
@@ -0,0 +1,55 @@
 2+use WiktionaryZ;
 3+use POSIX qw(strftime);
 4+
 5+my $startTime = time;
 6+
 7+# Example usage to import UMLS completely into an existing WiktionaryZ database:
 8+# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
 9+# $importer->setSourceDB('umls');
 10+# $importer->initialize;
 11+# $importer->importCompleteUMLS();
 12+
 13+# Example usage to import a part of UMLS into an existing WiktionaryZ database:
 14+# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
 15+# $importer->setSourceDB('umls');
 16+# $importer->initialize;
 17+# my %sourceAbbreviations = $importer->loadSourceAbbreviations();
 18+# delete($sourceAbbreviations{"MSH"});
 19+# $importer->importUMLS(\%sourceAbbreviations);
 20+
 21+my $importer=new WiktionaryZ('wikidata_icpc','root','');
 22+$importer->setSourceDB('umls');
 23+#$importer->setSourceDB('swissprot');
 24+$importer->initialize;
 25+#$importer->importCompleteUMLS();
 26+
 27+#read the source abbreviations and remove those you do not wish to import
 28+my %sourceAbbreviations = $importer->loadSourceAbbreviations();
 29+my @deleteList;
 30+while (($key, $val) = each(%sourceAbbreviations)) {
 31+
 32+#remove all that contains "MSH":
 33+# if (index($key,"MSH") >= 0) {
 34+# push(@deleteList, $key);
 35+# }
 36+
 37+#remove all that does not contain "ICPC":
 38+ if (index($key,"ICPC") < 0) {
 39+ push(@deleteList, $key);
 40+ }
 41+}
 42+
 43+foreach $sab (@deleteList){
 44+ delete($sourceAbbreviations{$sab});
 45+}
 46+
 47+$importer->importUMLS(\%sourceAbbreviations);
 48+
 49+
 50+my $endTime = time;
 51+print "\n";
 52+print "Import started at: " . (strftime "%H:%M:%S", localtime($startTime)) . "\n";
 53+print "Import ended at: " . (strftime "%H:%M:%S", localtime($endTime)) . "\n";
 54+print "Elapsed time: " . (strftime "%H:%M:%S", gmtime($endTime - $startTime)) . "\n";
 55+
 56+exit 0;
\ No newline at end of file
Index: trunk/extensions/Wikidata/perl-tools/WiktionaryZ.pm
@@ -0,0 +1,1063 @@
 2+# Example usage to import UMLS into an existing WiktionaryZ database:
 3+# use WiktionaryZ;
 4+# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
 5+# $importer->setSourceDB('umls');
 6+# $importer->initialize;
 7+# $importer->importCompleteUMLS();
 8+#
 9+# NOTE: When importing UMLS, we expect the presence of the semantic network data
 10+# in the tables SRDEF and the manually created tables SEMRELHIER and SEMTYPEHIER.
 11+# SEMRELHIER and SEMTYPEHIER contain information about the relations between
 12+# semantic types and relation types, using RB as the code for "broader than"
 13+# and RN for "narrower than".
 14+#
 15+# Todo for UMLS:
 16+# SyntransCollection
 17+# RelationCollection
 18+# Fully deal with alternative definitions referring to the same concept
 19+# Deal with preferred lexical expressions, primary concepts (general weighting mechanism?)
 20+
 21+package WiktionaryZ;
 22+use DBI;
 23+use Encode;
 24+use POSIX qw(strftime);
 25+
 26+sub new {
 27+ my $type=shift;
 28+ my $self={};
 29+ $self->{targetdb}=shift;
 30+ $self->{targetuser}=shift;
 31+ $self->{targetpass}=shift;
 32+ $self->{targethost}=shift || 'localhost';
 33+ $self->{targetport}=shift || '3306';
 34+ $self->{targetdriver}=shift || 'mysql';
 35+ bless($self, $type);
 36+ return($self);
 37+}
 38+
 39+sub setSourceDB {
 40+ my $self=shift;
 41+ $self->{sourcedb}=shift;
 42+ $self->{sourceuser}=shift || $self->{targetuser};
 43+ $self->{sourcepass}=shift || $self->{targetpass};
 44+ $self->{sourcehost}=shift || $self->{targethost};
 45+ $self->{sourceport}=shift || $self->{targetport};
 46+ $self->{sourcedriver}=shift || $self->{targetdriver};
 47+}
 48+
 49+sub connectSourceDB {
 50+ my $self=shift;
 51+ my $dsn = 'dbi:'.$self->{sourcedriver}.':'.$self->{sourcedb}.':'.$self->{sourcehost}.':'.$self->{sourceport};
 52+ $self->{dbs}=DBI->connect($dsn,$self->{sourceuser},$self->{sourcepass});
 53+}
 54+
 55+sub connectTargetDB {
 56+ my $self=shift;
 57+ my $dsn = 'dbi:'.$self->{targetdriver}.':'.$self->{targetdb}.':'.$self->{targethost}.':'.$self->{targetport};
 58+ $self->{dbt}=DBI->connect($dsn,$self->{targetuser},$self->{targetpass});
 59+}
 60+
 61+sub connectDBs() {
 62+ my $self = shift;
 63+
 64+ $self->connectSourceDB();
 65+ $self->connectTargetDB();
 66+}
 67+
 68+sub loadLanguages() {
 69+ my $self = shift;
 70+
 71+ my %la=$self->loadLangs();
 72+ $self->{la}=\%la;
 73+ my %la_iso=$self->loadLangsIso();
 74+ $self->{la_iso}=\%la_iso;
 75+}
 76+
 77+sub initialize {
 78+ my $self=shift;
 79+ $self->connectDBs();
 80+ $self->loadLanguages();
 81+}
 82+
 83+sub importCompleteUMLS {
 84+ my $self=shift;
 85+ my $level=shift || 0; # 0= complete; 1=reltypes+; 2=rel+
 86+
 87+ my %sourceAbbreviations = $self->loadSourceAbbreviations();
 88+ $self->importUMLS(\%sourceAbbreviations, $level);
 89+}
 90+
 91+sub importUMLS() {
 92+ my $self=shift;
 93+ my $sourceAbbreviationsReference = shift;
 94+ my $level=shift || 0; # 0= complete; 1=reltypes+; 2=rel+
 95+
 96+ my %sourceAbbreviations = %{$sourceAbbreviationsReference};
 97+ my %cid=$self->getOrCreateCollections(\%sourceAbbreviations);
 98+ $self->{cid}=\%cid;
 99+
 100+ if ($level<1){
 101+ while (($sourceAbbreviation, $collectionId) = each %cid) {
 102+ print "Import UMLS terms for $sourceAbbreviation\n";
 103+ $self->importUMLSterms($sourceAbbreviation, $collectionId);
 104+ }
 105+ }
 106+
 107+ if($level<2) {
 108+ print "Import UMLS relation types 'REL'\n";
 109+ $self->importUMLSrelationtypes('REL');
 110+ print "Import UMLS relation types 'RELA'\n";
 111+ $self->importUMLSrelationtypes('RELA');
 112+ }
 113+
 114+ if($level<3) {
 115+ while (($sourceAbbreviation, $collectionId) = each %cid) {
 116+ my %rt=$self->loadReltypes();
 117+ $self->{reltypes}=\%rt;
 118+ print "Import UMLS relations 'REL' for $sourceAbbreviation\n";
 119+ $self->importUMLSrelations('REL',$sourceAbbreviation);
 120+ print "Import UMLS relations 'RELA' for $sourceAbbreviation\n";
 121+ $self->importUMLSrelations('RELA',$sourceAbbreviation);
 122+ }
 123+ }
 124+
 125+ if($level<4) {
 126+ print "Import SN types 'STY'\n";
 127+ $self->importSNtypes('STY');
 128+ print "Import SN types 'RL'\n";
 129+ $self->importSNtypes('RL');
 130+ print "Import ST relations 'STY'\n";
 131+ $self->importSTrelations('STY');
 132+ print "Import ST relations 'RL'\n";
 133+ $self->importSTrelations('RL');
 134+ # $self->importSTrelations2();
 135+ }
 136+
 137+ if($level<5) {
 138+ while (($sourceAbbreviation, $collectionId) = each %cid) {
 139+ my %attribs=$self->loadAttributes();
 140+ $self->{attribs}=\%attribs;
 141+ print "Import UMLS types for $sourceAbbreviation\n";
 142+ $self->importUMLSstypes($sourceAbbreviation);
 143+ }
 144+ }
 145+}
 146+
 147+sub importGEMET {
 148+ my $self=shift;
 149+ $self->connectSourceDB();
 150+ $self->connectTargetDB();
 151+ my %la=$self->loadLangs();
 152+ $self->{la}=\%la;
 153+ my %cid=$self->bootstrapGemetCollection();
 154+ $self->{cid}=\%cid;
 155+ $self->initRel($self->{cid}{'GEMETREL'});
 156+ my %rt=$self->loadReltypes();
 157+ $self->{reltypes}=\%rt;
 158+ $self->importGemetTerms();
 159+ $self->importGemetRelations();
 160+ $self->importGemetThemes();
 161+}
 162+
 163+sub importUMLSstypes {
 164+ my $self=shift;
 165+ my $sab=shift;
 166+
 167+ my $getassocs=$self->{dbs}->prepare("select MRSTY.CUI, MRSTY.STY from MRCONSO,MRSTY where MRCONSO.SAB like ? and MRCONSO.CUI=MRSTY.CUI");
 168+ $getassocs->execute($sab);
 169+ while(my $row=$getassocs->fetchrow_hashref()) {
 170+ my %rv=$self->getMidForMember($row->{CUI});
 171+ my $att=$self->{attribs}{$row->{STY}};
 172+ #print "$rv{mid} is a $row->{STY} ($att)\n";
 173+ $self->addRelation($rv{rid},0,$rv{mid},$att, my $checkfordupes=1);
 174+ }
 175+}
 176+
 177+sub getCollections(){
 178+ my $self=shift;
 179+ my %cid;
 180+ $cid{'CRISP'}=$self->findCollection($self->findMeaning($self->findItem('CRISP Thesaurus, 2005',$self->{la}{'en'})));
 181+ $cid{'STY'}=$self->findCollection($self->findMeaning($self->findItem('Semantic Network 2005AC Semantic Types',$self->{la}{'en'})));
 182+ $cid{'RL'}=$self->findCollection($self->findMeaning($self->findItem('Semantic Network 2005AC Relation Types',$self->{la}{'en'})));
 183+ $cid{'REL'}=$self->findCollection($self->findMeaning($self->findItem('UMLS Relation Types 2005',$self->{la}{'en'})));
 184+ $cid{'RELA'}=$self->findCollection($self->findMeaning($self->findItem('UMLS Relation Attributes 2005',$self->{la}{'en'})));
 185+ $cid{'ICPC'}=$self->findCollection($self->findMeaning($self->findItem('The International Classification of Primary Care (ICPC), 1993',$self->{la}{'en'})));
 186+ $cid{'MESH'}=$self->findCollection($self->findMeaning($self->findItem('Medical Subject Headings (MeSH), 2005',$self->{la}{'en'})));
 187+# $cid{'SP'}=$self->findCollection($self->findMeaning($self->findItem('Swiss-Prot',$self->{la}{'en'})));
 188+ return %cid;
 189+}
 190+
 191+sub findCollection() {
 192+ my $self=shift;
 193+ my $mid=shift;
 194+ my $findcoll=$self->{dbt}->prepare("select collection_id from uw_collection_ns where collection_mid=? and is_latest=1");
 195+ $findcoll->execute($mid);
 196+ my $row=$findcoll->fetchrow_hashref();
 197+ return $row->{collection_id};
 198+}
 199+
 200+sub getCollection {
 201+ my $self = shift;
 202+ my $expression = shift;
 203+
 204+ return $self->findCollection($self->findMeaning($self->findExpressionId($expression,$self->{la}{'en'})));
 205+}
 206+
 207+sub bootstrapCollection {
 208+ my $self = shift;
 209+ my $expression = shift;
 210+ my $collectionType = shift;
 211+
 212+ %rv=$self->addExpression($expression,$self->{la}{'en'});
 213+ return $self->addCollection($rv{mid},$collectionType);
 214+}
 215+
 216+sub getOrCreateCollection {
 217+ my $self = shift;
 218+ my $expression = shift;
 219+
 220+ my $result = $self->getCollection($expression);
 221+
 222+ if (!$result) {
 223+ $result = $self->bootstrapCollection($expression, '');
 224+ }
 225+
 226+ return $result;
 227+}
 228+
 229+sub getOrCreateCollections {
 230+ my $self = shift;
 231+ my $sourceAbbreviationsReference = shift;
 232+ my %sourceAbbreviations = %{$sourceAbbreviationsReference};
 233+ my %cid;
 234+
 235+ while (($key, $value) = each %sourceAbbreviations) {
 236+ $cid{$key} = $self->getOrCreateCollection($value);
 237+ }
 238+
 239+ return %cid;
 240+}
 241+
 242+sub loadSourceAbbreviations {
 243+ my $self = shift;
 244+ my %sab;
 245+
 246+ my $dataset = $self->{dbs}->prepare("select * from mrsab");
 247+ $dataset->execute();
 248+ while (my $row = $dataset->fetchrow_hashref()) {
 249+ $sab{$row->{RSAB}} = $row->{SON};
 250+ }
 251+ return %sab;
 252+}
 253+
 254+# SEMTYPEHIER and SEMRELHIER contain only the is_a relationships, whereas
 255+# srstr contains all others
 256+# FIXME: only use SRSTR
 257+sub importSTrelations2 {
 258+ my $self=shift;
 259+ my $getrels=$self->{dbs}->prepare("select * from srstr where rel!='isa'");
 260+ $getrels->execute();
 261+ while(my $row=$getrels->fetchrow_hashref()) {
 262+ my %rv1=$self->getMidForMember($row->{TYPE1},$self->{cid}{'STY'});
 263+ my %rv2=$self->getMidForMember($row->{TYPE2},$self->{cid}{'STY'});
 264+ my $rtmid=$self->{reltypes}{$row->{REL}};
 265+ #print "Adding relation $row->{REL} ($rtmid) between $row->{TYPE1} and $row->{TYPE2}\n";
 266+ $self->addRelation($rv1{rid},$rtmid,$rv1{mid},$rv2{mid},my $checkfordupes=1);
 267+ }
 268+}
 269+
 270+
 271+sub importSTrelations {
 272+ my $self=shift;
 273+ my $which=shift;
 274+ my $table;
 275+ my $field1;
 276+ my $field2;
 277+ if($which eq 'STY') {
 278+ $table='semtypehier';
 279+ $field1='SEMTYPE1';
 280+ $field2='SEMTYPE2';
 281+ } elsif($which eq 'RL') {
 282+ $table='semrelhier';
 283+ $field1='RELTYPE1';
 284+ $field2='RELTYPE2';
 285+ }
 286+
 287+ my $gettypehier=$self->{dbs}->prepare("select * from $table");
 288+ $gettypehier->execute();
 289+ while(my $typehier=$gettypehier->fetchrow_hashref()) {
 290+ my %rv1=$self->getMidForMember($typehier->{$field1},$self->{cid}{$which});
 291+ my %rv2=$self->getMidForMember($typehier->{$field2},$self->{cid}{$which});
 292+ my $rtmid=$self->{reltypes}{$typehier->{RELATION}};
 293+ print "Adding relation $typehier->{RELATION} ($rtmid) between $typehier->{$field1} and $typehier->{$field2}\n";
 294+ $self->addRelation($rv1{rid},$rtmid,$rv1{mid},$rv2{mid},my $checkfordupes=1);
 295+ }
 296+}
 297+
 298+# $member_id - the collection-internal identifier for this member
 299+# $cid The collection in which to search for this member (optional)
 300+# Returns the DefinedMeaningID and the revision id
 301+sub getMidForMember {
 302+ my $self=shift;
 303+ my $member_id=shift;
 304+ my $cid=shift;
 305+ my %rv;
 306+ my $getmid;
 307+ if($cid) {
 308+ $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where collection_id=? and internal_member_id=? and is_latest_set=1 limit 1");
 309+ $getmid->execute($cid,$member_id);
 310+ } else {
 311+ $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where internal_member_id=? and is_latest_set=1 limit 1");
 312+ $getmid->execute($member_id);
 313+ }
 314+ my $member_mid=$getmid->fetchrow_hashref();
 315+ $rv{mid}=$member_mid->{member_mid};
 316+ $rv{rid}=$member_mid->{revision_id};
 317+ return %rv;
 318+
 319+}
 320+
 321+sub loadReltypes {
 322+ my $self=shift;
 323+ my %reltypes;
 324+ # Get the relation type
 325+ $getreltype=$self->{dbt}->prepare("select member_mid,internal_member_id from uw_collection_contents,uw_collection_ns where uw_collection_ns.collection_type='RELT' and uw_collection_ns.collection_id=uw_collection_contents.collection_id");
 326+ $getreltype->execute();
 327+ while (my $reltype=$getreltype->fetchrow_hashref()) {
 328+ $reltypes{$reltype->{internal_member_id}}=$reltype->{member_mid};
 329+ }
 330+ return %reltypes;
 331+}
 332+
 333+sub loadAttributes {
 334+ my $self=shift;
 335+ my %attributes;
 336+ $getatt=$self->{dbt}->prepare("select member_mid,internal_member_id from uw_collection_contents,uw_collection_ns where uw_collection_ns.collection_type='ATTR' and uw_collection_ns.collection_id=uw_collection_contents.collection_id");
 337+ $getatt->execute();
 338+ while (my $att=$getatt->fetchrow_hashref()) {
 339+ $attributes{$att->{internal_member_id}}=$att->{member_mid};
 340+ }
 341+ return %attributes;
 342+}
 343+
 344+
 345+# Get all SRDEF attributes
 346+# Get relations between SRDEF
 347+sub importSNtypes {
 348+ my $self=shift;
 349+ my $type=shift;
 350+ $getsemtypes=$self->{dbs}->prepare("select semtypeab,type,definition from srdef where type=?");
 351+ $getsemtypes->execute($type);
 352+ while (my $semtype=$getsemtypes->fetchrow_hashref()) {
 353+ my $type_expression=$semtype->{semtypeab};
 354+ my $type_code=$type_expression;
 355+ $type_expression=~s/_/ /g;
 356+ $type_expression=lc($type_expression);
 357+ my %rv=$self->addExpression($type_expression,$self->{la}{'en'},0,$self->{cid}{$type},$type_code);
 358+ $self->addMeaningText($rv{'rid'},$rv{'mid'},$semtype->{definition},undef,$self->{la}{'en'});
 359+ #print $type_expression." - $self->{cid}{$type} - $type_code\n";
 360+ }
 361+}
 362+
 363+sub importUMLSrelations {
 364+ my $self=shift;
 365+ my $which=shift; # REL or RELA
 366+ my $source=shift; # SAB as MySQL LIKE string
 367+ my $getrels;
 368+
 369+ if($which eq 'REL') {
 370+ $getrels=$self->{dbs}->prepare("select cui1,cui2,rel from MRREL where sab like ?");
 371+ } elsif($which eq 'RELA') {
 372+ $getrels=$self->{dbs}->prepare("select cui1,cui2,rela from MRREL where sab like ? and rela!=''");
 373+ }
 374+ $getrels->execute($source);
 375+ while(my $rel=$getrels->fetchrow_hashref()) {
 376+ my $relid=$rel->{lc($which)};
 377+ # These mean the same thing
 378+ if($relid eq 'CHD') {
 379+ $relid='RN';
 380+ } elsif($relid eq 'PAR') {
 381+ $relid='RB';
 382+ }
 383+ $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where internal_member_id=? and is_latest_set=1 limit 1");
 384+ # Note that the direction in UMLS is opposite to ours
 385+ $getmid->execute($rel->{cui2});
 386+ my $mid1=$getmid->fetchrow_hashref();
 387+ $getmid->execute($rel->{cui1});
 388+ my $mid2=$getmid->fetchrow_hashref();
 389+ # FIXME: We are ignoring term relations for now!
 390+ if(($mid1->{member_mid} && $mid2->{member_mid}) && ($mid1->{member_mid} != $mid2->{member_mid}) && $self->{reltypes}{$relid}) {
 391+ # Add the relation
 392+ #print "Found relation ".$relid." (".$self->{reltypes}{$relid}.") between ".$mid1->{member_mid}." and ".$mid2->{member_mid}.".\n";
 393+ $self->addRelation($mid1->{revision_id},$self->{reltypes}{$relid},$mid1->{member_mid},$mid2->{member_mid},my $checkfordupes=1);
 394+ } else {
 395+ if(!$mid1->{member_mid} && $mid2->{member_mid}) {
 396+ print "Did not find MID for ".$rel->{cui1}."!\n";
 397+ } elsif($mid1->{member_mid} && !$mid2->{member_mid}) {
 398+ print "Did not find MID for ".$rel->{cui2}."!\n";
 399+ } elsif(!$mid1->{member_mid} && !$mid2->{member_mid}) {
 400+ print "Did not find MIDs for ".$rel->{cui1}." and ".$rel->{cui2}."!\n";
 401+ }
 402+ }
 403+ }
 404+
 405+}
 406+
 407+
 408+sub bootstrapGemetCollection {
 409+ my $self=shift;
 410+ my %cid;
 411+ %rv=$self->addExpression('GEMET Environmental Thesaurus Relation Types',$self->{la}{'en'});
 412+ $cid{'GEMETREL'}=$self->addCollection($rv{mid},'RELT');
 413+ %rv=$self->addExpression('GEMET Environmental Thesaurus Relation Types',$self->{la}{'en'});
 414+ $cid{'GEMET'}=$self->addCollection($rv{mid},'');
 415+ return %cid;
 416+}
 417+
 418+
 419+sub bootstrapCollections {
 420+ my $self=shift;
 421+ my %cid;
 422+ my %rv;
 423+
 424+ %rv=$self->addExpression('CRISP Thesaurus, 2005',$self->{la}{'en'});
 425+ $cid{'CRISP'}=$self->addCollection($rv{mid},'');
 426+ %rv=$self->addExpression('Semantic Network 2005AC Semantic Types',$self->{la}{'en'});
 427+ $cid{'STY'}=$self->addCollection($rv{mid},'ATTR');
 428+ %rv=$self->addExpression('Semantic Network 2005AC Relation Types',$self->{la}{'en'});
 429+ $cid{'RL'}=$self->addCollection($rv{mid},'RELT');
 430+ %rv=$self->addExpression('UMLS Relation Types 2005',$self->{la}{'en'});
 431+ $cid{'REL'}=$self->addCollection($rv{mid},'RELT');
 432+ %rv=$self->addExpression('UMLS Relation Attributes 2005',$self->{la}{'en'});
 433+ $cid{'RELA'}=$self->addCollection($rv{mid},'RELT');
 434+ %rv=$self->addExpression('The International Classification of Primary Care (ICPC), 1993',$self->{la}{'en'});
 435+ $cid{'ICPC'}=$self->addCollection($rv{mid},'');
 436+ %rv=$self->addExpression('Medical Subject Headings (MeSH), 2005',$self->{la}{'en'});
 437+ $cid{'MESH'}=$self->addCollection($rv{mid},'');
 438+# %rv=$self->addExpression('Swiss-Prot',$self->{la}{'en'});
 439+# $cid{'SP'}=$self->addCollection($rv{mid},'');
 440+ return %cid;
 441+}
 442+
 443+sub addCollection {
 444+ my $self=shift;
 445+ my $mid=shift;
 446+ my $collection_type=shift;
 447+ my $addcollection=$self->{dbt}->prepare('INSERT INTO uw_collection_ns(collection_mid,is_latest,collection_type) values(?,1,?)');
 448+ $addcollection->execute($mid,$collection_type);
 449+ my $cid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
 450+ my $updatefirstver=$self->{dbt}->prepare('UPDATE uw_collection_ns set first_ver=? where collection_id=?');
 451+ $updatefirstver->execute($cid,$cid);
 452+ return $cid;
 453+}
 454+
 455+sub importUMLSrelationtypes {
 456+ my $self=shift;
 457+ my $which=shift;
 458+ my $getreltypes;
 459+ if($which eq 'REL') {
 460+ # CHD and PAR are to be interpreted as RN and RB, SUBX is not used
 461+ $getreltypes=$self->{dbs}->prepare("select * from rel where ABBREV!='CHD' and ABBREV!='PAR' and ABBREV!='SUBX'");
 462+ } elsif($which eq 'RELA') {
 463+ $getreltypes=$self->{dbs}->prepare("select * from rela");
 464+ }
 465+ $getreltypes->execute();
 466+ while(my $reltype=$getreltypes->fetchrow_hashref()) {
 467+ my %rv=$self->addExpression($reltype->{FULL},$self->{la}{'en'},0,$self->{cid}{$which},$reltype->{ABBREV});
 468+ }
 469+}
 470+
 471+sub importUMLSterms {
 472+ my $self=shift;
 473+ my $sab=shift; # the source abbreviation which to import
 474+ my $cid=shift; # which collection to associate the defined meanings with
 475+
 476+ $getterm=$self->{dbs}->prepare("select str,cui,lat from MRCONSO where sab like ?");
 477+ $getterm->execute($sab);
 478+ my %textmid;
 479+ while(my $r=$getterm->fetchrow_hashref()) {
 480+ my %rv;
 481+ my $dupe=0;
 482+ my %cuimid=$self->getMidForMember($r->{cui});
 483+
 484+ # Create new expression / Defined Meaning
 485+ if(!$cuimid{mid}) {
 486+ %rv=$self->addExpression($r->{str},$self->{la_iso}{lc($r->{lat})},0,$cid,$r->{cui});
 487+ # If this is the first time we encounter this CUI, import the definitions
 488+ # Note that we'll take any definitions, regardless of the SABs specified!
 489+ if($rv{mid}!=-1) {
 490+ $getdefs=$self->{dbs}->prepare("select def from MRDEF where cui=?");
 491+ $getdefs->execute($r->{cui});
 492+ while(my $d=$getdefs->fetchrow_hashref()) {
 493+ # UMLS only has English definitions
 494+ $self->addMeaningText($rv{rid},$rv{mid},$d->{def},0,$self->{la}{'en'});
 495+ }
 496+ $textmid{$rv{mid}}=1;
 497+ }
 498+ # Add as SynTrans to existing Defined Meaning
 499+ } else {
 500+ %rv=$self->addExpression($r->{str},$self->{la_iso}{lc($r->{lat})},$cuimid{mid});
 501+ }
 502+ }
 503+}
 504+
 505+
 506+sub importGemetTerms {
 507+ my $self=shift;
 508+ my $cid=shift;
 509+ # Get all English terms as base
 510+ $getterm=$self->{dbs}->prepare("select * from term where langcode=?");
 511+ $getterm->execute('en');
 512+ while($r=$getterm->fetchrow_hashref()) {
 513+ # Add English term as defined meaning
 514+ my %rv=$self->addExpression($r->{name},$self->{la}{'en'},0,);
 515+
 516+ # All translations
 517+ $gettrans=$self->{dbs}->prepare("select name,langcode from term where id_concept=? and langcode!='en'");
 518+ $gettrans->execute($r->{id_concept});
 519+ # Add them with the same meaning ID
 520+ while($t=$gettrans->fetchrow_hashref()) {
 521+ print "Language: $t->{langcode}\n";
 522+ %tv=$self->addExpression($t->{name},$self->{la}{$t->{langcode}},$rv{mid});
 523+ }
 524+ # All definitions
 525+ $getdef=$self->{dbs}->prepare("select definition,langcode from scope where id_concept=?");
 526+ $getdef->execute($r->{id_concept});
 527+ my $tcid=0;
 528+ while($d=$getdef->fetchrow_hashref()) {
 529+ if(!$tcid) {
 530+ my %mv=$self->addMeaningText($rv{rid},$rv{mid},$d->{definition},0,$self->{la}{$d->{langcode}});
 531+ $tcid=$mv{tcid};
 532+
 533+ } else {
 534+ $self->addMeaningText($rv{rid},$rv{mid},$d->{definition},$tcid,$self->{la}{$d->{langcode}});
 535+
 536+ }
 537+ }
 538+ }
 539+}
 540+
 541+
 542+sub importGemetRelations {
 543+ my $self=shift;
 544+ # Import GEMET relations
 545+ my $getrels=$self->{dbs}->prepare("select * from relation");
 546+ $getrels->execute();
 547+ while(my $rrow=$getrels->fetchrow_hashref()) {
 548+ %rv_A=$self->findGemetItem($rrow->{id_concept});
 549+ %rv_B=$self->findGemetItem($rrow->{id_relation});
 550+ if($rv_A{mid} && $rv_B{mid}) {
 551+ $self->addRelation($rv_A{rid},$self->{reltypes}{$rrow->{id_type}},$rv_A{mid},$rv_B{mid});
 552+ }
 553+ }
 554+}
 555+
 556+sub importGemetThemes {
 557+ my $self=shift;
 558+ # Get all themes
 559+ my $getthemes=$self->{dbs}->prepare("select * from theme");
 560+ my $gettheme_set=$self->{dbs}->prepare("select * from theme where id_theme=?");
 561+ $getthemes->execute();
 562+ while(my $theme_row=$getthemes->fetchrow_hashref()) {
 563+ my $theme=$theme_row->{description};
 564+ my @themes=split(/[,;]( ){0,1}/,$theme);
 565+ foreach(@themes) {
 566+ $_=~s/^ *$//i;
 567+ if($_) {
 568+ # Does this theme have a expression?
 569+ my $t=$_;
 570+ my %it=$self->findLatestRevision($t,$self->{la}{$theme_row->{langcode}});
 571+ if($it{liid}) {
 572+ # Get the meaning
 573+ print "NEW THEME: $t - retrieving existing MID for LIID... ".$it{liid};
 574+ $it{mid}=$self->findMeaning($rv{liid});
 575+ print $it{mid}."\n";
 576+ #print $t. " is a dupe! - $dupes\n";
 577+ #$dupes++;
 578+ } else {
 579+ # Do we have any of its translations?
 580+ # We can only add those if the theme does
 581+ # not contain a , - otherwise we can't match!
 582+ my $tra_mid=0;
 583+ if(!($theme_row->{description}=~m/[,;]/i)) {
 584+ print "NEW THEME: $t - no record, looking for its known translations in GEMET\n";
 585+ #print "Checking for translations of ".$theme_row->{description}."\n";
 586+ $gettheme_set->execute($theme_row->{id_theme});
 587+ while((my $tra_row=$gettheme_set->fetchrow_hashref()) && !$tra_mid) {
 588+ if($tra_lid=$self->findExpressionId($tra_row->{description},$self->{la}{$tra_row->{langcode}})) {
 589+ $tra_mid=$self->findMeaning($tra_lid);
 590+
 591+ }
 592+ }
 593+ } else {
 594+ print "NEW THEME: $t - split from the original GEMET data\n";
 595+ }
 596+ # Let's make one
 597+ if($tra_mid) {
 598+ print "Adding new term as translation of $tra_mid\n";
 599+ %it = $self->addExpression($t,$self->{la}{$theme_row->{langcode}},$tra_mid);
 600+ } else {
 601+ print "Adding new term independently, we do not know its translations.\n";
 602+ %it = $self->addExpression($t,$self->{la}{$theme_row->{langcode}});
 603+ }
 604+
 605+
 606+ }
 607+
 608+ if(!$have_rel{$theme_row->{id_theme}}) {
 609+ # Get all items which have this relation
 610+ my $getconcepts=$self->{dbs}->prepare('select id_concept from concept_theme where id_theme=?');
 611+ $getconcepts->execute($theme_row->{id_theme});
 612+ while(my $concrow=$getconcepts->fetchrow_hashref()) {
 613+ # Get LIID,RID->meaning for the item
 614+ my %tr=$self->findGemetItem($concrow->{id_concept});
 615+ if($tr{rid}) {
 616+ $self->addRelation($tr{rid},$self->{reltypes}{it},$tr{mid},$it{mid});
 617+ print "Tied up a relation..";
 618+ } else {
 619+ print "Missing record to tie the relation to..";
 620+ }
 621+ }
 622+ print "\n";
 623+ $have_rel{$theme_row->{id_theme}}=1;
 624+ }
 625+
 626+ }
 627+ }
 628+ }
 629+ #Split theme into parts
 630+}
 631+
 632+sub findGemetItem {
 633+ my $self=shift;
 634+ my $concept_id=shift;
 635+ # get a word, language
 636+ my $getword=$self->{dbs}->prepare("select langcode,name from term where id_concept=? LIMIT 1");
 637+ $getword->execute($concept_id);
 638+ my $wordrow=$getword->fetchrow_hashref();
 639+
 640+ # find an expression + meaning
 641+ my %rv=$self->findLatestRevision($wordrow->{name},$self->{la}{$wordrow->{langcode}});
 642+ $rv{mid}=$self->findMeaning($rv{liid});
 643+ return %rv;
 644+}
 645+
 646+sub addRelation {
 647+ my $self=shift;
 648+ my $revid=shift;
 649+ my $rtid=shift;
 650+ my $mid_A=shift;
 651+ my $mid_B=shift;
 652+ my $checkfordupes=shift;
 653+
 654+ if($checkfordupes) {
 655+ my $checkRelationDuplicates=$self->{dbt}->prepare('select 1 as one from uw_meaning_relations where meaning1_mid=? and meaning2_mid=? and relationtype_mid=? and is_latest_set=1 limit 1');
 656+ $checkRelationDuplicates->execute($mid_A,$mid_B,$rtid);
 657+ #print "Checking dupe $mid_A, $mid_B, relation type $rtid\n";
 658+ my $dupecheck=$checkRelationDuplicates->fetchrow_hashref();
 659+ if($dupecheck->{one}) {
 660+ print "Duplicate relation, not adding.\n";
 661+ return false;
 662+ }
 663+ }
 664+
 665+ my $newkey= $self->getSetIdWhere('uw_meaning_relations','meaning1_mid',$mid_A) || $self->getMaxId('set_id','uw_meaning_relations');
 666+ my $addrel=$self->{dbt}->prepare('insert into uw_meaning_relations(set_id,meaning1_mid,meaning2_mid,relationtype_mid,is_latest_set,first_set,revision_id) values(?,?,?,?,?,?,?)');
 667+ $addrel->execute($newkey,$mid_A,$mid_B,$rtid,1,$newkey,$revid);
 668+
 669+ print "newkey: $newkey\n";
 670+ print "mid_A: $mid_A\n";
 671+ print "mid_B: $mid_B\n";
 672+ print "rtid: $rtid\n";
 673+ print "revid: $revid\n";
 674+}
 675+
 676+
 677+sub findMeaning {
 678+ my $self=shift;
 679+ my $liid=shift;
 680+ # Search syntrans table
 681+ my $getsyn=$self->{dbt}->prepare("select defined_meaning_id from uw_syntrans where expression_id=?");
 682+ $getsyn->execute($liid);
 683+ my $syn_row=$getsyn->fetchrow_hashref();
 684+ if($syn_row->{defined_meaning_id}) {
 685+ return $syn_row->{defined_meaning_id};
 686+ }
 687+ my $getdm=$self->{dbt}->prepare("select defined_meaning_id from uw_defined_meaning where expression_id=? limit 1");
 688+ $getdm->execute($liid);
 689+ my $dm_row=$getdm->fetchrow_hashref();
 690+ if($dm_row->{defined_meaning_id}) {
 691+ return $dm_row->{defined_meaning_id};
 692+ }
 693+ return 0;
 694+}
 695+
 696+# If there already is a meaning text for this DefinedMeaning, it will add the MeaningText as an alternative definition
 697+sub addMeaningText {
 698+ my $self=shift;
 699+ my $rid=shift;
 700+ my $mid=shift;
 701+ my $meaningtext=shift; # optional
 702+ my $meaningtext_set=shift; # optional TCID set to join with
 703+ my $lid=shift; # ID, not code
 704+ my %rv;
 705+
 706+ # Add text row entry
 707+ my $maketext=$self->{dbt}->prepare('insert into text(old_text) values(?)');
 708+ $maketext->execute($meaningtext);
 709+ # Get text row ID
 710+ $tid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
 711+ # Get new or existing translated content set ID
 712+ $tcid=$meaningtext_set || $self->getMaxId('set_id','translated_content');
 713+ # Create new translated content set
 714+ my $maketc=$self->{dbt}->prepare('insert into translated_content(set_id,language_id,text_id,first_set,revision_id) values(?,?,?,?,?)');
 715+ $maketc->execute($tcid,$lid,$tid,$tcid,$rid);
 716+ $rv{tcid}=$tcid;
 717+
 718+ # THIS DOESN'T WORK FOR DEFINITIONS IN MULTIPLE LANGUAGES
 719+ # Check if a meaning text has already been set
 720+ my $lookformeaning=$self->{dbt}->prepare('select meaning_text_tcid from uw_defined_meaning where defined_meaning_id=? and is_latest_ver=1');
 721+ $lookformeaning->execute($mid);
 722+ my $mrow=$lookformeaning->fetchrow_hashref();
 723+ if($mrow->{meaning_text_tcid}) {
 724+ # There is a meaning text - the new one is only an alternative
 725+ my $altset=$self->getSetIdWhere('uw_alt_meaningtexts','meaning_mid',$mid) || $self->getMaxId('set_id','uw_alt_meaningtexts');
 726+ my $addaltmeaning=$self->{dbt}->prepare('insert into uw_alt_meaningtexts(set_id,meaning_mid,meaning_text_tcid,is_latest_set,first_set,revision_id) values(?,?,?,?,?,?)');
 727+ $addaltmeaning->execute($altset,$mid,$tcid,1,$altset,$rid)
 728+ } else {
 729+ my $updatemeaning=$self->{dbt}->prepare('update uw_defined_meaning set meaning_text_tcid=? where defined_meaning_id=?');
 730+ $updatemeaning->execute($tcid,$mid);
 731+ }
 732+ return %rv;
 733+}
 734+
 735+
 736+# If the expression already exists, add a new DefinedMeaning - unless this is a translation or synonym; if a record already exists in SynTrans with this expression _and_ $translation_of as a DefinedMeaning, do not do anything
 737+sub addExpression {
 738+ my $self=shift;
 739+ # return MID, RID, LID, TCID!
 740+ my $expression=shift;
 741+ my $lid=shift; # ID, not code
 742+ my $translation_of=shift; # 0 or MID (!), optional
 743+ my $collection_id=shift; # optional
 744+ my $collection_internal_member_id=shift; # what does the collection use to refer to this member?
 745+ my %rv;
 746+ my $isdupe=0;
 747+ my %firv=$self->findLatestRevision($expression,$lid);
 748+ if($firv{liid}) { $isdupe=1; }
 749+
 750+ if(!$isdupe) {
 751+
 752+ #create page
 753+ my $pt=$self->canonize($expression);
 754+ $makepage=$self->{dbt}->prepare('insert into page(page_namespace,page_title,page_is_new,page_title_language_id,page_touched) values(?,?,?,?,?)');
 755+ $makepage->execute(16,$pt,1,$lid,$self->mwtimestamp());
 756+ $pid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
 757+ print "PID: $pid\n";
 758+
 759+ $rv{pid}=$pid;
 760+
 761+ #create revision
 762+ $makerev=$self->{dbt}->prepare('insert into revision(rev_page,rev_comment,rev_user,rev_user_text,rev_timestamp) values(?,?,?,?,?)');
 763+ $makerev->execute($pid,'Initial import',2,'GEMET',$self->mwtimestamp());
 764+
 765+ #get revision_id
 766+ $rid=$self->getId('select rev_id from revision where rev_page=?',$pid);
 767+ $rv{rid}=$rid;
 768+
 769+ #update page to link to revision
 770+ $updatepage=$self->{dbt}->prepare('update page set page_latest=? where page_id=?');
 771+ $updatepage->execute($rid,$pid);
 772+
 773+ #create expression
 774+ $makeitem=$self->{dbt}->prepare('insert into uw_expression_ns(spelling,language_id,is_latest) values(?,?,1)');
 775+ $makeitem->execute($expression,$lid);
 776+ $liid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
 777+ $rv{liid}=$liid;
 778+
 779+ # update firstver
 780+ $updateitem=$self->{dbt}->prepare('update uw_expression_ns set first_ver=? where expression_id=?');
 781+ $updateitem->execute($liid,$liid);
 782+
 783+ #update revision to link to expression
 784+ $updaterev=$self->{dbt}->prepare('update revision set rev_data_id=? where rev_id=?');
 785+ $updaterev->execute($liid,$rid);
 786+
 787+ } else {
 788+
 789+ $rid=$firv{rid};
 790+ $liid=$firv{liid};
 791+ $rv{rid}=$rid;
 792+ $rv{liid}=$liid;
 793+
 794+ }
 795+
 796+ #create definedmeaning
 797+ if(!$translation_of) {
 798+ $makemean=$self->{dbt}->prepare('insert into uw_defined_meaning(expression_id,revision_id) values(?,?)');
 799+ $makemean->execute($liid,$rid);
 800+ # We always want a syntrans record, so in this case it links to its own
 801+ # def. meaning
 802+ $translation_of=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
 803+ $mid=$translation_of;
 804+ $rv{mid}=$mid;
 805+ $updatemeaningver=$self->{dbt}->prepare('update uw_defined_meaning set first_ver=? where defined_meaning_id=?');
 806+ $updatemeaningver->execute($mid,$mid);
 807+ if($collection_id) {
 808+ $addtocoll=$self->{dbt}->prepare('insert into uw_collection_contents(set_id, collection_id, member_mid, is_latest_set, first_Set, revision_id, internal_member_id) values(?,?,?,?,?,?,?)');
 809+ #fixme set association
 810+ $addtocoll->execute(1,$collection_id,$mid,1,1,$rid,$collection_internal_member_id);
 811+ }
 812+ }
 813+
 814+ # Check if we already have this specific record
 815+ $checkdupes=$self->{dbt}->prepare('select set_id from uw_syntrans where defined_meaning_id=? and expression_id=?');
 816+ $checkdupes->execute($translation_of,$liid);
 817+ my $duperow=$checkdupes->fetchrow_hashref();
 818+ my $dupeid=$duperow->{set_id};
 819+ if(!$dupeid) {
 820+
 821+ # Check if this is part of a set
 822+ $getset=$self->{dbt}->prepare('select set_id from uw_syntrans where defined_meaning_id=? and is_latest_set=1');
 823+ $getset->execute($mid);
 824+ $row=$getset->fetchrow_hashref();
 825+ my $setid=$row->{set_id} || $self->getMaxId('set_id','uw_syntrans');
 826+ # Add syntrans record
 827+ $maketrans=$self->{dbt}->prepare('insert into uw_syntrans(set_id,defined_meaning_id,expression_id,first_set,revision_id,is_latest_set,endemic_meaning) values(?,?,?,?,?,1,1)');
 828+ $maketrans->execute($setid,$translation_of,$liid,$setid,$rid);
 829+ $rv{setid}=$setid;
 830+ $rv{mid}=$translation_of;
 831+ } else{
 832+ $rv{setid}=$dupeid; # Dupe
 833+ $rv{mid}=-1; # Dupe
 834+ }
 835+ return %rv;
 836+
 837+}
 838+
 839+sub findLatestRevision {
 840+ my $self = shift;
 841+ my $expressionSpelling = shift;
 842+ my $languageId = shift;
 843+
 844+ my $expressionId = $self->findExpressionId($expressionSpelling, $languageId);
 845+ if ($expressionId != 0) {
 846+ my $getRevisionId = $self->{dbt}->prepare('select rev_id from revision where rev_data_id=?');
 847+ $getRevisionId->execute($expressionId);
 848+ my %revision;
 849+ $revision{liid} = $expressionId;
 850+ $revision{rid} = $getRevisionId->fetchrow_hashref->{rev_id};
 851+ return %revision;
 852+ } else {
 853+ return 0;
 854+ }
 855+}
 856+
 857+sub findExpressionId {
 858+ my $self = shift;
 859+ my $expressionSpelling = shift;
 860+ my $languageId = shift;
 861+
 862+ my $getItem = $self->{dbt}->prepare("select expression_id from uw_expression_ns where spelling=binary ? and language_id=? and is_latest=1");
 863+ $getItem->execute($expressionSpelling, $languageId);
 864+ my $itemRow = $getItem->fetchrow_hashref();
 865+ if ($itemRow) {
 866+ return $itemRow->{expression_id};
 867+ } else {
 868+ return 0;
 869+ }
 870+}
 871+
 872+sub getMaxId {
 873+ my $self=shift;
 874+ my $field=shift;
 875+ my $table=shift;
 876+ $getmax=$self->{dbt}->prepare("select max($field) as maxset from $table");
 877+ $getmax->execute();
 878+ my $row=$getmax->fetchrow_hashref();
 879+ return $row->{maxset}+1;
 880+}
 881+
 882+sub getSetIdWhere {
 883+ my $self=shift;
 884+ my $table=shift;
 885+ my $wherefield=shift;
 886+ my $wherekey=shift;
 887+ $getmax=$self->{dbt}->prepare("select set_id from $table WHERE $wherefield=? AND is_latest_set=1 limit 1");
 888+ $getmax->execute($wherekey);
 889+ my $row=$getmax->fetchrow_hashref();
 890+ return $row->{set_id};
 891+}
 892+
 893+
 894+sub getId {
 895+ my $self=shift;
 896+ my $prep=shift;
 897+ $prep=~m/select (.*?) from/i;
 898+ my $field=$1;
 899+ my $getlang=$self->{dbt}->prepare($prep);
 900+ $getlang->execute(@_);
 901+ my $row=$getlang->fetchrow_hashref();
 902+ my $id=$row->{$field};
 903+ return $id;
 904+}
 905+
 906+sub mwtimestamp {
 907+ my $self=shift;
 908+ use POSIX qw(strftime);
 909+ return(strftime "%Y%m%d%H%M%S", localtime);
 910+}
 911+
 912+
 913+sub canonize {
 914+ my $self=shift;
 915+ my $title=shift;
 916+ #$title=ucfirst($title);
 917+ $title=~s/ /_/ig;
 918+ return $title;
 919+}
 920+
 921+sub initlangs {
 922+ my $self=shift;
 923+ %langs=(
 924+ en_en=>'English',
 925+ en_de=>'Englisch',
 926+ 'en-US_de'=>'Englisch (USA)',
 927+ 'en-US_en'=>'English (United States)',
 928+ bg_en=>'Bulgarian',
 929+ bg_de=>'Bulgarisch',
 930+ cs_en=>'Czech',
 931+ cs_de=>'Tschechisch',
 932+ da_en=>'Dansk',
 933+ da_de=>'D?isch',
 934+ de_en=>'German',
 935+ de_de=>'Deutsch',
 936+ es_en=>'Spanish',
 937+ es_de=>'Spanisch',
 938+ et_en=>'Estonian',
 939+ et_de=>'Estnisch',
 940+ eu_en=>'Basque',
 941+ eu_de=>'Baskisch',
 942+ fi_en=>'Finnish',
 943+ fi_de=>'Finnisch',
 944+ fr_en=>'French',
 945+ fr_de=>'Franz?isch',
 946+ hu_en=>'Hungarian',
 947+ hu_de=>'Ungarisch',
 948+ it_en=>'Italian',
 949+ it_de=>'Italienisch',
 950+ nl_en=>'Dutch',
 951+ nl_de=>'Niederl?disch',
 952+ no_en=>'Norwegian',
 953+ no_de=>'Norwegisch',
 954+ pl_en=>'Polish',
 955+ pl_de=>'Polnisch',
 956+ pt_en=>'Portuguese',
 957+ pt_de=>'Portugiesisch',
 958+ ru_en=>'Russian',
 959+ ru_de=>'Russisch',
 960+ sk_en=>'Slovak',
 961+ sk_de=>'Slowakische Sprache',
 962+ sl_en=>'Slovenian',
 963+ sl_de=>'Slowenisch',
 964+ el_en=>'Greek',
 965+ el_de=>'Griechisch',
 966+ sv_en=>'Swedish',
 967+ sv_de=>'Schwedisch');
 968+ foreach(keys(%langs)) {
 969+ $key=$_;
 970+ $key=~m/(.*?)_(.*)/i;
 971+ $lang=$1;
 972+ #print "Lang: $lang\n";
 973+ $wordlang=$2;
 974+ if($wordlang eq 'en') {
 975+ $addwm=$self->{dbt}->prepare("insert into language(wikimedia_key) values(?)");
 976+ $addwm->execute($lang);
 977+ }
 978+ }
 979+ foreach(keys(%langs)) {
 980+ $key=$_;
 981+ $key=~m/(.*?)_(.*)/i;
 982+ $lang=$1;
 983+ #print "Lang: $lang\n";
 984+ $wordlang=$2;
 985+ $langword_u=$langs{$key};
 986+ $langword=encode("utf8",$langword_u);
 987+ $newwm=$self->{dbt}->prepare("select language_id from language where wikimedia_key=?");
 988+ $newwm->execute($lang);
 989+ my $row=$newwm->fetchrow_hashref();
 990+ $newwm->execute('en');
 991+ my $en_row=$newwm->fetchrow_hashref();
 992+ $newwm->execute('de');
 993+ my $de_row=$newwm->fetchrow_hashref();
 994+ $newword=$self->{dbt}->prepare("insert into language_names values (?,?,?)");
 995+ if($wordlang eq 'en') {
 996+ $newword->execute($row->{language_id},$en_row->{language_id},$langword);
 997+ } elsif($wordlang eq 'de') {
 998+ $newword->execute($row->{language_id},$de_row->{language_id},$langword);
 999+ }
 1000+ }
 1001+}
 1002+
 1003+sub initRel {
 1004+ my $self=shift;
 1005+ my $cid=shift;
 1006+ %rel_types=(
 1007+ bt_en=>'broader terms',
 1008+ bt_de=>'breitere Begriffe',
 1009+ nt_en=>'narrower terms',
 1010+ nt_de=>'engere Begriffe',
 1011+ rt_en=>'related terms',
 1012+ rt_de=>'verwandte Begriffe',
 1013+ it_en=>'is part of theme',
 1014+ it_de=>'ist Themenbestandteil von'
 1015+ );
 1016+
 1017+ %rel_definitions=(
 1018+ bt_en=>'Those terms in a thesaurus which are broader than others',
 1019+ bt_de=>'Die Begriffe in einem Thesaurus, die breiter sind als andere',
 1020+ nt_en=>'Those terms in a thesaurus which are narrower than others',
 1021+ nt_de=>'Die Begriffe in einem Thesaurus, die enger sind als andere',
 1022+ rt_en=>'Those terms in a thesaurus which are related to others',
 1023+ rt_de=>'Die Begriffe in einem Thesaurus, die mit anderen verwandt sind',
 1024+ it_en=>'Those terms in a thesaurus or dictionary which are associated with a topic',
 1025+ it_de=>'Die Begriffe in einem Thesaurus oder Woerterbuch, die mit einem Thema assoziiert sind');
 1026+
 1027+ foreach(keys(%rel_types)) {
 1028+ $key=$_;
 1029+ $key=~m/(..)_(..)/i;
 1030+ $ident=$1;
 1031+ $lang=$2;
 1032+ if($lang eq 'de') {
 1033+ $en_key="$ident\_en";
 1034+ my %rv=$self->addExpression($rel_types{$en_key},$self->{la}{'en'},0,$cid,$ident);
 1035+ $self->addMeaningText($rv{rid},$rv{mid},$rel_definitions{$en_key},0,$self->{la}{'en'});
 1036+ my %dv=$self->addExpression($rel_types{$key},$self->{la}{'de'},$rv{'mid'});
 1037+ $self->addMeaningText($dv{rid},$dv{mid},$rel_definitions{$key},$rv{'tcid'},$self->{la}{'de'});
 1038+ }
 1039+ }
 1040+}
 1041+
 1042+sub loadLangs {
 1043+ my $self=shift;
 1044+ my %la;
 1045+ $getlangs=$self->{dbt}->prepare('select language_id,wikimedia_key from language');
 1046+ $getlangs->execute();
 1047+ while($langrow=$getlangs->fetchrow_hashref()) {
 1048+ $la{$langrow->{wikimedia_key}}=$langrow->{language_id};
 1049+ }
 1050+ return %la;
 1051+}
 1052+
 1053+sub loadLangsIso {
 1054+ my $self=shift;
 1055+ my %la_iso;
 1056+ $getlangs=$self->{dbt}->prepare('select language_id,iso639_2 from language');
 1057+ $getlangs->execute();
 1058+ while($langrow=$getlangs->fetchrow_hashref()) {
 1059+ $la_iso{$langrow->{iso639_2}}=$langrow->{language_id};
 1060+ }
 1061+ return %la_iso;
 1062+}
 1063+
 1064+return(1);
Index: trunk/extensions/Wikidata/perl-tools/README
@@ -0,0 +1,2 @@
 2+These are obsolete and need to be updated to work with the latest database
 3+schema. However, this may be worth doing for interested Perl hackers.
\ No newline at end of file
Index: trunk/extensions/Wikidata/OmegaWiki/WiktionaryZ.php
@@ -1,123 +0,0 @@
2 -<?php
3 -
4 -require_once('Wikidata.php');
5 -require_once('Transaction.php');
6 -require_once('Expression.php');
7 -require_once('forms.php');
8 -require_once('Attribute.php');
9 -require_once('type.php');
10 -require_once('languages.php');
11 -require_once('HTMLtable.php');
12 -require_once('OmegaWikiRecordSets.php');
13 -require_once('OmegaWikiEditors.php');
14 -
15 -/**
16 - * Load and modify content in a OmegaWiki-enabled
17 - * namespace.
18 - *
19 - */
20 -class OmegaWiki extends DefaultWikidataApplication {
21 - public function view() {
22 - global
23 - $wgOut, $wgTitle;
24 -
25 - parent::view();
26 -
27 - $spelling = $wgTitle->getText();
28 -
29 - $wgOut->addHTML(
30 - getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, $this->shouldShowAuthorities)->view(
31 - $this->getIdStack(),
32 - getExpressionsRecordSet(
33 - $spelling,
34 - $this->filterLanguageId,
35 - $this->possiblySynonymousRelationTypeId,
36 - $this->viewQueryTransactionInformation
37 - )
38 - )
39 - );
40 -
41 - $wgOut->addHTML(DefaultEditor::getExpansionCss());
42 - $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
43 - }
44 -
45 - public function history() {
46 - global
47 - $wgOut, $wgTitle;
48 -
49 - parent::history();
50 -
51 - $spelling = $wgTitle->getText();
52 -
53 - $wgOut->addHTML(
54 - getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, $this->showRecordLifeSpan, false)->view(
55 - $this->getIdStack(),
56 - getExpressionsRecordSet(
57 - $spelling,
58 - $this->filterLanguageId,
59 - $this->possiblySynonymousRelationTypeId,
60 - $this->queryTransactionInformation
61 - )
62 - )
63 - );
64 -
65 - $wgOut->addHTML(DefaultEditor::getExpansionCss());
66 - $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
67 - }
68 -
69 - protected function save($referenceTransaction) {
70 - global
71 - $wgTitle;
72 -
73 - parent::save($referenceTransaction);
74 -
75 - $spelling = $wgTitle->getText();
76 -
77 - getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, false)->save(
78 - $this->getIdStack(),
79 - getExpressionsRecordSet(
80 - $spelling,
81 - $this->filterLanguageId,
82 - $this->possiblySynonymousRelationTypeId,
83 - $referenceTransaction
84 - )
85 - );
86 - }
87 -
88 - public function edit() {
89 - global
90 - $wgOut, $wgTitle, $wgUser;
91 -
92 - parent::edit();
93 - $this->outputEditHeader();
94 -
95 - $spelling = $wgTitle->getText();
96 -
97 - $wgOut->addHTML(
98 - getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, false)->edit(
99 - $this->getIdStack(),
100 - getExpressionsRecordSet(
101 - $spelling,
102 - $this->filterLanguageId,
103 - $this->possiblySynonymousRelationTypeId,
104 - new QueryLatestTransactionInformation()
105 - )
106 - )
107 - );
108 -
109 - $this->outputEditFooter();
110 - }
111 -
112 - public function getTitle() {
113 - global
114 - $wgTitle;
115 -
116 - return "Disambiguation: " . $wgTitle->getText();
117 - }
118 -
119 - protected function getIdStack() {
120 - return new IdStack("expression");
121 - }
122 -}
123 -
124 -?>
Index: trunk/extensions/Wikidata/OmegaWiki/Import WiktionaryZ.pl
@@ -1,55 +0,0 @@
2 -use WiktionaryZ;
3 -use POSIX qw(strftime);
4 -
5 -my $startTime = time;
6 -
7 -# Example usage to import UMLS completely into an existing WiktionaryZ database:
8 -# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
9 -# $importer->setSourceDB('umls');
10 -# $importer->initialize;
11 -# $importer->importCompleteUMLS();
12 -
13 -# Example usage to import a part of UMLS into an existing WiktionaryZ database:
14 -# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
15 -# $importer->setSourceDB('umls');
16 -# $importer->initialize;
17 -# my %sourceAbbreviations = $importer->loadSourceAbbreviations();
18 -# delete($sourceAbbreviations{"MSH"});
19 -# $importer->importUMLS(\%sourceAbbreviations);
20 -
21 -my $importer=new WiktionaryZ('wikidata_icpc','root','');
22 -$importer->setSourceDB('umls');
23 -#$importer->setSourceDB('swissprot');
24 -$importer->initialize;
25 -#$importer->importCompleteUMLS();
26 -
27 -#read the source abbreviations and remove those you do not wish to import
28 -my %sourceAbbreviations = $importer->loadSourceAbbreviations();
29 -my @deleteList;
30 -while (($key, $val) = each(%sourceAbbreviations)) {
31 -
32 -#remove all that contains "MSH":
33 -# if (index($key,"MSH") >= 0) {
34 -# push(@deleteList, $key);
35 -# }
36 -
37 -#remove all that does not contain "ICPC":
38 - if (index($key,"ICPC") < 0) {
39 - push(@deleteList, $key);
40 - }
41 -}
42 -
43 -foreach $sab (@deleteList){
44 - delete($sourceAbbreviations{$sab});
45 -}
46 -
47 -$importer->importUMLS(\%sourceAbbreviations);
48 -
49 -
50 -my $endTime = time;
51 -print "\n";
52 -print "Import started at: " . (strftime "%H:%M:%S", localtime($startTime)) . "\n";
53 -print "Import ended at: " . (strftime "%H:%M:%S", localtime($endTime)) . "\n";
54 -print "Elapsed time: " . (strftime "%H:%M:%S", gmtime($endTime - $startTime)) . "\n";
55 -
56 -exit 0;
\ No newline at end of file
Index: trunk/extensions/Wikidata/OmegaWiki/WiktionaryZAttributes.php
@@ -1,243 +0,0 @@
2 -<?php
3 -
4 -require_once("Attribute.php");
5 -require_once("WikiDataGlobals.php");
6 -
7 -function initializeOmegaWikiAttributes($filterOnLanguage, $hasMetaDataAttributes) {
8 - global
9 - $languageAttribute, $spellingAttribute, $textAttribute;
10 -
11 - $languageAttribute = new Attribute("language", "Language", "language");
12 - $spellingAttribute = new Attribute("spelling", "Spelling", "spelling");
13 - $textAttribute = new Attribute("text", "Text", "text");
14 -
15 - global
16 - $expressionIdAttribute, $identicalMeaningAttribute;
17 -
18 - $expressionIdAttribute = new Attribute("expression-id", "Expression Id", "expression-id");
19 - $identicalMeaningAttribute = new Attribute("indentical-meaning", "Identical meaning?", "boolean");
20 -
21 - global
22 - $expressionStructure, $expressionAttribute;
23 -
24 - if ($filterOnLanguage)
25 - $expressionAttribute = new Attribute("expression", "Spelling", "spelling");
26 - else {
27 - $expressionStructure = new Structure($languageAttribute, $spellingAttribute);
28 - $expressionAttribute = new Attribute("expression", "Expression", new RecordType($expressionStructure));
29 - }
30 -
31 - global
32 - $definedMeaningIdAttribute, $definedMeaningDefiningExpressionAttribute;
33 -
34 - $definedMeaningIdAttribute = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id");
35 - $definedMeaningDefiningExpressionAttribute = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text");
36 -
37 - global
38 - $definedMeaningReferenceStructure, $definedMeaningLabelAttribute, $definedMeaningReferenceKeyStructure, $definedMeaningReferenceType,
39 - $definedMeaningReferenceAttribute;
40 -
41 - $definedMeaningLabelAttribute = new Attribute("defined-meaning-label", "Defined meaning label", "short-text");
42 - $definedMeaningReferenceStructure = new Structure($definedMeaningIdAttribute, $definedMeaningLabelAttribute, $definedMeaningDefiningExpressionAttribute);
43 - $definedMeaningReferenceKeyStructure = new Structure($definedMeaningIdAttribute);
44 - $definedMeaningReferenceType = new RecordType($definedMeaningReferenceStructure);
45 - $definedMeaningReferenceAttribute = new Attribute("defined-meaning", "Defined meaning", $definedMeaningReferenceType);
46 -
47 - global
48 - $collectionIdAttribute, $collectionMeaningType, $collectionMeaningAttribute, $sourceIdentifierAttribute;
49 -
50 - $collectionIdAttribute = new Attribute("collection", "Collection", "collection-id");
51 - $collectionMeaningType = new RecordType($definedMeaningReferenceStructure);
52 - $collectionMeaningAttribute = new Attribute("collection-meaning", "Collection", $collectionMeaningType);
53 - $sourceIdentifierAttribute = new Attribute("source-identifier", "Source identifier", "short-text");
54 -
55 - global
56 - $collectionMembershipAttribute;
57 -
58 - $collectionMembershipAttribute = new Attribute("collection-membership", "Collection membership", new RecordSetType(new Structure($collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute)));
59 -
60 - global
61 - $classMembershipIdAttribute, $classAttribute;
62 -
63 - $classMembershipIdAttribute = new Attribute("class-membership-id", "Class membership id", "integer");
64 - $classAttribute = new Attribute("class", "Class", new RecordType($definedMeaningReferenceStructure));
65 -
66 - global
67 - $classMembershipStructure, $classMembershipKeyStructure, $classMembershipAttribute, $wgClassMembershipAttributeName;
68 -
69 - $classMembershipStructure = new Structure($classMembershipIdAttribute, $classAttribute);
70 - $classMembershipKeyStructure = new Structure($classMembershipIdAttribute);
71 - $classMembershipAttribute = new Attribute("class-membership", $wgClassMembershipAttributeName, new RecordSetType($classMembershipStructure));
72 -
73 - global
74 - $possiblySynonymousIdAttribute, $possibleSynonymAttribute;
75 -
76 - $possiblySynonymousIdAttribute = new Attribute("possibly-synonymous-id", "Possibly synonymous id", "integer");
77 - $possibleSynonymAttribute = new Attribute("possible-synonym", "Possible synonym", new RecordType($definedMeaningReferenceStructure));
78 -
79 - global
80 - $possiblySynonymousStructure, $possiblySynonymousKeyStructure, $possiblySynonymousAttribute,
81 - $wgPossiblySynonymousAttributeName;
82 -
83 - $possiblySynonymousStructure = new Structure($possiblySynonymousIdAttribute, $possiblySynonymousAttribute);
84 - $possiblySynonymousKeyStructure = new Structure($possiblySynonymousIdAttribute);
85 - $possiblySynonymousAttribute = new Attribute("possibly-synonymous", $wgPossiblySynonymousAttributeName, new RecordSetType($possiblySynonymousStructure));
86 -
87 - global
88 - $relationIdAttribute, $relationTypeAttribute, $relationTypeType, $otherDefinedMeaningAttribute,
89 - $wgRelationTypeAttributeName, $wgOtherDefinedMeaningAttributeName;
90 -
91 - $relationIdAttribute = new Attribute("relation-id", "Relation identifier", "object-id");
92 - $relationTypeType = new RecordType($definedMeaningReferenceStructure);
93 - $relationTypeAttribute = new Attribute("relation-type", $wgRelationTypeAttributeName, $relationTypeType);
94 - $otherDefinedMeaningAttribute = new Attribute("other-defined-meaning", $wgOtherDefinedMeaningAttributeName, $definedMeaningReferenceType);
95 -
96 - global
97 - $relationsAttribute, $relationStructure, $relationKeyStructure, $reciprocalRelationsAttribute, $objectAttributesAttribute,
98 - $wgRelationsAttributeName, $wgIncomingRelationsAttributeName;
99 -
100 - $relationStructure = new Structure($relationIdAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute, $objectAttributesAttribute);
101 - $relationKeyStructure = new Structure($relationIdAttribute);
102 - $relationsAttribute = new Attribute("relations", $wgRelationsAttributeName, new RecordSetType($relationStructure));
103 - $reciprocalRelationsAttribute = new Attribute("reciprocal-relations", $wgIncomingRelationsAttributeName, new RecordSetType($relationStructure));
104 -
105 - global
106 - $translatedTextIdAttribute, $translatedTextStructure;
107 -
108 - $translatedTextIdAttribute = new Attribute("translated-text-id", "Translated text ID", "integer");
109 - $translatedTextStructure = new Structure($languageAttribute, $textAttribute);
110 -
111 - global
112 - $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute,
113 - $wgAlternativeDefinitionAttributeName, $wgSourceAttributeName;
114 -
115 - $definitionIdAttribute = new Attribute("definition-id", "Definition identifier", "integer");
116 -
117 - if ($filterOnLanguage && !$hasMetaDataAttributes)
118 - $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, "text");
119 - else
120 - $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, new RecordSetType($translatedTextStructure));
121 -
122 - $sourceAttribute = new Attribute("source-id", $wgSourceAttributeName, $definedMeaningReferenceType);
123 -
124 - global
125 - $alternativeDefinitionsAttribute, $wgAlternativeDefinitionsAttributeName;
126 -
127 - $alternativeDefinitionsAttribute = new Attribute("alternative-definitions", $wgAlternativeDefinitionsAttributeName, new RecordSetType(new Structure($definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute)));
128 -
129 - global
130 - $synonymsAndTranslationsAttribute, $syntransIdAttribute;
131 -
132 - if ($filterOnLanguage)
133 - $synonymsAndTranslationsCaption = "Synonyms";
134 - else
135 - $synonymsAndTranslationsCaption = "Synonyms and translations";
136 -
137 - $syntransIdAttribute = new Attribute("syntrans-id", "$synonymsAndTranslationsCaption identifier", "integer");
138 - $synonymsAndTranslationsAttribute = new Attribute("synonyms-translations", "$synonymsAndTranslationsCaption", new RecordSetType(new Structure($syntransIdAttribute, $expressionAttribute, $identicalMeaningAttribute, $objectAttributesAttribute)));
139 -
140 - global
141 - $translatedTextAttributeIdAttribute, $translatedTextValueIdAttribute, $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute,
142 - $translatedTextAttributeValuesStructure, $wgTranslatedTextAttributeValuesAttributeName, $wgTranslatedTextAttributeAttributeName, $wgTranslatedTextAttributeValueAttributeName;
143 -
144 - $translatedTextAttributeIdAttribute = new Attribute("translated-text-attribute-id", "Attribute identifier", "object-id");
145 - $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", $wgTranslatedTextAttributeAttributeName, $definedMeaningReferenceType);
146 - $translatedTextValueIdAttribute = new Attribute("translated-text-value-id", "Translated text value identifier", "translated-text-value-id");
147 -
148 - if ($filterOnLanguage && !$hasMetaDataAttributes)
149 - $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, "text");
150 - else
151 - $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, new RecordSetType($translatedTextStructure));
152 -
153 - $translatedTextAttributeValuesStructure = new Structure($translatedTextAttributeIdAttribute, $translatedTextAttributeAttribute, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $objectAttributesAttribute);
154 - $translatedTextAttributeValuesAttribute = new Attribute("translated-text-attribute-values", $wgTranslatedTextAttributeValuesAttributeName, new RecordSetType($translatedTextAttributeValuesStructure));
155 -
156 - global
157 - $textAttributeIdAttribute, $textAttributeAttribute, $textAttributeValuesStructure, $textAttributeValuesAttribute,
158 - $wgTextAttributeValuesAttributeName, $wgTextAttributeAttributeName;
159 -
160 - $textAttributeIdAttribute = new Attribute("text-attribute-id", "Attribute identifier", "object-id");
161 - $textAttributeObjectAttribute = new Attribute("text-attribute-object-id", "Attribute object", "object-id");
162 - $textAttributeAttribute = new Attribute("text-attribute", $wgTextAttributeAttributeName, new RecordSetType($definedMeaningReferenceStructure));
163 - $textAttributeValuesStructure = new Structure($textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttribute, $objectAttributesAttribute);
164 - $textAttributeValuesAttribute = new Attribute("text-attribute-values", $wgTextAttributeValuesAttributeName, new RecordSetType($textAttributeValuesStructure));
165 -
166 - global
167 - $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute,
168 - $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName;
169 -
170 - $urlAttribute = new Attribute("url", "URL", "url");
171 - $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id");
172 - $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id");
173 - $urlAttributeAttribute = new Attribute("url-attribute", $wgUrlAttributeAttributeName, new RecordSetType($definedMeaningReferenceStructure));
174 - $urlAttributeValuesStructure = new Structure($urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute);
175 - $urlAttributeValuesAttribute = new Attribute("url-attribute-values", $wgUrlAttributeValuesAttributeName, new RecordSetType($urlAttributeValuesStructure));
176 -
177 - global
178 - $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute,
179 - $wgOptionAttributeAttributeName, $wgOptionAttributeOptionAttributeName, $wgOptionAttributeValuesAttributeName;
180 -
181 - $optionAttributeIdAttribute = new Attribute('option-attribute-id', 'Attribute identifier', 'object-id');
182 - $optionAttributeObjectAttribute = new Attribute('option-attribute-object-id', 'Attribute object', 'object-id');
183 - $optionAttributeAttribute = new Attribute('option-attribute', $wgOptionAttributeAttributeName, $definedMeaningReferenceType);
184 - $optionAttributeOptionAttribute = new Attribute('option-attribute-option', $wgOptionAttributeOptionAttributeName, $definedMeaningReferenceType);
185 - $optionAttributeValuesStructure = new Structure($optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $objectAttributesAttribute);
186 - $optionAttributeValuesAttribute = new Attribute('option-attribute-values', $wgOptionAttributeValuesAttributeName, new RecordSetType($optionAttributeValuesStructure));
187 -
188 - global
189 - $optionAttributeOptionIdAttribute, $optionAttributeOptionsAttribute;
190 -
191 - $optionAttributeOptionIdAttribute = new Attribute('option-attribute-option-id', 'Option identifier', 'object-id');
192 - $optionAttributeOptionsStructure = new Structure($optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute);
193 - $optionAttributeOptionsAttribute = new Attribute('option-attribute-options', 'Options', new RecordSetType($optionAttributeOptionsStructure));
194 -
195 - global
196 - $definitionAttribute, $definedMeaningAttribute, $translatedTextAttribute, $classAttributesAttribute,
197 - $wgDefinitionAttributeName;
198 -
199 - if ($filterOnLanguage && !$hasMetaDataAttributes)
200 - $translatedTextAttribute = new Attribute("translated-text", "Text", "text");
201 - else
202 - $translatedTextAttribute = new Attribute("translated-text", "Translated text", new RecordSetType($translatedTextStructure));
203 -
204 - $definitionAttribute = new Attribute("definition", $wgDefinitionAttributeName, new RecordType(new Structure($translatedTextAttribute, $objectAttributesAttribute)));
205 - $definedMeaningAttribute = new Attribute("defined-meaning", "Defined meaning", new RecordType(new Structure($definitionAttribute, $classAttributesAttribute, $alternativeDefinitionsAttribute, $synonymsAndTranslationsAttribute, $relationsAttribute, $classMembershipAttribute, $collectionMembershipAttribute, $objectAttributesAttribute)));
206 -
207 - global
208 - $expressionsAttribute, $expressionMeaningStructure, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute,
209 - $wgExactMeaningsAttributeName, $wgApproximateMeaningsAttributeName;
210 -
211 - $expressionMeaningStructure = new Structure($definedMeaningIdAttribute, $textAttribute, $definedMeaningAttribute);
212 - $expressionExactMeaningsAttribute = new Attribute("expression-exact-meanings", $wgExactMeaningsAttributeName, new RecordSetType($expressionMeaningStructure));
213 - $expressionApproximateMeaningsAttribute = new Attribute("expression-approximate-meanings", $wgApproximateMeaningsAttributeName, new RecordSetType($expressionMeaningStructure));
214 -
215 - global
216 - $expressionMeaningsAttribute, $expressionMeaningsStructure, $expressionApproximateMeaningAttribute;
217 -
218 - $expressionMeaningsStructure = new Structure($expressionExactMeaningsAttribute, $expressionApproximateMeaningAttribute);
219 - $expressionMeaningsAttribute = new Attribute("expression-meanings", "Expression meanings", new RecordType($expressionMeaningsStructure));
220 -
221 - $expressionsAttribute = new Attribute("expressions", "Expressions", new RecordSetType(new Structure($expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute)));
222 -
223 - global
224 - $objectIdAttribute, $objectAttributesStructure, $wgAnnotationAttributeName;
225 -
226 - $objectIdAttribute = new Attribute("object-id", "Object identifier", "object-id");
227 - $objectAttributesStructure = new Structure($objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute);
228 - $objectAttributesAttribute = new Attribute("object-attributes", $wgAnnotationAttributeName, new RecordType($objectAttributesStructure));
229 -
230 - global
231 - $classAttributesStructure,
232 - // $classAttributeClassAttribute,
233 - $classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute;
234 -
235 - $classAttributeIdAttribute = new Attribute("class-attribute-id", "Class attribute identifier", "object-id");
236 - //$classAttributeClassAttribute = new Attribute("class-attribute-class", "Class", "defined-meaning-id");
237 - $classAttributeAttributeAttribute = new Attribute("class-attribute-attribute", "Attribute", new RecordType($definedMeaningReferenceStructure));
238 - $classAttributeLevelAttribute = new Attribute("class-attribute-level", "Level", new RecordType($definedMeaningReferenceStructure));
239 - $classAttributeTypeAttribute = new Attribute("class-attribute-type", "Type", "short-text");
240 - $classAttributesStructure = new Structure($classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute, $optionAttributeOptionsAttribute);
241 - $classAttributesAttribute = new Attribute("class-attributes", "Class attributes", new RecordSetType($classAttributesStructure));
242 -}
243 -
244 -?>
Index: trunk/extensions/Wikidata/OmegaWiki/WiktionaryZ.pm
@@ -1,1063 +0,0 @@
2 -# Example usage to import UMLS into an existing WiktionaryZ database:
3 -# use WiktionaryZ;
4 -# my $importer=new WiktionaryZ('wikidatadb','root','MyPass');
5 -# $importer->setSourceDB('umls');
6 -# $importer->initialize;
7 -# $importer->importCompleteUMLS();
8 -#
9 -# NOTE: When importing UMLS, we expect the presence of the semantic network data
10 -# in the tables SRDEF and the manually created tables SEMRELHIER and SEMTYPEHIER.
11 -# SEMRELHIER and SEMTYPEHIER contain information about the relations between
12 -# semantic types and relation types, using RB as the code for "broader than"
13 -# and RN for "narrower than".
14 -#
15 -# Todo for UMLS:
16 -# SyntransCollection
17 -# RelationCollection
18 -# Fully deal with alternative definitions referring to the same concept
19 -# Deal with preferred lexical expressions, primary concepts (general weighting mechanism?)
20 -
21 -package WiktionaryZ;
22 -use DBI;
23 -use Encode;
24 -use POSIX qw(strftime);
25 -
26 -sub new {
27 - my $type=shift;
28 - my $self={};
29 - $self->{targetdb}=shift;
30 - $self->{targetuser}=shift;
31 - $self->{targetpass}=shift;
32 - $self->{targethost}=shift || 'localhost';
33 - $self->{targetport}=shift || '3306';
34 - $self->{targetdriver}=shift || 'mysql';
35 - bless($self, $type);
36 - return($self);
37 -}
38 -
39 -sub setSourceDB {
40 - my $self=shift;
41 - $self->{sourcedb}=shift;
42 - $self->{sourceuser}=shift || $self->{targetuser};
43 - $self->{sourcepass}=shift || $self->{targetpass};
44 - $self->{sourcehost}=shift || $self->{targethost};
45 - $self->{sourceport}=shift || $self->{targetport};
46 - $self->{sourcedriver}=shift || $self->{targetdriver};
47 -}
48 -
49 -sub connectSourceDB {
50 - my $self=shift;
51 - my $dsn = 'dbi:'.$self->{sourcedriver}.':'.$self->{sourcedb}.':'.$self->{sourcehost}.':'.$self->{sourceport};
52 - $self->{dbs}=DBI->connect($dsn,$self->{sourceuser},$self->{sourcepass});
53 -}
54 -
55 -sub connectTargetDB {
56 - my $self=shift;
57 - my $dsn = 'dbi:'.$self->{targetdriver}.':'.$self->{targetdb}.':'.$self->{targethost}.':'.$self->{targetport};
58 - $self->{dbt}=DBI->connect($dsn,$self->{targetuser},$self->{targetpass});
59 -}
60 -
61 -sub connectDBs() {
62 - my $self = shift;
63 -
64 - $self->connectSourceDB();
65 - $self->connectTargetDB();
66 -}
67 -
68 -sub loadLanguages() {
69 - my $self = shift;
70 -
71 - my %la=$self->loadLangs();
72 - $self->{la}=\%la;
73 - my %la_iso=$self->loadLangsIso();
74 - $self->{la_iso}=\%la_iso;
75 -}
76 -
77 -sub initialize {
78 - my $self=shift;
79 - $self->connectDBs();
80 - $self->loadLanguages();
81 -}
82 -
83 -sub importCompleteUMLS {
84 - my $self=shift;
85 - my $level=shift || 0; # 0= complete; 1=reltypes+; 2=rel+
86 -
87 - my %sourceAbbreviations = $self->loadSourceAbbreviations();
88 - $self->importUMLS(\%sourceAbbreviations, $level);
89 -}
90 -
91 -sub importUMLS() {
92 - my $self=shift;
93 - my $sourceAbbreviationsReference = shift;
94 - my $level=shift || 0; # 0= complete; 1=reltypes+; 2=rel+
95 -
96 - my %sourceAbbreviations = %{$sourceAbbreviationsReference};
97 - my %cid=$self->getOrCreateCollections(\%sourceAbbreviations);
98 - $self->{cid}=\%cid;
99 -
100 - if ($level<1){
101 - while (($sourceAbbreviation, $collectionId) = each %cid) {
102 - print "Import UMLS terms for $sourceAbbreviation\n";
103 - $self->importUMLSterms($sourceAbbreviation, $collectionId);
104 - }
105 - }
106 -
107 - if($level<2) {
108 - print "Import UMLS relation types 'REL'\n";
109 - $self->importUMLSrelationtypes('REL');
110 - print "Import UMLS relation types 'RELA'\n";
111 - $self->importUMLSrelationtypes('RELA');
112 - }
113 -
114 - if($level<3) {
115 - while (($sourceAbbreviation, $collectionId) = each %cid) {
116 - my %rt=$self->loadReltypes();
117 - $self->{reltypes}=\%rt;
118 - print "Import UMLS relations 'REL' for $sourceAbbreviation\n";
119 - $self->importUMLSrelations('REL',$sourceAbbreviation);
120 - print "Import UMLS relations 'RELA' for $sourceAbbreviation\n";
121 - $self->importUMLSrelations('RELA',$sourceAbbreviation);
122 - }
123 - }
124 -
125 - if($level<4) {
126 - print "Import SN types 'STY'\n";
127 - $self->importSNtypes('STY');
128 - print "Import SN types 'RL'\n";
129 - $self->importSNtypes('RL');
130 - print "Import ST relations 'STY'\n";
131 - $self->importSTrelations('STY');
132 - print "Import ST relations 'RL'\n";
133 - $self->importSTrelations('RL');
134 - # $self->importSTrelations2();
135 - }
136 -
137 - if($level<5) {
138 - while (($sourceAbbreviation, $collectionId) = each %cid) {
139 - my %attribs=$self->loadAttributes();
140 - $self->{attribs}=\%attribs;
141 - print "Import UMLS types for $sourceAbbreviation\n";
142 - $self->importUMLSstypes($sourceAbbreviation);
143 - }
144 - }
145 -}
146 -
147 -sub importGEMET {
148 - my $self=shift;
149 - $self->connectSourceDB();
150 - $self->connectTargetDB();
151 - my %la=$self->loadLangs();
152 - $self->{la}=\%la;
153 - my %cid=$self->bootstrapGemetCollection();
154 - $self->{cid}=\%cid;
155 - $self->initRel($self->{cid}{'GEMETREL'});
156 - my %rt=$self->loadReltypes();
157 - $self->{reltypes}=\%rt;
158 - $self->importGemetTerms();
159 - $self->importGemetRelations();
160 - $self->importGemetThemes();
161 -}
162 -
163 -sub importUMLSstypes {
164 - my $self=shift;
165 - my $sab=shift;
166 -
167 - my $getassocs=$self->{dbs}->prepare("select MRSTY.CUI, MRSTY.STY from MRCONSO,MRSTY where MRCONSO.SAB like ? and MRCONSO.CUI=MRSTY.CUI");
168 - $getassocs->execute($sab);
169 - while(my $row=$getassocs->fetchrow_hashref()) {
170 - my %rv=$self->getMidForMember($row->{CUI});
171 - my $att=$self->{attribs}{$row->{STY}};
172 - #print "$rv{mid} is a $row->{STY} ($att)\n";
173 - $self->addRelation($rv{rid},0,$rv{mid},$att, my $checkfordupes=1);
174 - }
175 -}
176 -
177 -sub getCollections(){
178 - my $self=shift;
179 - my %cid;
180 - $cid{'CRISP'}=$self->findCollection($self->findMeaning($self->findItem('CRISP Thesaurus, 2005',$self->{la}{'en'})));
181 - $cid{'STY'}=$self->findCollection($self->findMeaning($self->findItem('Semantic Network 2005AC Semantic Types',$self->{la}{'en'})));
182 - $cid{'RL'}=$self->findCollection($self->findMeaning($self->findItem('Semantic Network 2005AC Relation Types',$self->{la}{'en'})));
183 - $cid{'REL'}=$self->findCollection($self->findMeaning($self->findItem('UMLS Relation Types 2005',$self->{la}{'en'})));
184 - $cid{'RELA'}=$self->findCollection($self->findMeaning($self->findItem('UMLS Relation Attributes 2005',$self->{la}{'en'})));
185 - $cid{'ICPC'}=$self->findCollection($self->findMeaning($self->findItem('The International Classification of Primary Care (ICPC), 1993',$self->{la}{'en'})));
186 - $cid{'MESH'}=$self->findCollection($self->findMeaning($self->findItem('Medical Subject Headings (MeSH), 2005',$self->{la}{'en'})));
187 -# $cid{'SP'}=$self->findCollection($self->findMeaning($self->findItem('Swiss-Prot',$self->{la}{'en'})));
188 - return %cid;
189 -}
190 -
191 -sub findCollection() {
192 - my $self=shift;
193 - my $mid=shift;
194 - my $findcoll=$self->{dbt}->prepare("select collection_id from uw_collection_ns where collection_mid=? and is_latest=1");
195 - $findcoll->execute($mid);
196 - my $row=$findcoll->fetchrow_hashref();
197 - return $row->{collection_id};
198 -}
199 -
200 -sub getCollection {
201 - my $self = shift;
202 - my $expression = shift;
203 -
204 - return $self->findCollection($self->findMeaning($self->findExpressionId($expression,$self->{la}{'en'})));
205 -}
206 -
207 -sub bootstrapCollection {
208 - my $self = shift;
209 - my $expression = shift;
210 - my $collectionType = shift;
211 -
212 - %rv=$self->addExpression($expression,$self->{la}{'en'});
213 - return $self->addCollection($rv{mid},$collectionType);
214 -}
215 -
216 -sub getOrCreateCollection {
217 - my $self = shift;
218 - my $expression = shift;
219 -
220 - my $result = $self->getCollection($expression);
221 -
222 - if (!$result) {
223 - $result = $self->bootstrapCollection($expression, '');
224 - }
225 -
226 - return $result;
227 -}
228 -
229 -sub getOrCreateCollections {
230 - my $self = shift;
231 - my $sourceAbbreviationsReference = shift;
232 - my %sourceAbbreviations = %{$sourceAbbreviationsReference};
233 - my %cid;
234 -
235 - while (($key, $value) = each %sourceAbbreviations) {
236 - $cid{$key} = $self->getOrCreateCollection($value);
237 - }
238 -
239 - return %cid;
240 -}
241 -
242 -sub loadSourceAbbreviations {
243 - my $self = shift;
244 - my %sab;
245 -
246 - my $dataset = $self->{dbs}->prepare("select * from mrsab");
247 - $dataset->execute();
248 - while (my $row = $dataset->fetchrow_hashref()) {
249 - $sab{$row->{RSAB}} = $row->{SON};
250 - }
251 - return %sab;
252 -}
253 -
254 -# SEMTYPEHIER and SEMRELHIER contain only the is_a relationships, whereas
255 -# srstr contains all others
256 -# FIXME: only use SRSTR
257 -sub importSTrelations2 {
258 - my $self=shift;
259 - my $getrels=$self->{dbs}->prepare("select * from srstr where rel!='isa'");
260 - $getrels->execute();
261 - while(my $row=$getrels->fetchrow_hashref()) {
262 - my %rv1=$self->getMidForMember($row->{TYPE1},$self->{cid}{'STY'});
263 - my %rv2=$self->getMidForMember($row->{TYPE2},$self->{cid}{'STY'});
264 - my $rtmid=$self->{reltypes}{$row->{REL}};
265 - #print "Adding relation $row->{REL} ($rtmid) between $row->{TYPE1} and $row->{TYPE2}\n";
266 - $self->addRelation($rv1{rid},$rtmid,$rv1{mid},$rv2{mid},my $checkfordupes=1);
267 - }
268 -}
269 -
270 -
271 -sub importSTrelations {
272 - my $self=shift;
273 - my $which=shift;
274 - my $table;
275 - my $field1;
276 - my $field2;
277 - if($which eq 'STY') {
278 - $table='semtypehier';
279 - $field1='SEMTYPE1';
280 - $field2='SEMTYPE2';
281 - } elsif($which eq 'RL') {
282 - $table='semrelhier';
283 - $field1='RELTYPE1';
284 - $field2='RELTYPE2';
285 - }
286 -
287 - my $gettypehier=$self->{dbs}->prepare("select * from $table");
288 - $gettypehier->execute();
289 - while(my $typehier=$gettypehier->fetchrow_hashref()) {
290 - my %rv1=$self->getMidForMember($typehier->{$field1},$self->{cid}{$which});
291 - my %rv2=$self->getMidForMember($typehier->{$field2},$self->{cid}{$which});
292 - my $rtmid=$self->{reltypes}{$typehier->{RELATION}};
293 - print "Adding relation $typehier->{RELATION} ($rtmid) between $typehier->{$field1} and $typehier->{$field2}\n";
294 - $self->addRelation($rv1{rid},$rtmid,$rv1{mid},$rv2{mid},my $checkfordupes=1);
295 - }
296 -}
297 -
298 -# $member_id - the collection-internal identifier for this member
299 -# $cid The collection in which to search for this member (optional)
300 -# Returns the DefinedMeaningID and the revision id
301 -sub getMidForMember {
302 - my $self=shift;
303 - my $member_id=shift;
304 - my $cid=shift;
305 - my %rv;
306 - my $getmid;
307 - if($cid) {
308 - $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where collection_id=? and internal_member_id=? and is_latest_set=1 limit 1");
309 - $getmid->execute($cid,$member_id);
310 - } else {
311 - $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where internal_member_id=? and is_latest_set=1 limit 1");
312 - $getmid->execute($member_id);
313 - }
314 - my $member_mid=$getmid->fetchrow_hashref();
315 - $rv{mid}=$member_mid->{member_mid};
316 - $rv{rid}=$member_mid->{revision_id};
317 - return %rv;
318 -
319 -}
320 -
321 -sub loadReltypes {
322 - my $self=shift;
323 - my %reltypes;
324 - # Get the relation type
325 - $getreltype=$self->{dbt}->prepare("select member_mid,internal_member_id from uw_collection_contents,uw_collection_ns where uw_collection_ns.collection_type='RELT' and uw_collection_ns.collection_id=uw_collection_contents.collection_id");
326 - $getreltype->execute();
327 - while (my $reltype=$getreltype->fetchrow_hashref()) {
328 - $reltypes{$reltype->{internal_member_id}}=$reltype->{member_mid};
329 - }
330 - return %reltypes;
331 -}
332 -
333 -sub loadAttributes {
334 - my $self=shift;
335 - my %attributes;
336 - $getatt=$self->{dbt}->prepare("select member_mid,internal_member_id from uw_collection_contents,uw_collection_ns where uw_collection_ns.collection_type='ATTR' and uw_collection_ns.collection_id=uw_collection_contents.collection_id");
337 - $getatt->execute();
338 - while (my $att=$getatt->fetchrow_hashref()) {
339 - $attributes{$att->{internal_member_id}}=$att->{member_mid};
340 - }
341 - return %attributes;
342 -}
343 -
344 -
345 -# Get all SRDEF attributes
346 -# Get relations between SRDEF
347 -sub importSNtypes {
348 - my $self=shift;
349 - my $type=shift;
350 - $getsemtypes=$self->{dbs}->prepare("select semtypeab,type,definition from srdef where type=?");
351 - $getsemtypes->execute($type);
352 - while (my $semtype=$getsemtypes->fetchrow_hashref()) {
353 - my $type_expression=$semtype->{semtypeab};
354 - my $type_code=$type_expression;
355 - $type_expression=~s/_/ /g;
356 - $type_expression=lc($type_expression);
357 - my %rv=$self->addExpression($type_expression,$self->{la}{'en'},0,$self->{cid}{$type},$type_code);
358 - $self->addMeaningText($rv{'rid'},$rv{'mid'},$semtype->{definition},undef,$self->{la}{'en'});
359 - #print $type_expression." - $self->{cid}{$type} - $type_code\n";
360 - }
361 -}
362 -
363 -sub importUMLSrelations {
364 - my $self=shift;
365 - my $which=shift; # REL or RELA
366 - my $source=shift; # SAB as MySQL LIKE string
367 - my $getrels;
368 -
369 - if($which eq 'REL') {
370 - $getrels=$self->{dbs}->prepare("select cui1,cui2,rel from MRREL where sab like ?");
371 - } elsif($which eq 'RELA') {
372 - $getrels=$self->{dbs}->prepare("select cui1,cui2,rela from MRREL where sab like ? and rela!=''");
373 - }
374 - $getrels->execute($source);
375 - while(my $rel=$getrels->fetchrow_hashref()) {
376 - my $relid=$rel->{lc($which)};
377 - # These mean the same thing
378 - if($relid eq 'CHD') {
379 - $relid='RN';
380 - } elsif($relid eq 'PAR') {
381 - $relid='RB';
382 - }
383 - $getmid=$self->{dbt}->prepare("select member_mid,revision_id from uw_collection_contents where internal_member_id=? and is_latest_set=1 limit 1");
384 - # Note that the direction in UMLS is opposite to ours
385 - $getmid->execute($rel->{cui2});
386 - my $mid1=$getmid->fetchrow_hashref();
387 - $getmid->execute($rel->{cui1});
388 - my $mid2=$getmid->fetchrow_hashref();
389 - # FIXME: We are ignoring term relations for now!
390 - if(($mid1->{member_mid} && $mid2->{member_mid}) && ($mid1->{member_mid} != $mid2->{member_mid}) && $self->{reltypes}{$relid}) {
391 - # Add the relation
392 - #print "Found relation ".$relid." (".$self->{reltypes}{$relid}.") between ".$mid1->{member_mid}." and ".$mid2->{member_mid}.".\n";
393 - $self->addRelation($mid1->{revision_id},$self->{reltypes}{$relid},$mid1->{member_mid},$mid2->{member_mid},my $checkfordupes=1);
394 - } else {
395 - if(!$mid1->{member_mid} && $mid2->{member_mid}) {
396 - print "Did not find MID for ".$rel->{cui1}."!\n";
397 - } elsif($mid1->{member_mid} && !$mid2->{member_mid}) {
398 - print "Did not find MID for ".$rel->{cui2}."!\n";
399 - } elsif(!$mid1->{member_mid} && !$mid2->{member_mid}) {
400 - print "Did not find MIDs for ".$rel->{cui1}." and ".$rel->{cui2}."!\n";
401 - }
402 - }
403 - }
404 -
405 -}
406 -
407 -
408 -sub bootstrapGemetCollection {
409 - my $self=shift;
410 - my %cid;
411 - %rv=$self->addExpression('GEMET Environmental Thesaurus Relation Types',$self->{la}{'en'});
412 - $cid{'GEMETREL'}=$self->addCollection($rv{mid},'RELT');
413 - %rv=$self->addExpression('GEMET Environmental Thesaurus Relation Types',$self->{la}{'en'});
414 - $cid{'GEMET'}=$self->addCollection($rv{mid},'');
415 - return %cid;
416 -}
417 -
418 -
419 -sub bootstrapCollections {
420 - my $self=shift;
421 - my %cid;
422 - my %rv;
423 -
424 - %rv=$self->addExpression('CRISP Thesaurus, 2005',$self->{la}{'en'});
425 - $cid{'CRISP'}=$self->addCollection($rv{mid},'');
426 - %rv=$self->addExpression('Semantic Network 2005AC Semantic Types',$self->{la}{'en'});
427 - $cid{'STY'}=$self->addCollection($rv{mid},'ATTR');
428 - %rv=$self->addExpression('Semantic Network 2005AC Relation Types',$self->{la}{'en'});
429 - $cid{'RL'}=$self->addCollection($rv{mid},'RELT');
430 - %rv=$self->addExpression('UMLS Relation Types 2005',$self->{la}{'en'});
431 - $cid{'REL'}=$self->addCollection($rv{mid},'RELT');
432 - %rv=$self->addExpression('UMLS Relation Attributes 2005',$self->{la}{'en'});
433 - $cid{'RELA'}=$self->addCollection($rv{mid},'RELT');
434 - %rv=$self->addExpression('The International Classification of Primary Care (ICPC), 1993',$self->{la}{'en'});
435 - $cid{'ICPC'}=$self->addCollection($rv{mid},'');
436 - %rv=$self->addExpression('Medical Subject Headings (MeSH), 2005',$self->{la}{'en'});
437 - $cid{'MESH'}=$self->addCollection($rv{mid},'');
438 -# %rv=$self->addExpression('Swiss-Prot',$self->{la}{'en'});
439 -# $cid{'SP'}=$self->addCollection($rv{mid},'');
440 - return %cid;
441 -}
442 -
443 -sub addCollection {
444 - my $self=shift;
445 - my $mid=shift;
446 - my $collection_type=shift;
447 - my $addcollection=$self->{dbt}->prepare('INSERT INTO uw_collection_ns(collection_mid,is_latest,collection_type) values(?,1,?)');
448 - $addcollection->execute($mid,$collection_type);
449 - my $cid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
450 - my $updatefirstver=$self->{dbt}->prepare('UPDATE uw_collection_ns set first_ver=? where collection_id=?');
451 - $updatefirstver->execute($cid,$cid);
452 - return $cid;
453 -}
454 -
455 -sub importUMLSrelationtypes {
456 - my $self=shift;
457 - my $which=shift;
458 - my $getreltypes;
459 - if($which eq 'REL') {
460 - # CHD and PAR are to be interpreted as RN and RB, SUBX is not used
461 - $getreltypes=$self->{dbs}->prepare("select * from rel where ABBREV!='CHD' and ABBREV!='PAR' and ABBREV!='SUBX'");
462 - } elsif($which eq 'RELA') {
463 - $getreltypes=$self->{dbs}->prepare("select * from rela");
464 - }
465 - $getreltypes->execute();
466 - while(my $reltype=$getreltypes->fetchrow_hashref()) {
467 - my %rv=$self->addExpression($reltype->{FULL},$self->{la}{'en'},0,$self->{cid}{$which},$reltype->{ABBREV});
468 - }
469 -}
470 -
471 -sub importUMLSterms {
472 - my $self=shift;
473 - my $sab=shift; # the source abbreviation which to import
474 - my $cid=shift; # which collection to associate the defined meanings with
475 -
476 - $getterm=$self->{dbs}->prepare("select str,cui,lat from MRCONSO where sab like ?");
477 - $getterm->execute($sab);
478 - my %textmid;
479 - while(my $r=$getterm->fetchrow_hashref()) {
480 - my %rv;
481 - my $dupe=0;
482 - my %cuimid=$self->getMidForMember($r->{cui});
483 -
484 - # Create new expression / Defined Meaning
485 - if(!$cuimid{mid}) {
486 - %rv=$self->addExpression($r->{str},$self->{la_iso}{lc($r->{lat})},0,$cid,$r->{cui});
487 - # If this is the first time we encounter this CUI, import the definitions
488 - # Note that we'll take any definitions, regardless of the SABs specified!
489 - if($rv{mid}!=-1) {
490 - $getdefs=$self->{dbs}->prepare("select def from MRDEF where cui=?");
491 - $getdefs->execute($r->{cui});
492 - while(my $d=$getdefs->fetchrow_hashref()) {
493 - # UMLS only has English definitions
494 - $self->addMeaningText($rv{rid},$rv{mid},$d->{def},0,$self->{la}{'en'});
495 - }
496 - $textmid{$rv{mid}}=1;
497 - }
498 - # Add as SynTrans to existing Defined Meaning
499 - } else {
500 - %rv=$self->addExpression($r->{str},$self->{la_iso}{lc($r->{lat})},$cuimid{mid});
501 - }
502 - }
503 -}
504 -
505 -
506 -sub importGemetTerms {
507 - my $self=shift;
508 - my $cid=shift;
509 - # Get all English terms as base
510 - $getterm=$self->{dbs}->prepare("select * from term where langcode=?");
511 - $getterm->execute('en');
512 - while($r=$getterm->fetchrow_hashref()) {
513 - # Add English term as defined meaning
514 - my %rv=$self->addExpression($r->{name},$self->{la}{'en'},0,);
515 -
516 - # All translations
517 - $gettrans=$self->{dbs}->prepare("select name,langcode from term where id_concept=? and langcode!='en'");
518 - $gettrans->execute($r->{id_concept});
519 - # Add them with the same meaning ID
520 - while($t=$gettrans->fetchrow_hashref()) {
521 - print "Language: $t->{langcode}\n";
522 - %tv=$self->addExpression($t->{name},$self->{la}{$t->{langcode}},$rv{mid});
523 - }
524 - # All definitions
525 - $getdef=$self->{dbs}->prepare("select definition,langcode from scope where id_concept=?");
526 - $getdef->execute($r->{id_concept});
527 - my $tcid=0;
528 - while($d=$getdef->fetchrow_hashref()) {
529 - if(!$tcid) {
530 - my %mv=$self->addMeaningText($rv{rid},$rv{mid},$d->{definition},0,$self->{la}{$d->{langcode}});
531 - $tcid=$mv{tcid};
532 -
533 - } else {
534 - $self->addMeaningText($rv{rid},$rv{mid},$d->{definition},$tcid,$self->{la}{$d->{langcode}});
535 -
536 - }
537 - }
538 - }
539 -}
540 -
541 -
542 -sub importGemetRelations {
543 - my $self=shift;
544 - # Import GEMET relations
545 - my $getrels=$self->{dbs}->prepare("select * from relation");
546 - $getrels->execute();
547 - while(my $rrow=$getrels->fetchrow_hashref()) {
548 - %rv_A=$self->findGemetItem($rrow->{id_concept});
549 - %rv_B=$self->findGemetItem($rrow->{id_relation});
550 - if($rv_A{mid} && $rv_B{mid}) {
551 - $self->addRelation($rv_A{rid},$self->{reltypes}{$rrow->{id_type}},$rv_A{mid},$rv_B{mid});
552 - }
553 - }
554 -}
555 -
556 -sub importGemetThemes {
557 - my $self=shift;
558 - # Get all themes
559 - my $getthemes=$self->{dbs}->prepare("select * from theme");
560 - my $gettheme_set=$self->{dbs}->prepare("select * from theme where id_theme=?");
561 - $getthemes->execute();
562 - while(my $theme_row=$getthemes->fetchrow_hashref()) {
563 - my $theme=$theme_row->{description};
564 - my @themes=split(/[,;]( ){0,1}/,$theme);
565 - foreach(@themes) {
566 - $_=~s/^ *$//i;
567 - if($_) {
568 - # Does this theme have a expression?
569 - my $t=$_;
570 - my %it=$self->findLatestRevision($t,$self->{la}{$theme_row->{langcode}});
571 - if($it{liid}) {
572 - # Get the meaning
573 - print "NEW THEME: $t - retrieving existing MID for LIID... ".$it{liid};
574 - $it{mid}=$self->findMeaning($rv{liid});
575 - print $it{mid}."\n";
576 - #print $t. " is a dupe! - $dupes\n";
577 - #$dupes++;
578 - } else {
579 - # Do we have any of its translations?
580 - # We can only add those if the theme does
581 - # not contain a , - otherwise we can't match!
582 - my $tra_mid=0;
583 - if(!($theme_row->{description}=~m/[,;]/i)) {
584 - print "NEW THEME: $t - no record, looking for its known translations in GEMET\n";
585 - #print "Checking for translations of ".$theme_row->{description}."\n";
586 - $gettheme_set->execute($theme_row->{id_theme});
587 - while((my $tra_row=$gettheme_set->fetchrow_hashref()) && !$tra_mid) {
588 - if($tra_lid=$self->findExpressionId($tra_row->{description},$self->{la}{$tra_row->{langcode}})) {
589 - $tra_mid=$self->findMeaning($tra_lid);
590 -
591 - }
592 - }
593 - } else {
594 - print "NEW THEME: $t - split from the original GEMET data\n";
595 - }
596 - # Let's make one
597 - if($tra_mid) {
598 - print "Adding new term as translation of $tra_mid\n";
599 - %it = $self->addExpression($t,$self->{la}{$theme_row->{langcode}},$tra_mid);
600 - } else {
601 - print "Adding new term independently, we do not know its translations.\n";
602 - %it = $self->addExpression($t,$self->{la}{$theme_row->{langcode}});
603 - }
604 -
605 -
606 - }
607 -
608 - if(!$have_rel{$theme_row->{id_theme}}) {
609 - # Get all items which have this relation
610 - my $getconcepts=$self->{dbs}->prepare('select id_concept from concept_theme where id_theme=?');
611 - $getconcepts->execute($theme_row->{id_theme});
612 - while(my $concrow=$getconcepts->fetchrow_hashref()) {
613 - # Get LIID,RID->meaning for the item
614 - my %tr=$self->findGemetItem($concrow->{id_concept});
615 - if($tr{rid}) {
616 - $self->addRelation($tr{rid},$self->{reltypes}{it},$tr{mid},$it{mid});
617 - print "Tied up a relation..";
618 - } else {
619 - print "Missing record to tie the relation to..";
620 - }
621 - }
622 - print "\n";
623 - $have_rel{$theme_row->{id_theme}}=1;
624 - }
625 -
626 - }
627 - }
628 - }
629 - #Split theme into parts
630 -}
631 -
632 -sub findGemetItem {
633 - my $self=shift;
634 - my $concept_id=shift;
635 - # get a word, language
636 - my $getword=$self->{dbs}->prepare("select langcode,name from term where id_concept=? LIMIT 1");
637 - $getword->execute($concept_id);
638 - my $wordrow=$getword->fetchrow_hashref();
639 -
640 - # find an expression + meaning
641 - my %rv=$self->findLatestRevision($wordrow->{name},$self->{la}{$wordrow->{langcode}});
642 - $rv{mid}=$self->findMeaning($rv{liid});
643 - return %rv;
644 -}
645 -
646 -sub addRelation {
647 - my $self=shift;
648 - my $revid=shift;
649 - my $rtid=shift;
650 - my $mid_A=shift;
651 - my $mid_B=shift;
652 - my $checkfordupes=shift;
653 -
654 - if($checkfordupes) {
655 - my $checkRelationDuplicates=$self->{dbt}->prepare('select 1 as one from uw_meaning_relations where meaning1_mid=? and meaning2_mid=? and relationtype_mid=? and is_latest_set=1 limit 1');
656 - $checkRelationDuplicates->execute($mid_A,$mid_B,$rtid);
657 - #print "Checking dupe $mid_A, $mid_B, relation type $rtid\n";
658 - my $dupecheck=$checkRelationDuplicates->fetchrow_hashref();
659 - if($dupecheck->{one}) {
660 - print "Duplicate relation, not adding.\n";
661 - return false;
662 - }
663 - }
664 -
665 - my $newkey= $self->getSetIdWhere('uw_meaning_relations','meaning1_mid',$mid_A) || $self->getMaxId('set_id','uw_meaning_relations');
666 - my $addrel=$self->{dbt}->prepare('insert into uw_meaning_relations(set_id,meaning1_mid,meaning2_mid,relationtype_mid,is_latest_set,first_set,revision_id) values(?,?,?,?,?,?,?)');
667 - $addrel->execute($newkey,$mid_A,$mid_B,$rtid,1,$newkey,$revid);
668 -
669 - print "newkey: $newkey\n";
670 - print "mid_A: $mid_A\n";
671 - print "mid_B: $mid_B\n";
672 - print "rtid: $rtid\n";
673 - print "revid: $revid\n";
674 -}
675 -
676 -
677 -sub findMeaning {
678 - my $self=shift;
679 - my $liid=shift;
680 - # Search syntrans table
681 - my $getsyn=$self->{dbt}->prepare("select defined_meaning_id from uw_syntrans where expression_id=?");
682 - $getsyn->execute($liid);
683 - my $syn_row=$getsyn->fetchrow_hashref();
684 - if($syn_row->{defined_meaning_id}) {
685 - return $syn_row->{defined_meaning_id};
686 - }
687 - my $getdm=$self->{dbt}->prepare("select defined_meaning_id from uw_defined_meaning where expression_id=? limit 1");
688 - $getdm->execute($liid);
689 - my $dm_row=$getdm->fetchrow_hashref();
690 - if($dm_row->{defined_meaning_id}) {
691 - return $dm_row->{defined_meaning_id};
692 - }
693 - return 0;
694 -}
695 -
696 -# If there already is a meaning text for this DefinedMeaning, it will add the MeaningText as an alternative definition
697 -sub addMeaningText {
698 - my $self=shift;
699 - my $rid=shift;
700 - my $mid=shift;
701 - my $meaningtext=shift; # optional
702 - my $meaningtext_set=shift; # optional TCID set to join with
703 - my $lid=shift; # ID, not code
704 - my %rv;
705 -
706 - # Add text row entry
707 - my $maketext=$self->{dbt}->prepare('insert into text(old_text) values(?)');
708 - $maketext->execute($meaningtext);
709 - # Get text row ID
710 - $tid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
711 - # Get new or existing translated content set ID
712 - $tcid=$meaningtext_set || $self->getMaxId('set_id','translated_content');
713 - # Create new translated content set
714 - my $maketc=$self->{dbt}->prepare('insert into translated_content(set_id,language_id,text_id,first_set,revision_id) values(?,?,?,?,?)');
715 - $maketc->execute($tcid,$lid,$tid,$tcid,$rid);
716 - $rv{tcid}=$tcid;
717 -
718 - # THIS DOESN'T WORK FOR DEFINITIONS IN MULTIPLE LANGUAGES
719 - # Check if a meaning text has already been set
720 - my $lookformeaning=$self->{dbt}->prepare('select meaning_text_tcid from uw_defined_meaning where defined_meaning_id=? and is_latest_ver=1');
721 - $lookformeaning->execute($mid);
722 - my $mrow=$lookformeaning->fetchrow_hashref();
723 - if($mrow->{meaning_text_tcid}) {
724 - # There is a meaning text - the new one is only an alternative
725 - my $altset=$self->getSetIdWhere('uw_alt_meaningtexts','meaning_mid',$mid) || $self->getMaxId('set_id','uw_alt_meaningtexts');
726 - my $addaltmeaning=$self->{dbt}->prepare('insert into uw_alt_meaningtexts(set_id,meaning_mid,meaning_text_tcid,is_latest_set,first_set,revision_id) values(?,?,?,?,?,?)');
727 - $addaltmeaning->execute($altset,$mid,$tcid,1,$altset,$rid)
728 - } else {
729 - my $updatemeaning=$self->{dbt}->prepare('update uw_defined_meaning set meaning_text_tcid=? where defined_meaning_id=?');
730 - $updatemeaning->execute($tcid,$mid);
731 - }
732 - return %rv;
733 -}
734 -
735 -
736 -# If the expression already exists, add a new DefinedMeaning - unless this is a translation or synonym; if a record already exists in SynTrans with this expression _and_ $translation_of as a DefinedMeaning, do not do anything
737 -sub addExpression {
738 - my $self=shift;
739 - # return MID, RID, LID, TCID!
740 - my $expression=shift;
741 - my $lid=shift; # ID, not code
742 - my $translation_of=shift; # 0 or MID (!), optional
743 - my $collection_id=shift; # optional
744 - my $collection_internal_member_id=shift; # what does the collection use to refer to this member?
745 - my %rv;
746 - my $isdupe=0;
747 - my %firv=$self->findLatestRevision($expression,$lid);
748 - if($firv{liid}) { $isdupe=1; }
749 -
750 - if(!$isdupe) {
751 -
752 - #create page
753 - my $pt=$self->canonize($expression);
754 - $makepage=$self->{dbt}->prepare('insert into page(page_namespace,page_title,page_is_new,page_title_language_id,page_touched) values(?,?,?,?,?)');
755 - $makepage->execute(16,$pt,1,$lid,$self->mwtimestamp());
756 - $pid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
757 - print "PID: $pid\n";
758 -
759 - $rv{pid}=$pid;
760 -
761 - #create revision
762 - $makerev=$self->{dbt}->prepare('insert into revision(rev_page,rev_comment,rev_user,rev_user_text,rev_timestamp) values(?,?,?,?,?)');
763 - $makerev->execute($pid,'Initial import',2,'GEMET',$self->mwtimestamp());
764 -
765 - #get revision_id
766 - $rid=$self->getId('select rev_id from revision where rev_page=?',$pid);
767 - $rv{rid}=$rid;
768 -
769 - #update page to link to revision
770 - $updatepage=$self->{dbt}->prepare('update page set page_latest=? where page_id=?');
771 - $updatepage->execute($rid,$pid);
772 -
773 - #create expression
774 - $makeitem=$self->{dbt}->prepare('insert into uw_expression_ns(spelling,language_id,is_latest) values(?,?,1)');
775 - $makeitem->execute($expression,$lid);
776 - $liid=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
777 - $rv{liid}=$liid;
778 -
779 - # update firstver
780 - $updateitem=$self->{dbt}->prepare('update uw_expression_ns set first_ver=? where expression_id=?');
781 - $updateitem->execute($liid,$liid);
782 -
783 - #update revision to link to expression
784 - $updaterev=$self->{dbt}->prepare('update revision set rev_data_id=? where rev_id=?');
785 - $updaterev->execute($liid,$rid);
786 -
787 - } else {
788 -
789 - $rid=$firv{rid};
790 - $liid=$firv{liid};
791 - $rv{rid}=$rid;
792 - $rv{liid}=$liid;
793 -
794 - }
795 -
796 - #create definedmeaning
797 - if(!$translation_of) {
798 - $makemean=$self->{dbt}->prepare('insert into uw_defined_meaning(expression_id,revision_id) values(?,?)');
799 - $makemean->execute($liid,$rid);
800 - # We always want a syntrans record, so in this case it links to its own
801 - # def. meaning
802 - $translation_of=$self->{dbt}->last_insert_id(undef,undef,undef,undef);
803 - $mid=$translation_of;
804 - $rv{mid}=$mid;
805 - $updatemeaningver=$self->{dbt}->prepare('update uw_defined_meaning set first_ver=? where defined_meaning_id=?');
806 - $updatemeaningver->execute($mid,$mid);
807 - if($collection_id) {
808 - $addtocoll=$self->{dbt}->prepare('insert into uw_collection_contents(set_id, collection_id, member_mid, is_latest_set, first_Set, revision_id, internal_member_id) values(?,?,?,?,?,?,?)');
809 - #fixme set association
810 - $addtocoll->execute(1,$collection_id,$mid,1,1,$rid,$collection_internal_member_id);
811 - }
812 - }
813 -
814 - # Check if we already have this specific record
815 - $checkdupes=$self->{dbt}->prepare('select set_id from uw_syntrans where defined_meaning_id=? and expression_id=?');
816 - $checkdupes->execute($translation_of,$liid);
817 - my $duperow=$checkdupes->fetchrow_hashref();
818 - my $dupeid=$duperow->{set_id};
819 - if(!$dupeid) {
820 -
821 - # Check if this is part of a set
822 - $getset=$self->{dbt}->prepare('select set_id from uw_syntrans where defined_meaning_id=? and is_latest_set=1');
823 - $getset->execute($mid);
824 - $row=$getset->fetchrow_hashref();
825 - my $setid=$row->{set_id} || $self->getMaxId('set_id','uw_syntrans');
826 - # Add syntrans record
827 - $maketrans=$self->{dbt}->prepare('insert into uw_syntrans(set_id,defined_meaning_id,expression_id,first_set,revision_id,is_latest_set,endemic_meaning) values(?,?,?,?,?,1,1)');
828 - $maketrans->execute($setid,$translation_of,$liid,$setid,$rid);
829 - $rv{setid}=$setid;
830 - $rv{mid}=$translation_of;
831 - } else{
832 - $rv{setid}=$dupeid; # Dupe
833 - $rv{mid}=-1; # Dupe
834 - }
835 - return %rv;
836 -
837 -}
838 -
839 -sub findLatestRevision {
840 - my $self = shift;
841 - my $expressionSpelling = shift;
842 - my $languageId = shift;
843 -
844 - my $expressionId = $self->findExpressionId($expressionSpelling, $languageId);
845 - if ($expressionId != 0) {
846 - my $getRevisionId = $self->{dbt}->prepare('select rev_id from revision where rev_data_id=?');
847 - $getRevisionId->execute($expressionId);
848 - my %revision;
849 - $revision{liid} = $expressionId;
850 - $revision{rid} = $getRevisionId->fetchrow_hashref->{rev_id};
851 - return %revision;
852 - } else {
853 - return 0;
854 - }
855 -}
856 -
857 -sub findExpressionId {
858 - my $self = shift;
859 - my $expressionSpelling = shift;
860 - my $languageId = shift;
861 -
862 - my $getItem = $self->{dbt}->prepare("select expression_id from uw_expression_ns where spelling=binary ? and language_id=? and is_latest=1");
863 - $getItem->execute($expressionSpelling, $languageId);
864 - my $itemRow = $getItem->fetchrow_hashref();
865 - if ($itemRow) {
866 - return $itemRow->{expression_id};
867 - } else {
868 - return 0;
869 - }
870 -}
871 -
872 -sub getMaxId {
873 - my $self=shift;
874 - my $field=shift;
875 - my $table=shift;
876 - $getmax=$self->{dbt}->prepare("select max($field) as maxset from $table");
877 - $getmax->execute();
878 - my $row=$getmax->fetchrow_hashref();
879 - return $row->{maxset}+1;
880 -}
881 -
882 -sub getSetIdWhere {
883 - my $self=shift;
884 - my $table=shift;
885 - my $wherefield=shift;
886 - my $wherekey=shift;
887 - $getmax=$self->{dbt}->prepare("select set_id from $table WHERE $wherefield=? AND is_latest_set=1 limit 1");
888 - $getmax->execute($wherekey);
889 - my $row=$getmax->fetchrow_hashref();
890 - return $row->{set_id};
891 -}
892 -
893 -
894 -sub getId {
895 - my $self=shift;
896 - my $prep=shift;
897 - $prep=~m/select (.*?) from/i;
898 - my $field=$1;
899 - my $getlang=$self->{dbt}->prepare($prep);
900 - $getlang->execute(@_);
901 - my $row=$getlang->fetchrow_hashref();
902 - my $id=$row->{$field};
903 - return $id;
904 -}
905 -
906 -sub mwtimestamp {
907 - my $self=shift;
908 - use POSIX qw(strftime);
909 - return(strftime "%Y%m%d%H%M%S", localtime);
910 -}
911 -
912 -
913 -sub canonize {
914 - my $self=shift;
915 - my $title=shift;
916 - #$title=ucfirst($title);
917 - $title=~s/ /_/ig;
918 - return $title;
919 -}
920 -
921 -sub initlangs {
922 - my $self=shift;
923 - %langs=(
924 - en_en=>'English',
925 - en_de=>'Englisch',
926 - 'en-US_de'=>'Englisch (USA)',
927 - 'en-US_en'=>'English (United States)',
928 - bg_en=>'Bulgarian',
929 - bg_de=>'Bulgarisch',
930 - cs_en=>'Czech',
931 - cs_de=>'Tschechisch',
932 - da_en=>'Dansk',
933 - da_de=>'D?isch',
934 - de_en=>'German',
935 - de_de=>'Deutsch',
936 - es_en=>'Spanish',
937 - es_de=>'Spanisch',
938 - et_en=>'Estonian',
939 - et_de=>'Estnisch',
940 - eu_en=>'Basque',
941 - eu_de=>'Baskisch',
942 - fi_en=>'Finnish',
943 - fi_de=>'Finnisch',
944 - fr_en=>'French',
945 - fr_de=>'Franz?isch',
946 - hu_en=>'Hungarian',
947 - hu_de=>'Ungarisch',
948 - it_en=>'Italian',
949 - it_de=>'Italienisch',
950 - nl_en=>'Dutch',
951 - nl_de=>'Niederl?disch',
952 - no_en=>'Norwegian',
953 - no_de=>'Norwegisch',
954 - pl_en=>'Polish',
955 - pl_de=>'Polnisch',
956 - pt_en=>'Portuguese',
957 - pt_de=>'Portugiesisch',
958 - ru_en=>'Russian',
959 - ru_de=>'Russisch',
960 - sk_en=>'Slovak',
961 - sk_de=>'Slowakische Sprache',
962 - sl_en=>'Slovenian',
963 - sl_de=>'Slowenisch',
964 - el_en=>'Greek',
965 - el_de=>'Griechisch',
966 - sv_en=>'Swedish',
967 - sv_de=>'Schwedisch');
968 - foreach(keys(%langs)) {
969 - $key=$_;
970 - $key=~m/(.*?)_(.*)/i;
971 - $lang=$1;
972 - #print "Lang: $lang\n";
973 - $wordlang=$2;
974 - if($wordlang eq 'en') {
975 - $addwm=$self->{dbt}->prepare("insert into language(wikimedia_key) values(?)");
976 - $addwm->execute($lang);
977 - }
978 - }
979 - foreach(keys(%langs)) {
980 - $key=$_;
981 - $key=~m/(.*?)_(.*)/i;
982 - $lang=$1;
983 - #print "Lang: $lang\n";
984 - $wordlang=$2;
985 - $langword_u=$langs{$key};
986 - $langword=encode("utf8",$langword_u);
987 - $newwm=$self->{dbt}->prepare("select language_id from language where wikimedia_key=?");
988 - $newwm->execute($lang);
989 - my $row=$newwm->fetchrow_hashref();
990 - $newwm->execute('en');
991 - my $en_row=$newwm->fetchrow_hashref();
992 - $newwm->execute('de');
993 - my $de_row=$newwm->fetchrow_hashref();
994 - $newword=$self->{dbt}->prepare("insert into language_names values (?,?,?)");
995 - if($wordlang eq 'en') {
996 - $newword->execute($row->{language_id},$en_row->{language_id},$langword);
997 - } elsif($wordlang eq 'de') {
998 - $newword->execute($row->{language_id},$de_row->{language_id},$langword);
999 - }
1000 - }
1001 -}
1002 -
1003 -sub initRel {
1004 - my $self=shift;
1005 - my $cid=shift;
1006 - %rel_types=(
1007 - bt_en=>'broader terms',
1008 - bt_de=>'breitere Begriffe',
1009 - nt_en=>'narrower terms',
1010 - nt_de=>'engere Begriffe',
1011 - rt_en=>'related terms',
1012 - rt_de=>'verwandte Begriffe',
1013 - it_en=>'is part of theme',
1014 - it_de=>'ist Themenbestandteil von'
1015 - );
1016 -
1017 - %rel_definitions=(
1018 - bt_en=>'Those terms in a thesaurus which are broader than others',
1019 - bt_de=>'Die Begriffe in einem Thesaurus, die breiter sind als andere',
1020 - nt_en=>'Those terms in a thesaurus which are narrower than others',
1021 - nt_de=>'Die Begriffe in einem Thesaurus, die enger sind als andere',
1022 - rt_en=>'Those terms in a thesaurus which are related to others',
1023 - rt_de=>'Die Begriffe in einem Thesaurus, die mit anderen verwandt sind',
1024 - it_en=>'Those terms in a thesaurus or dictionary which are associated with a topic',
1025 - it_de=>'Die Begriffe in einem Thesaurus oder Woerterbuch, die mit einem Thema assoziiert sind');
1026 -
1027 - foreach(keys(%rel_types)) {
1028 - $key=$_;
1029 - $key=~m/(..)_(..)/i;
1030 - $ident=$1;
1031 - $lang=$2;
1032 - if($lang eq 'de') {
1033 - $en_key="$ident\_en";
1034 - my %rv=$self->addExpression($rel_types{$en_key},$self->{la}{'en'},0,$cid,$ident);
1035 - $self->addMeaningText($rv{rid},$rv{mid},$rel_definitions{$en_key},0,$self->{la}{'en'});
1036 - my %dv=$self->addExpression($rel_types{$key},$self->{la}{'de'},$rv{'mid'});
1037 - $self->addMeaningText($dv{rid},$dv{mid},$rel_definitions{$key},$rv{'tcid'},$self->{la}{'de'});
1038 - }
1039 - }
1040 -}
1041 -
1042 -sub loadLangs {
1043 - my $self=shift;
1044 - my %la;
1045 - $getlangs=$self->{dbt}->prepare('select language_id,wikimedia_key from language');
1046 - $getlangs->execute();
1047 - while($langrow=$getlangs->fetchrow_hashref()) {
1048 - $la{$langrow->{wikimedia_key}}=$langrow->{language_id};
1049 - }
1050 - return %la;
1051 -}
1052 -
1053 -sub loadLangsIso {
1054 - my $self=shift;
1055 - my %la_iso;
1056 - $getlangs=$self->{dbt}->prepare('select language_id,iso639_2 from language');
1057 - $getlangs->execute();
1058 - while($langrow=$getlangs->fetchrow_hashref()) {
1059 - $la_iso{$langrow->{iso639_2}}=$langrow->{language_id};
1060 - }
1061 - return %la_iso;
1062 -}
1063 -
1064 -return(1);
Index: trunk/extensions/Wikidata/OmegaWiki/WiktionaryZEditors.php
@@ -1,490 +0,0 @@
2 -<?php
3 -
4 -require_once('Editor.php');
5 -require_once('OmegaWikiAttributes.php');
6 -require_once('WikiDataBootstrappedMeanings.php');
7 -require_once('Fetcher.php');
8 -
9 -function initializeObjectAttributeEditors($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
10 - global
11 - $objectAttributesAttribute,
12 - $definedMeaningObjectAttributesEditor, $definedMeaningIdAttribute,
13 - $definitionObjectAttributesEditor, $definedMeaningIdAttribute,
14 - $synonymsAndTranslationsObjectAttributesEditor, $syntransIdAttribute,
15 - $relationsObjectAttributesEditor, $relationIdAttribute,
16 - $possiblySynonymousObjectAttributesEditor, $possiblySynonymousIdAttribute,
17 - $textValueObjectAttributesEditor, $textAttributeIdAttribute,
18 - $urlValueObjectAttributesEditor, $urlAttributeIdAttribute,
19 - $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute,
20 - $optionValueObjectAttributesEditor, $optionAttributeIdAttribute,
21 - $definedMeaningMeaningName, $definitionMeaningName,
22 - $relationMeaningName, $synTransMeaningName,
23 - $annotationMeaningName;
24 -
25 - $definedMeaningObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
26 - $definitionObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
27 - $synonymsAndTranslationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
28 - $possiblySynonymousObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
29 - $relationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
30 - $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
31 - $urlValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
32 - $translatedTextValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
33 - $optionValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
34 -
35 - setObjectAttributesEditor($definedMeaningObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $definedMeaningIdAttribute), $definedMeaningMeaningName, new ObjectIdFetcher(0, $definedMeaningIdAttribute));
36 - setObjectAttributesEditor($definitionObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new DefinitionObjectIdFetcher(0, $definedMeaningIdAttribute), $definitionMeaningName, new ObjectIdFetcher(0, $definedMeaningIdAttribute));
37 - setObjectAttributesEditor($synonymsAndTranslationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $syntransIdAttribute), $synTransMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
38 - setObjectAttributesEditor($possiblySynonymousObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $possiblySynonymousIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
39 - setObjectAttributesEditor($relationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $relationIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
40 - setObjectAttributesEditor($textValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
41 - setObjectAttributesEditor($urlValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
42 - setObjectAttributesEditor($translatedTextValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $translatedTextAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
43 - setObjectAttributesEditor($optionValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $optionAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
44 -}
45 -
46 -function getTransactionEditor($attribute) {
47 - global
48 - $userAttribute, $timestampAttribute;
49 -
50 - $transactionEditor = new RecordTableCellEditor($attribute);
51 - $transactionEditor->addEditor(createUserViewer($userAttribute));
52 - $transactionEditor->addEditor(new TimestampEditor($timestampAttribute, new SimplePermissionController(false), true));
53 -
54 - return $transactionEditor;
55 -}
56 -
57 -function createTableLifeSpanEditor($attribute) {
58 - global
59 - $addTransactionAttribute, $removeTransactionAttribute;
60 -
61 - $result = new RecordTableCellEditor($attribute);
62 - $result->addEditor(getTransactionEditor($addTransactionAttribute));
63 - $result->addEditor(getTransactionEditor($removeTransactionAttribute));
64 -
65 - return $result;
66 -}
67 -
68 -function addTableLifeSpanEditor($editor, $showRecordLifeSpan) {
69 - global
70 - $recordLifeSpanAttribute, $addTransactionAttribute, $removeTransactionAttribute, $wgRequest;
71 -
72 - if ($wgRequest->getText('action') == 'history' && $showRecordLifeSpan)
73 - $editor->addEditor(createTableLifeSpanEditor($recordLifeSpanAttribute));
74 -}
75 -
76 -function addTableAuthorityEditor($editor, $showAuthority) {
77 - global
78 - $authorityAttribute;
79 -
80 - if ($showAuthority)
81 - $editor->addEditor(createShortTextViewer($authorityAttribute));
82 -}
83 -
84 -function addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority) {
85 - addTableLifeSpanEditor($editor, $showRecordLifeSpan);
86 - addTableAuthorityEditor($editor, $showAuthority);
87 -}
88 -
89 -function getDefinitionEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
90 - global
91 - $definitionAttribute, $translatedTextAttribute, $definitionObjectAttributesEditor;
92 -
93 - if ($filterLanguageId == 0)
94 - $controller = new DefinedMeaningDefinitionController();
95 - else
96 - $controller = new DefinedMeaningFilteredDefinitionController($filterLanguageId);
97 -
98 - $editor = new RecordDivListEditor($definitionAttribute);
99 - $editor->addEditor(getTranslatedTextEditor($translatedTextAttribute, $controller, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
100 - $editor->addEditor(new PopUpEditor($definitionObjectAttributesEditor, 'Annotation'));
101 -
102 - return $editor;
103 -}
104 -
105 -function getTranslatedTextEditor($attribute, $controller, $filterLanguageId, $showRecordLifeSpan, $showAuthority) {
106 - global
107 - $languageAttribute, $textAttribute;
108 -
109 - if ($filterLanguageId == 0 || $showRecordLifeSpan || $showAuthority) {
110 - $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $controller);
111 -
112 - if ($filterLanguageId == 0)
113 - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
114 -
115 - $editor->addEditor(new TextEditor($textAttribute, new SimplePermissionController(true), true));
116 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
117 - }
118 - else
119 - $editor = new TextEditor($attribute, new SimplePermissionController(true), true, false, 0, $controller);
120 -
121 - return $editor;
122 -}
123 -
124 -function setObjectAttributesEditor($objectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, $objectIdFetcher, $levelDefinedMeaningName, $dmObjectIdFetcher) {
125 - $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new TextAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
126 - $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, new TranslatedTextAttributeValuesController($objectIdFetcher, $filterLanguageId), $levelDefinedMeaningName, $dmObjectIdFetcher));
127 - $objectAttributesEditor->addEditor(getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new URLAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
128 - $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new OptionAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
129 -}
130 -
131 -function getAlternativeDefinitionsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
132 - global
133 - $alternativeDefinitionsAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
134 -
135 - if ($filterLanguageId == 0)
136 - $alternativeDefinitionController = new DefinedMeaningAlternativeDefinitionController();
137 - else
138 - $alternativeDefinitionController = new DefinedMeaningFilteredAlternativeDefinitionController($filterLanguageId);
139 -
140 - $editor = new RecordSetTableEditor($alternativeDefinitionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningAlternativeDefinitionsController($filterLanguageId));
141 - $editor->addEditor(getTranslatedTextEditor($alternativeDefinitionAttribute, $alternativeDefinitionController, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
142 - $editor->addEditor(new DefinedMeaningReferenceEditor($sourceAttribute, new SimplePermissionController(false), true));
143 -
144 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
145 -
146 - return $editor;
147 -}
148 -
149 -function getExpressionTableCellEditor($attribute, $filterLanguageId) {
150 - global
151 - $languageAttribute, $spellingAttribute;
152 -
153 - if ($filterLanguageId == 0) {
154 - $editor = new RecordTableCellEditor($attribute);
155 - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
156 - $editor->addEditor(new SpellingEditor($spellingAttribute, new SimplePermissionController(false), true));
157 - }
158 - else
159 - $editor = new SpellingEditor($attribute, new SimplePermissionController(false), true);
160 -
161 - return $editor;
162 -}
163 -
164 -function getClassAttributesEditor($showRecordLifeSpan, $showAuthority) {
165 - global
166 - $definedMeaningIdAttribute, $classAttributesAttribute, $classAttributeLevelAttribute, $classAttributeAttributeAttribute, $classAttributeTypeAttribute;
167 -
168 - $tableEditor = new RecordSetTableEditor($classAttributesAttribute, new SimplePermissionController(true), new ShowEditFieldForClassesChecker(0, $definedMeaningIdAttribute), new AllowAddController(true), true, false, new ClassAttributesController());
169 - $tableEditor->addEditor(new ClassAttributesLevelDefinedMeaningEditor($classAttributeLevelAttribute, new SimplePermissionController(false), true));
170 - $tableEditor->addEditor(new DefinedMeaningReferenceEditor($classAttributeAttributeAttribute, new SimplePermissionController(false), true));
171 - $tableEditor->addEditor(new ClassAttributesTypeEditor($classAttributeTypeAttribute, new SimplePermissionController(false), true));
172 - $tableEditor->addEditor(new PopupEditor(getOptionAttributeOptionsEditor(), 'Options'));
173 -
174 - addTableMetadataEditors($tableEditor, $showRecordLifeSpan, $showAuthority);
175 -
176 - return $tableEditor;
177 -}
178 -
179 -function getSynonymsAndTranslationsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
180 - global
181 - $synonymsAndTranslationsAttribute, $identicalMeaningAttribute, $expressionIdAttribute,
182 - $expressionAttribute, $synonymsAndTranslationsObjectAttributesEditor;
183 -
184 - $tableEditor = new RecordSetTableEditor($synonymsAndTranslationsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new SynonymTranslationController($filterLanguageId));
185 - $tableEditor->addEditor(getExpressionTableCellEditor($expressionAttribute, $filterLanguageId));
186 - $tableEditor->addEditor(new BooleanEditor($identicalMeaningAttribute, new SimplePermissionController(true), true, true));
187 - $tableEditor->addEditor(new PopUpEditor($synonymsAndTranslationsObjectAttributesEditor, 'Annotation'));
188 -
189 - addTableMetadataEditors($tableEditor, $showRecordLifeSpan, $showAuthority);
190 -
191 - return $tableEditor;
192 -}
193 -
194 -function getDefinedMeaningRelationsEditor($showRecordLifeSpan, $showAuthority) {
195 - global
196 - $relationsAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute,
197 - $relationsObjectAttributesEditor;
198 -
199 - $editor = new RecordSetTableEditor($relationsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningRelationController());
200 - $editor->addEditor(new RelationTypeReferenceEditor($relationTypeAttribute, new SimplePermissionController(false), true));
201 - $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
202 - $editor->addEditor(new PopUpEditor($relationsObjectAttributesEditor, 'Annotation'));
203 -
204 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
205 -
206 - return $editor;
207 -}
208 -
209 -function getDefinedMeaningReciprocalRelationsEditor($showRecordLifeSpan, $showAuthority) {
210 - global
211 - $reciprocalRelationsAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute,
212 - $relationsObjectAttributesEditor;
213 -
214 - $editor = new RecordSetTableEditor($reciprocalRelationsAttribute, new SimplePermissionController(false), new ShowEditFieldChecker(true), new AllowAddController(false), false, false, null);
215 - $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
216 - $editor->addEditor(new RelationTypeReferenceEditor($relationTypeAttribute, new SimplePermissionController(false), true));
217 - $editor->addEditor(new PopUpEditor($relationsObjectAttributesEditor, 'Annotation'));
218 -
219 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
220 -
221 - return $editor;
222 -}
223 -
224 -function getDefinedMeaningClassMembershipEditor($showRecordLifeSpan, $showAuthority) {
225 - global
226 - $classMembershipAttribute, $classAttribute;
227 -
228 - $editor = new RecordSetTableEditor($classMembershipAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningClassMembershipController());
229 - $editor->addEditor(new ClassReferenceEditor($classAttribute, new SimplePermissionController(false), true));
230 -
231 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
232 -
233 - return $editor;
234 -}
235 -
236 -function getGroupedRelationTypeEditor($groupedRelationsAttribute, $groupedRelationIdAttribute, $otherDefinedMeaningAttribute, $relationTypeId, $showRecordLifeSpan, $showAuthority, $objectAttributesEditor) {
237 - $editor = new RecordSetTableEditor(
238 - $groupedRelationsAttribute,
239 - new SimplePermissionController(true),
240 - new ShowEditFieldChecker(true),
241 - new AllowAddController(true),
242 - true,
243 - false,
244 - new GroupedRelationTypeController($relationTypeId, $groupedRelationIdAttribute, $otherDefinedMeaningAttribute)
245 - );
246 -
247 - $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
248 -
249 - if ($objectAttributesEditor != null)
250 - $editor->addEditor(new PopUpEditor($objectAttributesEditor, 'Annotation'));
251 -
252 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
253 -
254 - return $editor;
255 -}
256 -
257 -function getDefinedMeaningCollectionMembershipEditor($showRecordLifeSpan, $showAuthority) {
258 - global
259 - $collectionMembershipAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute;
260 -
261 - $editor = new RecordSetTableEditor($collectionMembershipAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningCollectionController());
262 - $editor->addEditor(new CollectionReferenceEditor($collectionMeaningAttribute, new SimplePermissionController(false), true));
263 - $editor->addEditor(new ShortTextEditor($sourceIdentifierAttribute, new SimplePermissionController(true), true));
264 -
265 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
266 -
267 - return $editor;
268 -}
269 -
270 -function getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
271 - global
272 - $textAttributeAttribute, $textAttribute, $textAttributeValuesAttribute, $textValueObjectAttributesEditor;
273 -
274 - $editor = new RecordSetTableEditor($textAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
275 - $editor->addEditor(new TextAttributeEditor($textAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
276 - $editor->addEditor(new TextEditor($textAttribute, new SimplePermissionController(true), true));
277 - $editor->addEditor(new PopUpEditor($textValueObjectAttributesEditor, 'Annotation'));
278 -
279 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
280 -
281 - return $editor;
282 -}
283 -
284 -function getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
285 - global
286 - $urlAttributeAttribute, $urlAttribute, $urlAttributeValuesAttribute, $urlValueObjectAttributesEditor;
287 -
288 - $editor = new RecordSetTableEditor($urlAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
289 - $editor->addEditor(new TextAttributeEditor($urlAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
290 - $editor->addEditor(new URLEditor($urlAttribute, new SimplePermissionController(true), true));
291 - $editor->addEditor(new PopUpEditor($urlValueObjectAttributesEditor, 'Annotation'));
292 -
293 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
294 -
295 - return $editor;
296 -}
297 -
298 -function getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
299 - global
300 - $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute, $translatedTextValueObjectAttributesEditor;
301 -
302 - if ($filterLanguageId == 0)
303 - $translatedTextAttributeValueController = new TranslatedTextAttributeValueController();
304 - else
305 - $translatedTextAttributeValueController = new FilteredTranslatedTextAttributeValueController($filterLanguageId);
306 -
307 - $editor = new RecordSetTableEditor($translatedTextAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
308 - $editor->addEditor(new TranslatedTextAttributeEditor($translatedTextAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
309 - $editor->addEditor(getTranslatedTextEditor($translatedTextValueAttribute, $translatedTextAttributeValueController, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
310 - $editor->addEditor(new PopUpEditor($translatedTextValueObjectAttributesEditor, 'Annotation'));
311 -
312 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
313 -
314 - return $editor;
315 -}
316 -
317 -function getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
318 - global
319 - $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute, $optionValueObjectAttributesEditor;
320 -
321 - $editor = new RecordSetTableEditor($optionAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
322 -
323 - $editor->addEditor(new OptionAttributeEditor($optionAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
324 - $editor->addEditor(new OptionSelectEditor($optionAttributeOptionAttribute, new SimplePermissionController(false), true));
325 - $editor->addEditor(new PopUpEditor($optionValueObjectAttributesEditor, 'Annotation'));
326 -
327 - addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
328 -
329 - return $editor;
330 -}
331 -
332 -function getOptionAttributeOptionsEditor() {
333 - global
334 - $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsAttribute;
335 -
336 - $editor = new RecordSetTableEditor($optionAttributeOptionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new OptionAttributeOptionsController());
337 - $editor->addEditor(new DefinedMeaningReferenceEditor($optionAttributeOptionAttribute, new SimplePermissionController(false), true));
338 - $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
339 -
340 - return $editor;
341 -}
342 -
343 -function getExpressionMeaningsEditor($attribute, $allowAdd, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
344 - global
345 - $definedMeaningIdAttribute;
346 -
347 - $definedMeaningEditor = getDefinedMeaningEditor($filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority);
348 -
349 - $definedMeaningCaptionEditor = new DefinedMeaningHeaderEditor($definedMeaningIdAttribute, new SimplePermissionController(false), true, 75);
350 - $definedMeaningCaptionEditor->setAddText("New exact meaning");
351 -
352 - $expressionMeaningsEditor = new RecordSetListEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController($allowAdd), false, $allowAdd, new ExpressionMeaningController($filterLanguageId), 3, false);
353 - $expressionMeaningsEditor->setCaptionEditor($definedMeaningCaptionEditor);
354 - $expressionMeaningsEditor->setValueEditor($definedMeaningEditor);
355 -
356 - return $expressionMeaningsEditor;
357 -}
358 -
359 -function getExpressionsEditor($spelling, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
360 - global
361 - $expressionMeaningsAttribute, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute, $expressionAttribute, $languageAttribute, $expressionsAttribute;
362 -
363 - $expressionMeaningsRecordEditor = new RecordUnorderedListEditor($expressionMeaningsAttribute, 3);
364 -
365 - $exactMeaningsEditor = getExpressionMeaningsEditor($expressionExactMeaningsAttribute, true, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority);
366 - $expressionMeaningsRecordEditor->addEditor($exactMeaningsEditor);
367 - $expressionMeaningsRecordEditor->addEditor(getExpressionMeaningsEditor($expressionApproximateMeaningsAttribute, false, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority));
368 -
369 - $expressionMeaningsRecordEditor->expandEditor($exactMeaningsEditor);
370 -
371 - if ($filterLanguageId == 0) {
372 - $expressionEditor = new RecordSpanEditor($expressionAttribute, ': ', ' - ');
373 - $expressionEditor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
374 -
375 - $expressionsEditor = new RecordSetListEditor($expressionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), false, false, new ExpressionController($spelling, $filterLanguageId), 2, true);
376 - $expressionsEditor->setCaptionEditor($expressionEditor);
377 - $expressionsEditor->setValueEditor($expressionMeaningsRecordEditor);
378 - }
379 - else {
380 - $expressionEditor = new RecordSubRecordEditor($expressionAttribute);
381 - $expressionEditor->setSubRecordEditor($expressionMeaningsRecordEditor);
382 -
383 - $expressionsEditor = new RecordSetFirstRecordEditor($expressionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), false, false, new ExpressionController($spelling, $filterLanguageId));
384 - $expressionsEditor->setRecordEditor($expressionEditor);
385 - }
386 -
387 - return $expressionsEditor;
388 -}
389 -
390 -function getDefinedMeaningEditor($filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
391 - global
392 - $definedMeaningAttribute, $possiblySynonymousIdAttribute, $possiblySynonymousAttribute,
393 - $possibleSynonymAttribute, $definedMeaningObjectAttributesEditor, $possiblySynonymousObjectAttributesEditor;
394 -
395 - $definitionEditor = getDefinitionEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority);
396 - $classAttributesEditor = getClassAttributesEditor($showRecordLifeSpan, $showAuthority);
397 - $synonymsAndTranslationsEditor = getSynonymsAndTranslationsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority);
398 - $relationsEditor = getDefinedMeaningRelationsEditor($showRecordLifeSpan, $showAuthority);
399 - $reciprocalRelationsEditor = getDefinedMeaningReciprocalRelationsEditor($showRecordLifeSpan, $showAuthority);
400 - $classMembershipEditor = getDefinedMeaningClassMembershipEditor($showRecordLifeSpan, $showAuthority);
401 - $collectionMembershipEditor = getDefinedMeaningCollectionMembershipEditor($showRecordLifeSpan, $showAuthority);
402 -
403 - $definedMeaningEditor = new RecordUnorderedListEditor($definedMeaningAttribute, 4);
404 - $definedMeaningEditor->addEditor($definitionEditor);
405 - $definedMeaningEditor->addEditor($classAttributesEditor);
406 - $definedMeaningEditor->addEditor(getAlternativeDefinitionsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority));
407 - $definedMeaningEditor->addEditor($synonymsAndTranslationsEditor);
408 -
409 - if ($possiblySynonymousRelationTypeId != 0)
410 - $definedMeaningEditor->addEditor(
411 - getGroupedRelationTypeEditor(
412 - $possiblySynonymousAttribute,
413 - $possiblySynonymousIdAttribute,
414 - $possibleSynonymAttribute,
415 - $possiblySynonymousRelationTypeId,
416 - $showRecordLifeSpan,
417 - $showAuthority,
418 - $possiblySynonymousObjectAttributesEditor
419 - )
420 - );
421 -
422 - $definedMeaningEditor->addEditor($relationsEditor);
423 - $definedMeaningEditor->addEditor($reciprocalRelationsEditor);
424 - $definedMeaningEditor->addEditor($classMembershipEditor);
425 - $definedMeaningEditor->addEditor($collectionMembershipEditor);
426 - $definedMeaningEditor->addEditor($definedMeaningObjectAttributesEditor);
427 -
428 - $definedMeaningEditor->expandEditor($definitionEditor);
429 - $definedMeaningEditor->expandEditor($synonymsAndTranslationsEditor);
430 -
431 - return $definedMeaningEditor;
432 -}
433 -
434 -function createTableViewer($attribute) {
435 - return new RecordSetTableEditor($attribute, new SimplePermissionController(false), new ShowEditFieldChecker(true), new AllowAddController(false), false, false, null);
436 -}
437 -
438 -function createLanguageViewer($attribute) {
439 - return new LanguageEditor($attribute, new SimplePermissionController(false), false);
440 -}
441 -
442 -function createLongTextViewer($attribute) {
443 - $result = new TextEditor($attribute, new SimplePermissionController(false), false);
444 -
445 - return $result;
446 -}
447 -
448 -function createShortTextViewer($attribute) {
449 - return new ShortTextEditor($attribute, new SimplePermissionController(false), false);
450 -}
451 -
452 -function createURLViewer($attribute) {
453 - return new URLEditor($attribute, new SimplePermissionController(false), false);
454 -}
455 -
456 -function createBooleanViewer($attribute) {
457 - return new BooleanEditor($attribute, new SimplePermissionController(false), false, false);
458 -}
459 -
460 -function createDefinedMeaningReferenceViewer($attribute) {
461 - return new DefinedMeaningReferenceEditor($attribute, new SimplePermissionController(false), false);
462 -}
463 -
464 -function createSuggestionsTableViewer($attribute) {
465 - $result = createTableViewer($attribute);
466 - $result->setRowHTMLAttributes(array(
467 - "class" => "suggestion-row",
468 - "onclick" => "suggestRowClicked(event, this)",
469 - "onmouseover" => "mouseOverRow(this)",
470 - "onmouseout" => "mouseOutRow(this)"
471 - ));
472 -
473 - return $result;
474 -}
475 -
476 -function createUserViewer($attribute) {
477 - return new UserEditor($attribute, new SimplePermissionController(false), false);
478 -}
479 -
480 -function createTranslatedTextViewer($attribute) {
481 - global
482 - $languageAttribute, $textAttribute;
483 -
484 - $result = createTableViewer($attribute);
485 - $result->addEditor(createLanguageViewer($languageAttribute));
486 - $result->addEditor(createLongTextViewer($textAttribute));
487 -
488 - return $result;
489 -}
490 -
491 -?>
\ No newline at end of file
Index: trunk/extensions/Wikidata/OmegaWiki/WiktionaryZRecordSets.php
@@ -1,987 +0,0 @@
2 -<?php
3 -
4 -require_once('OmegaWikiAttributes.php');
5 -require_once('Record.php');
6 -require_once('RecordSet.php');
7 -require_once('Expression.php');
8 -require_once('Transaction.php');
9 -require_once('WikiDataTables.php');
10 -require_once('RecordSetQueries.php');
11 -
12 -function getSynonymSQLForLanguage($languageId, &$definedMeaningIds) {
13 - return
14 - "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
15 - " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
16 - " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
17 - " AND " . getLatestTransactionRestriction('uw_syntrans') .
18 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
19 - " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
20 - " AND uw_expression_ns.language_id=" . $languageId .
21 - " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
22 - " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
23 - " AND uw_syntrans.identical_meaning=1 " .
24 - " GROUP BY uw_defined_meaning.defined_meaning_id";
25 -}
26 -
27 -function getSynonymSQLForAnyLanguage(&$definedMeaningIds) {
28 - return
29 - "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
30 - " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
31 - " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
32 - " AND " . getLatestTransactionRestriction('uw_syntrans') .
33 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
34 - " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
35 - " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
36 - " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
37 - " AND uw_syntrans.identical_meaning=1 " .
38 - " GROUP BY uw_defined_meaning.defined_meaning_id";
39 -}
40 -
41 -function getDefiningSQLForLanguage($languageId, &$definedMeaningIds) {
42 - return
43 - "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
44 - " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
45 - " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
46 - " AND " . getLatestTransactionRestriction('uw_syntrans') .
47 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
48 - " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
49 - " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
50 - " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
51 - " AND uw_syntrans.identical_meaning=1 " .
52 - " AND uw_defined_meaning.expression_id=uw_expression_ns.expression_id " .
53 - " AND uw_expression_ns.language_id=" . $languageId .
54 - " GROUP BY uw_defined_meaning.defined_meaning_id";
55 -}
56 -
57 -function fetchDefinedMeaningReferenceRecords($sql, &$definedMeaningIds, &$definedMeaningReferenceRecords) {
58 - global
59 - $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
60 - $definedMeaningDefiningExpressionAttribute;
61 -
62 - $foundDefinedMeaningIds = array();
63 -
64 - $dbr =& wfGetDB(DB_SLAVE);
65 - $queryResult = $dbr->query($sql);
66 -
67 - while ($row = $dbr->fetchObject($queryResult)) {
68 - $definedMeaningId = $row->defined_meaning_id;
69 -
70 - $record = new ArrayRecord($definedMeaningReferenceStructure);
71 - $record->setAttributeValue($definedMeaningIdAttribute, $definedMeaningId);
72 - $record->setAttributeValue($definedMeaningLabelAttribute, $row->label);
73 -
74 - $definedMeaningReferenceRecords[$definedMeaningId] = $record;
75 - $foundDefinedMeaningIds[] = $definedMeaningId;
76 - }
77 -
78 - $definedMeaningIds = array_diff($definedMeaningIds, $foundDefinedMeaningIds);
79 -}
80 -
81 -function fetchDefinedMeaningDefiningExpressions(&$definedMeaningIds, &$definedMeaningReferenceRecords) {
82 - global
83 - $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
84 - $definedMeaningDefiningExpressionAttribute;
85 -
86 - $dbr =& wfGetDB(DB_SLAVE);
87 - $queryResult = $dbr->query(
88 - "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling" .
89 - " FROM uw_defined_meaning, uw_expression_ns " .
90 - " WHERE uw_defined_meaning.expression_id=uw_expression_ns.expression_id " .
91 - " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
92 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
93 - " AND uw_defined_meaning.defined_meaning_id IN (". implode(", ", $definedMeaningIds) .")"
94 - );
95 -
96 - while ($row = $dbr->fetchObject($queryResult)) {
97 - $definedMeaningReferenceRecord = $definedMeaningReferenceRecords[$row->defined_meaning_id];
98 -
99 - if ($definedMeaningReferenceRecord == null) {
100 - $definedMeaningReferenceRecord = new ArrayRecord($definedMeaningReferenceStructure);
101 - $definedMeaningReferenceRecord->setAttributeValue($definedMeaningIdAttribute, $row->defined_meaning_id);
102 - $definedMeaningReferenceRecord->setAttributeValue($definedMeaningLabelAttribute, $row->spelling);
103 - $definedMeaningReferenceRecords[$row->defined_meaning_id] = $definedMeaningReferenceRecord;
104 - }
105 -
106 - $definedMeaningReferenceRecord->setAttributeValue($definedMeaningDefiningExpressionAttribute, $row->spelling);
107 - }
108 -}
109 -
110 -function getNullDefinedMeaningReferenceRecord() {
111 - global
112 - $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
113 - $definedMeaningDefiningExpressionAttribute;
114 -
115 - $record = new ArrayRecord($definedMeaningReferenceStructure);
116 - $record->setAttributeValue($definedMeaningIdAttribute, 0);
117 - $record->setAttributeValue($definedMeaningLabelAttribute, "");
118 - $record->setAttributeValue($definedMeaningDefiningExpressionAttribute, "");
119 -
120 - return $record;
121 -}
122 -
123 -function getDefinedMeaningReferenceRecords($definedMeaningIds) {
124 - global
125 - $wgUser;
126 -
127 -// $startTime = microtime(true);
128 -
129 - $result = array();
130 - $definedMeaningIdsForExpressions = $definedMeaningIds;
131 -
132 - if (count($definedMeaningIds) > 0) {
133 - $userLanguage = getLanguageIdForCode($wgUser->getOption('language'));
134 -
135 - if ($userLanguage > 0)
136 - $definingLanguage = $userLanguage;
137 - else
138 - $definingLanguage = 85;
139 -
140 - fetchDefinedMeaningReferenceRecords(
141 - getDefiningSQLForLanguage($definingLanguage, $definedMeaningIds),
142 - $definedMeaningIds,
143 - $result
144 - );
145 -
146 - if (count($definedMeaningIds) > 0) {
147 - if ($userLanguage > 0)
148 - fetchDefinedMeaningReferenceRecords(
149 - getSynonymSQLForLanguage($userLanguage, $definedMeaningIds),
150 - $definedMeaningIds,
151 - $result
152 - );
153 -
154 - if (count($definedMeaningIds) > 0) {
155 - fetchDefinedMeaningReferenceRecords(
156 - getSynonymSQLForLanguage(85, $definedMeaningIds),
157 - $definedMeaningIds,
158 - $result
159 - );
160 -
161 - if (count($definedMeaningIds) > 0) {
162 - fetchDefinedMeaningReferenceRecords(
163 - getSynonymSQLForAnyLanguage($definedMeaningIds),
164 - $definedMeaningIds,
165 - $result
166 - );
167 - }
168 - }
169 - }
170 -
171 - fetchDefinedMeaningDefiningExpressions($definedMeaningIdsForExpressions, $result);
172 - $result[0] = getNullDefinedMeaningReferenceRecord();
173 - }
174 -
175 -// $queriesTime = microtime(true) - $startTime;
176 -// echo "<!-- Defined meaning reference queries: " . $queriesTime . " -->\n";
177 -
178 - return $result;
179 -}
180 -
181 -function expandDefinedMeaningReferencesInRecordSet($recordSet, $definedMeaningAttributes) {
182 - $definedMeaningReferenceRecords = getDefinedMeaningReferenceRecords(getUniqueIdsInRecordSet($recordSet, $definedMeaningAttributes));
183 -
184 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
185 - $record = $recordSet->getRecord($i);
186 -
187 - foreach($definedMeaningAttributes as $definedMeaningAttribute)
188 - $record->setAttributeValue(
189 - $definedMeaningAttribute,
190 - $definedMeaningReferenceRecords[$record->getAttributeValue($definedMeaningAttribute)]
191 - );
192 - }
193 -}
194 -
195 -function expandTranslatedContentInRecord($record, $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation) {
196 - $record->setAttributeValue(
197 - $translatedContentAttribute,
198 - getTranslatedContentValue($record->getAttributeValue($idAttribute), $filterLanguageId, $queryTransactionInformation)
199 - );
200 -}
201 -
202 -function expandTranslatedContentsInRecordSet($recordSet, $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation) {
203 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++)
204 - expandTranslatedContentInRecord($recordSet->getRecord($i), $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation);
205 -}
206 -
207 -function getExpressionReferenceRecords($expressionIds) {
208 - global
209 - $expressionStructure, $languageAttribute, $spellingAttribute;
210 -
211 - if (count($expressionIds) > 0) {
212 - $dbr =& wfGetDB(DB_SLAVE);
213 - $queryResult = $dbr->query(
214 - "SELECT expression_id, language_id, spelling" .
215 - " FROM uw_expression_ns" .
216 - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
217 - " AND ". getLatestTransactionRestriction('uw_expression_ns')
218 - );
219 -
220 - $result = array();
221 -
222 - while ($row = $dbr->fetchObject($queryResult)) {
223 - $record = new ArrayRecord($expressionStructure);
224 - $record->setAttributeValue($languageAttribute, $row->language_id);
225 - $record->setAttributeValue($spellingAttribute, $row->spelling);
226 -
227 - $result[$row->expression_id] = $record;
228 - }
229 -
230 - return $result;
231 - }
232 - else
233 - return array();
234 -}
235 -
236 -function expandExpressionReferencesInRecordSet($recordSet, $expressionAttributes) {
237 - $expressionReferenceRecords = getExpressionReferenceRecords(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
238 -
239 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
240 - $record = $recordSet->getRecord($i);
241 -
242 - foreach($expressionAttributes as $expressionAttribute)
243 - $record->setAttributeValue(
244 - $expressionAttribute,
245 - $expressionReferenceRecords[$record->getAttributeValue($expressionAttribute)]
246 - );
247 - }
248 -}
249 -
250 -function getExpressionSpellings($expressionIds) {
251 - global
252 - $expressionAttribute;
253 -
254 - if (count($expressionIds) > 0) {
255 - $dbr =& wfGetDB(DB_SLAVE);
256 - $queryResult = $dbr->query(
257 - "SELECT expression_id, spelling" .
258 - " FROM uw_expression_ns" .
259 - " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
260 - " AND ". getLatestTransactionRestriction('uw_expression_ns')
261 - );
262 -
263 - $result = array();
264 -
265 - while ($row = $dbr->fetchObject($queryResult))
266 - $result[$row->expression_id] = $row->spelling;
267 -
268 - return $result;
269 - }
270 - else
271 - return array();
272 -}
273 -
274 -function expandExpressionSpellingsInRecordSet($recordSet, $expressionAttributes) {
275 - $expressionSpellings = getExpressionSpellings(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
276 -
277 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
278 - $record = $recordSet->getRecord($i);
279 -
280 - foreach($expressionAttributes as $expressionAttribute)
281 - $record->setAttributeValue(
282 - $expressionAttribute,
283 - $expressionSpellings[$record->getAttributeValue($expressionAttribute)]
284 - );
285 - }
286 -}
287 -
288 -function getTextReferences($textIds) {
289 - if (count($textIds) > 0) {
290 - $dbr =& wfGetDB(DB_SLAVE);
291 - $queryResult = $dbr->query(
292 - "SELECT old_id, old_text" .
293 - " FROM text" .
294 - " WHERE old_id IN (". implode(', ', $textIds) .")"
295 - );
296 -
297 - $result = array();
298 -
299 - while ($row = $dbr->fetchObject($queryResult))
300 - $result[$row->old_id] = $row->old_text;
301 -
302 - return $result;
303 - }
304 - else
305 - return array();
306 -}
307 -
308 -function expandTextReferencesInRecordSet($recordSet, $textAttributes) {
309 - $textReferences = getTextReferences(getUniqueIdsInRecordSet($recordSet, $textAttributes));
310 -
311 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
312 - $record = $recordSet->getRecord($i);
313 -
314 - foreach($textAttributes as $textAttribute)
315 - $record->setAttributeValue(
316 - $textAttribute,
317 - $textReferences[$record->getAttributeValue($textAttribute)]
318 - );
319 - }
320 -}
321 -
322 -function getExpressionMeaningsRecordSet($expressionId, $exactMeaning, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
323 - global
324 - $expressionMeaningStructure, $definedMeaningIdAttribute;
325 -
326 - if ($exactMeaning)
327 - $identicalMeaning = 1;
328 - else
329 - $identicalMeaning = 0;
330 -
331 - $recordSet = new ArrayRecordSet($expressionMeaningStructure, new Structure($definedMeaningIdAttribute));
332 -
333 - $dbr =& wfGetDB(DB_SLAVE);
334 - $queryResult = $dbr->query("SELECT defined_meaning_id FROM uw_syntrans" .
335 - " WHERE expression_id=$expressionId AND identical_meaning=" . $identicalMeaning .
336 - " AND ". getLatestTransactionRestriction('uw_syntrans'));
337 -
338 - while($definedMeaning = $dbr->fetchObject($queryResult)) {
339 - $definedMeaningId = $definedMeaning->defined_meaning_id;
340 - $recordSet->addRecord(
341 - array(
342 - $definedMeaningId,
343 - getDefinedMeaningDefinition($definedMeaningId),
344 - getDefinedMeaningRecord($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation)
345 - )
346 - );
347 - }
348 -
349 - return $recordSet;
350 -}
351 -
352 -function getExpressionMeaningsRecord($expressionId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
353 - global
354 - $expressionMeaningsStructure, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute;
355 -
356 - $record = new ArrayRecord($expressionMeaningsStructure);
357 - $record->setAttributeValue($expressionExactMeaningsAttribute, getExpressionMeaningsRecordSet($expressionId, true, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
358 - $record->setAttributeValue($expressionApproximateMeaningsAttribute, getExpressionMeaningsRecordSet($expressionId, false, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
359 -
360 - return $record;
361 -}
362 -
363 -function getExpressionsRecordSet($spelling, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
364 - global
365 - $expressionIdAttribute, $expressionAttribute, $languageAttribute, $expressionMeaningsAttribute;
366 -
367 - if ($filterLanguageId != 0)
368 - $languageRestriction = " AND language_id=$filterLanguageId";
369 - else
370 - $languageRestriction = "";
371 -
372 - $dbr =& wfGetDB(DB_SLAVE);
373 - $queryResult = $dbr->query(
374 - "SELECT expression_id, language_id " .
375 - " FROM uw_expression_ns" .
376 - " WHERE spelling=BINARY " . $dbr->addQuotes($spelling) .
377 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
378 - $languageRestriction .
379 - " AND EXISTS (" .
380 - "SELECT expression_id " .
381 - " FROM uw_syntrans " .
382 - " WHERE uw_syntrans.expression_id=uw_expression_ns.expression_id" .
383 - " AND ". getLatestTransactionRestriction('uw_syntrans')
384 - .")"
385 - );
386 -
387 - $result = new ArrayRecordSet(new Structure($expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute), new Structure($expressionIdAttribute));
388 - $expressionStructure = new Structure($languageAttribute);
389 -
390 - while($expression = $dbr->fetchObject($queryResult)) {
391 - $expressionRecord = new ArrayRecord($expressionStructure);
392 - $expressionRecord->setAttributeValue($languageAttribute, $expression->language_id);
393 -
394 - $result->addRecord(array(
395 - $expression->expression_id,
396 - $expressionRecord,
397 - getExpressionMeaningsRecord($expression->expression_id, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation)
398 - ));
399 - }
400 -
401 - return $result;
402 -}
403 -
404 -function getExpressionIdThatHasSynonyms($spelling, $languageId) {
405 - $dbr =& wfGetDB(DB_SLAVE);
406 - $queryResult = $dbr->query(
407 - "SELECT expression_id, language_id " .
408 - " FROM uw_expression_ns" .
409 - " WHERE spelling=BINARY " . $dbr->addQuotes($spelling) .
410 - " AND " . getLatestTransactionRestriction('uw_expression_ns') .
411 - " AND language_id=$languageId" .
412 - " AND EXISTS (" .
413 - "SELECT expression_id " .
414 - " FROM uw_syntrans " .
415 - " WHERE uw_syntrans.expression_id=uw_expression_ns.expression_id" .
416 - " AND ". getLatestTransactionRestriction('uw_syntrans')
417 - .")"
418 - );
419 -
420 - if ($expression = $dbr->fetchObject($queryResult))
421 - return $expression->expression_id;
422 - else
423 - return 0;
424 -}
425 -
426 -function getDefinedMeaningRecord($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
427 - global
428 - $definedMeaningAttribute, $definitionAttribute, $classAttributesAttribute,
429 - $alternativeDefinitionsAttribute, $synonymsAndTranslationsAttribute,
430 - $relationsAttribute, $reciprocalRelationsAttribute,
431 - $classMembershipAttribute, $collectionMembershipAttribute, $objectAttributesAttribute,
432 - $possiblySynonymousAttribute;
433 -
434 - $record = new ArrayRecord($definedMeaningAttribute->type->getStructure());
435 - $record->setAttributeValue($definitionAttribute, getDefinedMeaningDefinitionRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
436 - $record->setAttributeValue($classAttributesAttribute, getClassAttributesRecordSet($definedMeaningId, $queryTransactionInformation));
437 - $record->setAttributeValue($alternativeDefinitionsAttribute, getAlternativeDefinitionsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
438 - $record->setAttributeValue($synonymsAndTranslationsAttribute, getSynonymAndTranslationRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
439 -
440 - $filterRelationTypes = array();
441 -
442 - if ($possiblySynonymousRelationTypeId != 0) {
443 - $record->setAttributeValue($possiblySynonymousAttribute, getPossiblySynonymousRecordSet($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
444 - $filterRelationTypes[] = $possiblySynonymousRelationTypeId;
445 - }
446 -
447 - $record->setAttributeValue($relationsAttribute, getDefinedMeaningRelationsRecordSet($definedMeaningId, $filterLanguageId, $filterRelationTypes, $queryTransactionInformation));
448 - $record->setAttributeValue($reciprocalRelationsAttribute, getDefinedMeaningReciprocalRelationsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
449 - $record->setAttributeValue($classMembershipAttribute, getDefinedMeaningClassMembershipRecordSet($definedMeaningId, $queryTransactionInformation));
450 - $record->setAttributeValue($collectionMembershipAttribute, getDefinedMeaningCollectionMembershipRecordSet($definedMeaningId, $queryTransactionInformation));
451 - $record->setAttributeValue($objectAttributesAttribute, getObjectAttributesRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
452 -
453 - return $record;
454 -}
455 -
456 -function getClassAttributesRecordSet($definedMeaningId, $queryTransactionInformation) {
457 - global
458 - $classAttributesTable, $classAttributeIdAttribute, $classAttributeLevelAttribute, $classAttributeAttributeAttribute, $classAttributeTypeAttribute, $optionAttributeOptionsAttribute;
459 -
460 - $recordSet = queryRecordSet(
461 - $queryTransactionInformation,
462 - $classAttributeIdAttribute,
463 - array(
464 - 'object_id' => $classAttributeIdAttribute,
465 - 'level_mid' => $classAttributeLevelAttribute,
466 - 'attribute_mid' => $classAttributeAttributeAttribute,
467 - 'attribute_type' => $classAttributeTypeAttribute
468 - ),
469 - $classAttributesTable,
470 - array("class_mid=$definedMeaningId")
471 - );
472 -
473 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($classAttributeLevelAttribute ,$classAttributeAttributeAttribute));
474 - expandOptionAttributeOptionsInRecordSet($recordSet, $classAttributeIdAttribute, $queryTransactionInformation);
475 -
476 - return $recordSet;
477 -}
478 -
479 -function expandOptionAttributeOptionsInRecordSet($recordSet, $attributeIdAttribute, $queryTransactionInformation) {
480 - global
481 - $definedMeaningIdAttribute, $optionAttributeOptionsAttribute;
482 -
483 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
484 - $record = $recordSet->getRecord($i);
485 -
486 - $record->setAttributeValue($optionAttributeOptionsAttribute, getOptionAttributeOptionsRecordSet($record->getAttributeValue($attributeIdAttribute), $queryTransactionInformation));
487 - }
488 -}
489 -
490 -function getAlternativeDefinitionsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
491 - global
492 - $alternativeDefinitionsTable, $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
493 -
494 - $recordSet = queryRecordSet(
495 - $queryTransactionInformation,
496 - $definitionIdAttribute,
497 - array(
498 - 'meaning_text_tcid' => $definitionIdAttribute,
499 - 'source_id' => $sourceAttribute
500 - ),
501 - $alternativeDefinitionsTable,
502 - array("meaning_mid=$definedMeaningId")
503 - );
504 -
505 - $recordSet->getStructure()->attributes[] = $alternativeDefinitionAttribute;
506 -
507 - expandTranslatedContentsInRecordSet($recordSet, $definitionIdAttribute, $alternativeDefinitionAttribute, $filterLanguageId, $queryTransactionInformation);
508 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($sourceAttribute));
509 -
510 - return $recordSet;
511 -}
512 -
513 -function getDefinedMeaningDefinitionRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
514 - global
515 - $definitionAttribute, $translatedTextAttribute, $objectAttributesAttribute;
516 -
517 - $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
518 - $record = new ArrayRecord($definitionAttribute->type->getStructure());
519 - $record->setAttributeValue($translatedTextAttribute, getTranslatedContentValue($definitionId, $filterLanguageId, $queryTransactionInformation));
520 - $record->setAttributeValue($objectAttributesAttribute, getObjectAttributesRecord($definitionId, $filterLanguageId, $queryTransactionInformation));
521 -
522 - return $record;
523 -}
524 -
525 -function getObjectAttributesRecord($objectId, $filterLanguageId, $queryTransactionInformation) {
526 - global
527 - $objectAttributesAttribute, $objectIdAttribute,
528 - $urlAttributeValuesAttribute, $textAttributeValuesAttribute,
529 - $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute;
530 -
531 - $record = new ArrayRecord($objectAttributesAttribute->type->getStructure());
532 -
533 - $record->setAttributeValue($objectIdAttribute, $objectId);
534 - $record->setAttributeValue($textAttributeValuesAttribute, getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
535 - $record->setAttributeValue($translatedTextAttributeValuesAttribute, getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
536 - $record->setAttributeValue($urlAttributeValuesAttribute, getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
537 - $record->setAttributeValue($optionAttributeValuesAttribute, getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
538 -
539 - return $record;
540 -}
541 -
542 -function getTranslatedContentValue($translatedContentId, $filterLanguageId, $queryTransactionInformation) {
543 - global
544 - $textAttribute;
545 -
546 - if ($filterLanguageId == 0)
547 - return getTranslatedContentRecordSet($translatedContentId, $queryTransactionInformation);
548 - else {
549 - $recordSet = getFilteredTranslatedContentRecordSet($translatedContentId, $filterLanguageId, $queryTransactionInformation);
550 -
551 - if (count($queryTransactionInformation->versioningAttributes()) > 0)
552 - return $recordSet;
553 - else {
554 - if ($recordSet->getRecordCount() > 0)
555 - return $recordSet->getRecord(0)->getAttributeValue($textAttribute);
556 - else
557 - return "";
558 - }
559 - }
560 -}
561 -
562 -function getTranslatedContentRecordSet($translatedContentId, $queryTransactionInformation) {
563 - global
564 - $translatedContentTable, $languageAttribute, $textAttribute;
565 -
566 - $recordSet = queryRecordSet(
567 - $queryTransactionInformation,
568 - $languageAttribute,
569 - array(
570 - 'language_id' => $languageAttribute,
571 - 'text_id' => $textAttribute
572 - ),
573 - $translatedContentTable,
574 - array("translated_content_id=$translatedContentId")
575 - );
576 -
577 - expandTextReferencesInRecordSet($recordSet, array($textAttribute));
578 -
579 - return $recordSet;
580 -}
581 -
582 -function getFilteredTranslatedContentRecordSet($translatedContentId, $filterLanguageId, $queryTransactionInformation) {
583 - global
584 - $translatedContentTable, $languageAttribute, $textAttribute;
585 -
586 - $recordSet = queryRecordSet(
587 - $queryTransactionInformation,
588 - $languageAttribute,
589 - array(
590 - 'language_id' => $languageAttribute,
591 - 'text_id' => $textAttribute
592 - ),
593 - $translatedContentTable,
594 - array(
595 - "translated_content_id=$translatedContentId",
596 - "language_id=$filterLanguageId"
597 - )
598 - );
599 -
600 - expandTextReferencesInRecordSet($recordSet, array($textAttribute));
601 -
602 - return $recordSet;
603 -}
604 -
605 -function getSynonymAndTranslationRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
606 - global
607 - $syntransTable, $syntransIdAttribute, $expressionAttribute, $identicalMeaningAttribute, $objectAttributesAttribute;
608 -
609 - $restrictions = array("defined_meaning_id=$definedMeaningId");
610 -
611 - if ($filterLanguageId != 0)
612 - $restrictions[] =
613 - "expression_id IN (" .
614 - "SELECT expressions.expression_id" .
615 - " FROM uw_expression_ns AS expressions" .
616 - " WHERE expressions.expression_id=expression_id" .
617 - " AND language_id=$filterLanguageId" .
618 - " AND " . getLatestTransactionRestriction('expressions') .
619 - ")";
620 -
621 - $recordSet = queryRecordSet(
622 - $queryTransactionInformation,
623 - $syntransIdAttribute,
624 - array(
625 - 'syntrans_sid' => $syntransIdAttribute,
626 - 'expression_id' => $expressionAttribute,
627 - 'identical_meaning' => $identicalMeaningAttribute
628 - ),
629 - $syntransTable,
630 - $restrictions
631 - );
632 -
633 - if ($filterLanguageId == 0)
634 - expandExpressionReferencesInRecordSet($recordSet, array($expressionAttribute));
635 - else
636 - expandExpressionSpellingsInRecordSet($recordSet, array($expressionAttribute));
637 -
638 - //add object attributes attribute to the generated structure
639 - //and expand the records
640 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
641 - expandObjectAttributesAttribute($recordSet, $syntransIdAttribute, $filterLanguageId, $queryTransactionInformation);
642 - return $recordSet;
643 -}
644 -
645 -function expandObjectAttributesAttribute($recordSet, $objectIdAttribute, $filterLanguageId, $queryTransactionInformation) {
646 - global
647 - $objectAttributesAttribute;
648 -
649 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
650 - $record = $recordSet->getRecord($i);
651 - $record->setAttributeValue(
652 - $objectAttributesAttribute,
653 - getObjectAttributesRecord(
654 - $record->getAttributeValue($objectIdAttribute),
655 - $filterLanguageId,
656 - $queryTransactionInformation
657 - )
658 - );
659 - }
660 -}
661 -
662 -function getDefinedMeaningReferenceRecord($definedMeaningId) {
663 - global
664 - $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
665 - $definedMeaningDefiningExpressionAttribute;
666 -
667 - $record = new ArrayRecord($definedMeaningReferenceStructure);
668 - $record->setAttributeValue($definedMeaningIdAttribute, $definedMeaningId);
669 - $record->setAttributeValue($definedMeaningLabelAttribute, definedMeaningExpression($definedMeaningId));
670 - $record->setAttributeValue($definedMeaningDefiningExpressionAttribute, definingExpression($definedMeaningId));
671 -
672 - return $record;
673 -}
674 -
675 -function getDefinedMeaningRelationsRecordSet($definedMeaningId, $filterLanguageId, $filterRelationTypes, $queryTransactionInformation) {
676 - global
677 - $meaningRelationsTable, $relationIdAttribute, $relationTypeAttribute,
678 - $objectAttributesAttribute, $otherDefinedMeaningAttribute;
679 -
680 - $restrictions = array("meaning1_mid=$definedMeaningId");
681 -
682 - if (count($filterRelationTypes) > 0)
683 - $restrictions[] = "relationtype_mid NOT IN (". implode(", ", $filterRelationTypes) .")";
684 -
685 - $recordSet = queryRecordSet(
686 - $queryTransactionInformation,
687 - $relationIdAttribute,
688 - array(
689 - 'relation_id' => $relationIdAttribute,
690 - 'relationtype_mid' => $relationTypeAttribute,
691 - 'meaning2_mid' => $otherDefinedMeaningAttribute
692 - ),
693 - $meaningRelationsTable,
694 - $restrictions,
695 - array('add_transaction_id')
696 - );
697 -
698 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
699 -
700 - //add object attributes attribute to the generated structure
701 - //and expand the records
702 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
703 - expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $filterLanguageId, $queryTransactionInformation);
704 -
705 - return $recordSet;
706 -}
707 -
708 -function getDefinedMeaningReciprocalRelationsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
709 - global
710 - $meaningRelationsTable, $relationIdAttribute, $relationTypeAttribute,
711 - $otherDefinedMeaningAttribute, $objectAttributesAttribute;
712 -
713 - $recordSet = queryRecordSet(
714 - $queryTransactionInformation,
715 - $relationIdAttribute,
716 - array(
717 - 'relation_id' => $relationIdAttribute,
718 - 'relationtype_mid' => $relationTypeAttribute,
719 - 'meaning1_mid' => $otherDefinedMeaningAttribute
720 - ),
721 - $meaningRelationsTable,
722 - array("meaning2_mid=$definedMeaningId"),
723 - array('relationtype_mid')
724 - );
725 -
726 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
727 -
728 - //add object attributes attribute to the generated structure
729 - //and expand the records
730 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
731 - expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $filterLanguageId, $queryTransactionInformation);
732 -
733 - return $recordSet;
734 -}
735 -
736 -function getPossiblySynonymousRecordSet($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
737 - global
738 - $meaningRelationsTable, $possiblySynonymousIdAttribute, $possibleSynonymAttribute,
739 - $objectAttributesAttribute, $otherDefinedMeaningAttribute;
740 -
741 - $recordSet = queryRecordSet(
742 - $queryTransactionInformation,
743 - $possiblySynonymousIdAttribute,
744 - array(
745 - 'relation_id' => $possiblySynonymousIdAttribute,
746 - 'meaning2_mid' => $possibleSynonymAttribute
747 - ),
748 - $meaningRelationsTable,
749 - array(
750 - "meaning1_mid=$definedMeaningId",
751 - "relationtype_mid=" . $possiblySynonymousRelationTypeId
752 - ),
753 - array('add_transaction_id')
754 - );
755 -
756 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($possibleSynonymAttribute));
757 -
758 - //add object attributes attribute to the generated structure
759 - //and expand the records
760 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
761 - expandObjectAttributesAttribute($recordSet, $possiblySynonymousIdAttribute, $filterLanguageId, $queryTransactionInformation);
762 -
763 - return $recordSet;
764 -}
765 -
766 -function getDefinedMeaningCollectionMembershipRecordSet($definedMeaningId, $queryTransactionInformation) {
767 - global
768 - $collectionMembershipsTable, $collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute;
769 -
770 - $recordSet = queryRecordSet(
771 - $queryTransactionInformation,
772 - $collectionIdAttribute,
773 - array(
774 - 'collection_id' => $collectionIdAttribute,
775 - 'internal_member_id' => $sourceIdentifierAttribute
776 - ),
777 - $collectionMembershipsTable,
778 - array("member_mid=$definedMeaningId")
779 - );
780 -
781 - $recordSet->getStructure()->atttributes[] = $collectionMeaningAttribute;
782 -
783 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
784 - $record = $recordSet->getRecord($i);
785 - $record->setAttributeValue($collectionMeaningAttribute, getCollectionMeaningId($record->getAttributeValue($collectionIdAttribute)));
786 - }
787 -
788 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($collectionMeaningAttribute));
789 -
790 - return $recordSet;
791 -}
792 -
793 -function getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
794 - global
795 - $textAttributeValuesTable, $textAttributeIdAttribute, $textAttributeObjectAttribute,
796 - $textAttributeAttribute, $textAttribute, $objectAttributesAttribute;
797 -
798 - $recordSet = queryRecordSet(
799 - $queryTransactionInformation,
800 - $textAttributeIdAttribute,
801 - array(
802 - 'value_id' => $textAttributeIdAttribute,
803 - 'object_id' => $textAttributeObjectAttribute,
804 - 'attribute_mid' => $textAttributeAttribute,
805 - 'text' => $textAttribute
806 - ),
807 - $textAttributeValuesTable,
808 - array("object_id=$objectId")
809 - );
810 -
811 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($textAttributeAttribute));
812 -
813 - //add object attributes attribute to the generated structure
814 - //and expand the records
815 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
816 - expandObjectAttributesAttribute($recordSet, $textAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
817 -
818 - return $recordSet;
819 -}
820 -
821 -function getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
822 - global
823 - $urlAttributeValuesTable, $urlAttributeIdAttribute, $urlAttributeObjectAttribute,
824 - $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute;
825 -
826 - $recordSet = queryRecordSet(
827 - $queryTransactionInformation,
828 - $urlAttributeIdAttribute,
829 - array(
830 - 'value_id' => $urlAttributeIdAttribute,
831 - 'object_id' => $urlAttributeObjectAttribute,
832 - 'attribute_mid' => $urlAttributeAttribute,
833 - 'url' => $urlAttribute
834 - ),
835 - $urlAttributeValuesTable,
836 - array("object_id=$objectId")
837 - );
838 -
839 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($urlAttributeAttribute));
840 -
841 - //add object attributes attribute to the generated structure
842 - //and expand the records
843 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
844 - expandObjectAttributesAttribute($recordSet, $urlAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
845 -
846 - return $recordSet;
847 -}
848 -
849 -function getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
850 - global
851 - $translatedTextAttributeIdAttribute, $translatedContentAttributeValuesTable, $translatedTextAttributeAttribute,
852 - $objectAttributesAttribute, $translatedTextValueAttribute, $translatedTextValueIdAttribute;
853 -
854 - $recordSet = queryRecordSet(
855 - $queryTransactionInformation,
856 - $translatedTextAttributeIdAttribute,
857 - array(
858 - 'value_id' => $translatedTextAttributeIdAttribute,
859 - 'attribute_mid' => $translatedTextAttributeAttribute,
860 - 'value_tcid' => $translatedTextValueIdAttribute
861 - ),
862 - $translatedContentAttributeValuesTable,
863 - array("object_id=$objectId")
864 - );
865 -
866 - $recordSet->getStructure()->attributes[] = $translatedTextValueAttribute;
867 -
868 - expandTranslatedContentsInRecordSet($recordSet, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $filterLanguageId, $queryTransactionInformation);
869 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($translatedTextAttributeAttribute));
870 -
871 - //add object attributes attribute to the generated structure
872 - //and expand the records
873 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
874 - expandObjectAttributesAttribute($recordSet, $translatedTextAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
875 - return $recordSet;
876 -}
877 -
878 -function getOptionAttributeOptionsRecordSet($attributeId, $queryTransactionInformation) {
879 - global
880 - $optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsTable;
881 -
882 - $recordSet = queryRecordSet(
883 - $queryTransactionInformation,
884 - $optionAttributeOptionIdAttribute,
885 - array(
886 - 'option_id' => $optionAttributeOptionIdAttribute,
887 - 'attribute_id' => $optionAttributeAttribute,
888 - 'option_mid' => $optionAttributeOptionAttribute,
889 - 'language_id' => $languageAttribute
890 - ),
891 - $optionAttributeOptionsTable,
892 - array('attribute_id = ' . $attributeId)
893 - );
894 -
895 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($optionAttributeOptionAttribute));
896 -
897 - return $recordSet;
898 -}
899 -
900 -function getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
901 - global
902 - $optionAttributeIdAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionIdAttribute, $optionAttributeAttribute,$optionAttributeOptionAttribute, $optionAttributeValuesTable, $objectAttributesAttribute;
903 -
904 - $recordSet = queryRecordSet(
905 - $queryTransactionInformation,
906 - $optionAttributeIdAttribute,
907 - array(
908 - 'value_id' => $optionAttributeIdAttribute,
909 - 'object_id' => $optionAttributeObjectAttribute,
910 - 'option_id' => $optionAttributeOptionIdAttribute
911 - ),
912 - $optionAttributeValuesTable,
913 - array('object_id = ' . $objectId)
914 - );
915 -
916 - expandOptionsInRecordSet($recordSet, $queryTransactionInformation);
917 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($optionAttributeAttribute, $optionAttributeOptionAttribute));
918 -
919 - /* Add object attributes attribute to the generated structure
920 - and expand the records. */
921 - $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
922 - expandObjectAttributesAttribute($recordSet, $optionAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
923 -
924 - return $recordSet;
925 -}
926 -
927 -/* XXX: This can probably be combined with other functions. In fact, it probably should be. Do it. */
928 -function expandOptionsInRecordSet($recordSet, $queryTransactionInformation) {
929 - global
930 - $optionAttributeOptionIdAttribute, $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeOptionsTable, $classAttributesTable;
931 -
932 - for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
933 - $record = $recordSet->getRecord($i);
934 -
935 - $optionRecordSet = queryRecordSet(
936 - $queryTransactionInformation,
937 - $optionAttributeOptionIdAttribute,
938 - array(
939 - 'attribute_id' => $optionAttributeIdAttribute,
940 - 'option_mid' => $optionAttributeOptionAttribute
941 - ),
942 - $optionAttributeOptionsTable,
943 - array('option_id = ' . $record->getAttributeValue($optionAttributeOptionIdAttribute))
944 - );
945 -
946 - $optionRecord = $optionRecordSet->getRecord(0);
947 - $record->setAttributeValue(
948 - $optionAttributeOptionAttribute,
949 - $optionRecord->getAttributeValue($optionAttributeOptionAttribute)
950 - );
951 -
952 - $optionRecordSet = queryRecordSet(
953 - $queryTransactionInformation,
954 - $optionAttributeIdAttribute,
955 - array('attribute_mid' => $optionAttributeAttribute),
956 - $classAttributesTable,
957 - array('object_id = ' . $optionRecord->getAttributeValue($optionAttributeIdAttribute))
958 - );
959 -
960 - $optionRecord = $optionRecordSet->getRecord(0);
961 - $record->setAttributeValue(
962 - $optionAttributeAttribute,
963 - $optionRecord->getAttributeValue($optionAttributeAttribute)
964 - );
965 - }
966 -}
967 -
968 -function getDefinedMeaningClassMembershipRecordSet($definedMeaningId, $queryTransactionInformation) {
969 - global
970 - $classMembershipsTable, $classMembershipIdAttribute, $classAttribute;
971 -
972 - $recordSet = queryRecordSet(
973 - $queryTransactionInformation,
974 - $classMembershipIdAttribute,
975 - array(
976 - 'class_membership_id' => $classMembershipIdAttribute,
977 - 'class_mid' => $classAttribute
978 - ),
979 - $classMembershipsTable,
980 - array("class_member_mid=$definedMeaningId")
981 - );
982 -
983 - expandDefinedMeaningReferencesInRecordSet($recordSet, array($classAttribute));
984 -
985 - return $recordSet;
986 -}
987 -
988 -?>
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
@@ -0,0 +1,243 @@
 2+<?php
 3+
 4+require_once("Attribute.php");
 5+require_once("WikiDataGlobals.php");
 6+
 7+function initializeOmegaWikiAttributes($filterOnLanguage, $hasMetaDataAttributes) {
 8+ global
 9+ $languageAttribute, $spellingAttribute, $textAttribute;
 10+
 11+ $languageAttribute = new Attribute("language", "Language", "language");
 12+ $spellingAttribute = new Attribute("spelling", "Spelling", "spelling");
 13+ $textAttribute = new Attribute("text", "Text", "text");
 14+
 15+ global
 16+ $expressionIdAttribute, $identicalMeaningAttribute;
 17+
 18+ $expressionIdAttribute = new Attribute("expression-id", "Expression Id", "expression-id");
 19+ $identicalMeaningAttribute = new Attribute("indentical-meaning", "Identical meaning?", "boolean");
 20+
 21+ global
 22+ $expressionStructure, $expressionAttribute;
 23+
 24+ if ($filterOnLanguage)
 25+ $expressionAttribute = new Attribute("expression", "Spelling", "spelling");
 26+ else {
 27+ $expressionStructure = new Structure($languageAttribute, $spellingAttribute);
 28+ $expressionAttribute = new Attribute("expression", "Expression", new RecordType($expressionStructure));
 29+ }
 30+
 31+ global
 32+ $definedMeaningIdAttribute, $definedMeaningDefiningExpressionAttribute;
 33+
 34+ $definedMeaningIdAttribute = new Attribute("defined-meaning-id", "Defined meaning identifier", "defined-meaning-id");
 35+ $definedMeaningDefiningExpressionAttribute = new Attribute("defined-meaning-defining-expression", "Defined meaning defining expression", "short-text");
 36+
 37+ global
 38+ $definedMeaningReferenceStructure, $definedMeaningLabelAttribute, $definedMeaningReferenceKeyStructure, $definedMeaningReferenceType,
 39+ $definedMeaningReferenceAttribute;
 40+
 41+ $definedMeaningLabelAttribute = new Attribute("defined-meaning-label", "Defined meaning label", "short-text");
 42+ $definedMeaningReferenceStructure = new Structure($definedMeaningIdAttribute, $definedMeaningLabelAttribute, $definedMeaningDefiningExpressionAttribute);
 43+ $definedMeaningReferenceKeyStructure = new Structure($definedMeaningIdAttribute);
 44+ $definedMeaningReferenceType = new RecordType($definedMeaningReferenceStructure);
 45+ $definedMeaningReferenceAttribute = new Attribute("defined-meaning", "Defined meaning", $definedMeaningReferenceType);
 46+
 47+ global
 48+ $collectionIdAttribute, $collectionMeaningType, $collectionMeaningAttribute, $sourceIdentifierAttribute;
 49+
 50+ $collectionIdAttribute = new Attribute("collection", "Collection", "collection-id");
 51+ $collectionMeaningType = new RecordType($definedMeaningReferenceStructure);
 52+ $collectionMeaningAttribute = new Attribute("collection-meaning", "Collection", $collectionMeaningType);
 53+ $sourceIdentifierAttribute = new Attribute("source-identifier", "Source identifier", "short-text");
 54+
 55+ global
 56+ $collectionMembershipAttribute;
 57+
 58+ $collectionMembershipAttribute = new Attribute("collection-membership", "Collection membership", new RecordSetType(new Structure($collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute)));
 59+
 60+ global
 61+ $classMembershipIdAttribute, $classAttribute;
 62+
 63+ $classMembershipIdAttribute = new Attribute("class-membership-id", "Class membership id", "integer");
 64+ $classAttribute = new Attribute("class", "Class", new RecordType($definedMeaningReferenceStructure));
 65+
 66+ global
 67+ $classMembershipStructure, $classMembershipKeyStructure, $classMembershipAttribute, $wgClassMembershipAttributeName;
 68+
 69+ $classMembershipStructure = new Structure($classMembershipIdAttribute, $classAttribute);
 70+ $classMembershipKeyStructure = new Structure($classMembershipIdAttribute);
 71+ $classMembershipAttribute = new Attribute("class-membership", $wgClassMembershipAttributeName, new RecordSetType($classMembershipStructure));
 72+
 73+ global
 74+ $possiblySynonymousIdAttribute, $possibleSynonymAttribute;
 75+
 76+ $possiblySynonymousIdAttribute = new Attribute("possibly-synonymous-id", "Possibly synonymous id", "integer");
 77+ $possibleSynonymAttribute = new Attribute("possible-synonym", "Possible synonym", new RecordType($definedMeaningReferenceStructure));
 78+
 79+ global
 80+ $possiblySynonymousStructure, $possiblySynonymousKeyStructure, $possiblySynonymousAttribute,
 81+ $wgPossiblySynonymousAttributeName;
 82+
 83+ $possiblySynonymousStructure = new Structure($possiblySynonymousIdAttribute, $possiblySynonymousAttribute);
 84+ $possiblySynonymousKeyStructure = new Structure($possiblySynonymousIdAttribute);
 85+ $possiblySynonymousAttribute = new Attribute("possibly-synonymous", $wgPossiblySynonymousAttributeName, new RecordSetType($possiblySynonymousStructure));
 86+
 87+ global
 88+ $relationIdAttribute, $relationTypeAttribute, $relationTypeType, $otherDefinedMeaningAttribute,
 89+ $wgRelationTypeAttributeName, $wgOtherDefinedMeaningAttributeName;
 90+
 91+ $relationIdAttribute = new Attribute("relation-id", "Relation identifier", "object-id");
 92+ $relationTypeType = new RecordType($definedMeaningReferenceStructure);
 93+ $relationTypeAttribute = new Attribute("relation-type", $wgRelationTypeAttributeName, $relationTypeType);
 94+ $otherDefinedMeaningAttribute = new Attribute("other-defined-meaning", $wgOtherDefinedMeaningAttributeName, $definedMeaningReferenceType);
 95+
 96+ global
 97+ $relationsAttribute, $relationStructure, $relationKeyStructure, $reciprocalRelationsAttribute, $objectAttributesAttribute,
 98+ $wgRelationsAttributeName, $wgIncomingRelationsAttributeName;
 99+
 100+ $relationStructure = new Structure($relationIdAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute, $objectAttributesAttribute);
 101+ $relationKeyStructure = new Structure($relationIdAttribute);
 102+ $relationsAttribute = new Attribute("relations", $wgRelationsAttributeName, new RecordSetType($relationStructure));
 103+ $reciprocalRelationsAttribute = new Attribute("reciprocal-relations", $wgIncomingRelationsAttributeName, new RecordSetType($relationStructure));
 104+
 105+ global
 106+ $translatedTextIdAttribute, $translatedTextStructure;
 107+
 108+ $translatedTextIdAttribute = new Attribute("translated-text-id", "Translated text ID", "integer");
 109+ $translatedTextStructure = new Structure($languageAttribute, $textAttribute);
 110+
 111+ global
 112+ $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute,
 113+ $wgAlternativeDefinitionAttributeName, $wgSourceAttributeName;
 114+
 115+ $definitionIdAttribute = new Attribute("definition-id", "Definition identifier", "integer");
 116+
 117+ if ($filterOnLanguage && !$hasMetaDataAttributes)
 118+ $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, "text");
 119+ else
 120+ $alternativeDefinitionAttribute = new Attribute("alternative-definition", $wgAlternativeDefinitionAttributeName, new RecordSetType($translatedTextStructure));
 121+
 122+ $sourceAttribute = new Attribute("source-id", $wgSourceAttributeName, $definedMeaningReferenceType);
 123+
 124+ global
 125+ $alternativeDefinitionsAttribute, $wgAlternativeDefinitionsAttributeName;
 126+
 127+ $alternativeDefinitionsAttribute = new Attribute("alternative-definitions", $wgAlternativeDefinitionsAttributeName, new RecordSetType(new Structure($definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute)));
 128+
 129+ global
 130+ $synonymsAndTranslationsAttribute, $syntransIdAttribute;
 131+
 132+ if ($filterOnLanguage)
 133+ $synonymsAndTranslationsCaption = "Synonyms";
 134+ else
 135+ $synonymsAndTranslationsCaption = "Synonyms and translations";
 136+
 137+ $syntransIdAttribute = new Attribute("syntrans-id", "$synonymsAndTranslationsCaption identifier", "integer");
 138+ $synonymsAndTranslationsAttribute = new Attribute("synonyms-translations", "$synonymsAndTranslationsCaption", new RecordSetType(new Structure($syntransIdAttribute, $expressionAttribute, $identicalMeaningAttribute, $objectAttributesAttribute)));
 139+
 140+ global
 141+ $translatedTextAttributeIdAttribute, $translatedTextValueIdAttribute, $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute,
 142+ $translatedTextAttributeValuesStructure, $wgTranslatedTextAttributeValuesAttributeName, $wgTranslatedTextAttributeAttributeName, $wgTranslatedTextAttributeValueAttributeName;
 143+
 144+ $translatedTextAttributeIdAttribute = new Attribute("translated-text-attribute-id", "Attribute identifier", "object-id");
 145+ $translatedTextAttributeAttribute = new Attribute("translated-text-attribute", $wgTranslatedTextAttributeAttributeName, $definedMeaningReferenceType);
 146+ $translatedTextValueIdAttribute = new Attribute("translated-text-value-id", "Translated text value identifier", "translated-text-value-id");
 147+
 148+ if ($filterOnLanguage && !$hasMetaDataAttributes)
 149+ $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, "text");
 150+ else
 151+ $translatedTextValueAttribute = new Attribute("translated-text-value", $wgTranslatedTextAttributeValueAttributeName, new RecordSetType($translatedTextStructure));
 152+
 153+ $translatedTextAttributeValuesStructure = new Structure($translatedTextAttributeIdAttribute, $translatedTextAttributeAttribute, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $objectAttributesAttribute);
 154+ $translatedTextAttributeValuesAttribute = new Attribute("translated-text-attribute-values", $wgTranslatedTextAttributeValuesAttributeName, new RecordSetType($translatedTextAttributeValuesStructure));
 155+
 156+ global
 157+ $textAttributeIdAttribute, $textAttributeAttribute, $textAttributeValuesStructure, $textAttributeValuesAttribute,
 158+ $wgTextAttributeValuesAttributeName, $wgTextAttributeAttributeName;
 159+
 160+ $textAttributeIdAttribute = new Attribute("text-attribute-id", "Attribute identifier", "object-id");
 161+ $textAttributeObjectAttribute = new Attribute("text-attribute-object-id", "Attribute object", "object-id");
 162+ $textAttributeAttribute = new Attribute("text-attribute", $wgTextAttributeAttributeName, new RecordSetType($definedMeaningReferenceStructure));
 163+ $textAttributeValuesStructure = new Structure($textAttributeIdAttribute, $textAttributeObjectAttribute, $textAttributeAttribute, $textAttribute, $objectAttributesAttribute);
 164+ $textAttributeValuesAttribute = new Attribute("text-attribute-values", $wgTextAttributeValuesAttributeName, new RecordSetType($textAttributeValuesStructure));
 165+
 166+ global
 167+ $urlAttribute, $urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttributeValuesStructure, $urlAttributeValuesAttribute,
 168+ $wgUrlAttributeValuesAttributeName, $wgUrlAttributeAttributeName;
 169+
 170+ $urlAttribute = new Attribute("url", "URL", "url");
 171+ $urlAttributeIdAttribute = new Attribute("url-attribute-id", "Attribute identifier", "object-id");
 172+ $urlAttributeObjectAttribute = new Attribute("url-attribute-object-id", "Attribute object", "object-id");
 173+ $urlAttributeAttribute = new Attribute("url-attribute", $wgUrlAttributeAttributeName, new RecordSetType($definedMeaningReferenceStructure));
 174+ $urlAttributeValuesStructure = new Structure($urlAttributeIdAttribute, $urlAttributeObjectAttribute, $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute);
 175+ $urlAttributeValuesAttribute = new Attribute("url-attribute-values", $wgUrlAttributeValuesAttributeName, new RecordSetType($urlAttributeValuesStructure));
 176+
 177+ global
 178+ $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute,
 179+ $wgOptionAttributeAttributeName, $wgOptionAttributeOptionAttributeName, $wgOptionAttributeValuesAttributeName;
 180+
 181+ $optionAttributeIdAttribute = new Attribute('option-attribute-id', 'Attribute identifier', 'object-id');
 182+ $optionAttributeObjectAttribute = new Attribute('option-attribute-object-id', 'Attribute object', 'object-id');
 183+ $optionAttributeAttribute = new Attribute('option-attribute', $wgOptionAttributeAttributeName, $definedMeaningReferenceType);
 184+ $optionAttributeOptionAttribute = new Attribute('option-attribute-option', $wgOptionAttributeOptionAttributeName, $definedMeaningReferenceType);
 185+ $optionAttributeValuesStructure = new Structure($optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionAttribute, $objectAttributesAttribute);
 186+ $optionAttributeValuesAttribute = new Attribute('option-attribute-values', $wgOptionAttributeValuesAttributeName, new RecordSetType($optionAttributeValuesStructure));
 187+
 188+ global
 189+ $optionAttributeOptionIdAttribute, $optionAttributeOptionsAttribute;
 190+
 191+ $optionAttributeOptionIdAttribute = new Attribute('option-attribute-option-id', 'Option identifier', 'object-id');
 192+ $optionAttributeOptionsStructure = new Structure($optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute);
 193+ $optionAttributeOptionsAttribute = new Attribute('option-attribute-options', 'Options', new RecordSetType($optionAttributeOptionsStructure));
 194+
 195+ global
 196+ $definitionAttribute, $definedMeaningAttribute, $translatedTextAttribute, $classAttributesAttribute,
 197+ $wgDefinitionAttributeName;
 198+
 199+ if ($filterOnLanguage && !$hasMetaDataAttributes)
 200+ $translatedTextAttribute = new Attribute("translated-text", "Text", "text");
 201+ else
 202+ $translatedTextAttribute = new Attribute("translated-text", "Translated text", new RecordSetType($translatedTextStructure));
 203+
 204+ $definitionAttribute = new Attribute("definition", $wgDefinitionAttributeName, new RecordType(new Structure($translatedTextAttribute, $objectAttributesAttribute)));
 205+ $definedMeaningAttribute = new Attribute("defined-meaning", "Defined meaning", new RecordType(new Structure($definitionAttribute, $classAttributesAttribute, $alternativeDefinitionsAttribute, $synonymsAndTranslationsAttribute, $relationsAttribute, $classMembershipAttribute, $collectionMembershipAttribute, $objectAttributesAttribute)));
 206+
 207+ global
 208+ $expressionsAttribute, $expressionMeaningStructure, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute,
 209+ $wgExactMeaningsAttributeName, $wgApproximateMeaningsAttributeName;
 210+
 211+ $expressionMeaningStructure = new Structure($definedMeaningIdAttribute, $textAttribute, $definedMeaningAttribute);
 212+ $expressionExactMeaningsAttribute = new Attribute("expression-exact-meanings", $wgExactMeaningsAttributeName, new RecordSetType($expressionMeaningStructure));
 213+ $expressionApproximateMeaningsAttribute = new Attribute("expression-approximate-meanings", $wgApproximateMeaningsAttributeName, new RecordSetType($expressionMeaningStructure));
 214+
 215+ global
 216+ $expressionMeaningsAttribute, $expressionMeaningsStructure, $expressionApproximateMeaningAttribute;
 217+
 218+ $expressionMeaningsStructure = new Structure($expressionExactMeaningsAttribute, $expressionApproximateMeaningAttribute);
 219+ $expressionMeaningsAttribute = new Attribute("expression-meanings", "Expression meanings", new RecordType($expressionMeaningsStructure));
 220+
 221+ $expressionsAttribute = new Attribute("expressions", "Expressions", new RecordSetType(new Structure($expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute)));
 222+
 223+ global
 224+ $objectIdAttribute, $objectAttributesStructure, $wgAnnotationAttributeName;
 225+
 226+ $objectIdAttribute = new Attribute("object-id", "Object identifier", "object-id");
 227+ $objectAttributesStructure = new Structure($objectIdAttribute, $textAttributeValuesAttribute, $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute);
 228+ $objectAttributesAttribute = new Attribute("object-attributes", $wgAnnotationAttributeName, new RecordType($objectAttributesStructure));
 229+
 230+ global
 231+ $classAttributesStructure,
 232+ // $classAttributeClassAttribute,
 233+ $classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute;
 234+
 235+ $classAttributeIdAttribute = new Attribute("class-attribute-id", "Class attribute identifier", "object-id");
 236+ //$classAttributeClassAttribute = new Attribute("class-attribute-class", "Class", "defined-meaning-id");
 237+ $classAttributeAttributeAttribute = new Attribute("class-attribute-attribute", "Attribute", new RecordType($definedMeaningReferenceStructure));
 238+ $classAttributeLevelAttribute = new Attribute("class-attribute-level", "Level", new RecordType($definedMeaningReferenceStructure));
 239+ $classAttributeTypeAttribute = new Attribute("class-attribute-type", "Type", "short-text");
 240+ $classAttributesStructure = new Structure($classAttributeIdAttribute, $classAttributeAttributeAttribute, $classAttributeLevelAttribute, $classAttributeTypeAttribute, $optionAttributeOptionsAttribute);
 241+ $classAttributesAttribute = new Attribute("class-attributes", "Class attributes", new RecordSetType($classAttributesStructure));
 242+}
 243+
 244+?>
Property changes on: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
___________________________________________________________________
Added: svn:eol-style
1245 + native
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
@@ -0,0 +1,490 @@
 2+<?php
 3+
 4+require_once('Editor.php');
 5+require_once('OmegaWikiAttributes.php');
 6+require_once('WikiDataBootstrappedMeanings.php');
 7+require_once('Fetcher.php');
 8+
 9+function initializeObjectAttributeEditors($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
 10+ global
 11+ $objectAttributesAttribute,
 12+ $definedMeaningObjectAttributesEditor, $definedMeaningIdAttribute,
 13+ $definitionObjectAttributesEditor, $definedMeaningIdAttribute,
 14+ $synonymsAndTranslationsObjectAttributesEditor, $syntransIdAttribute,
 15+ $relationsObjectAttributesEditor, $relationIdAttribute,
 16+ $possiblySynonymousObjectAttributesEditor, $possiblySynonymousIdAttribute,
 17+ $textValueObjectAttributesEditor, $textAttributeIdAttribute,
 18+ $urlValueObjectAttributesEditor, $urlAttributeIdAttribute,
 19+ $translatedTextValueObjectAttributesEditor, $translatedTextAttributeIdAttribute,
 20+ $optionValueObjectAttributesEditor, $optionAttributeIdAttribute,
 21+ $definedMeaningMeaningName, $definitionMeaningName,
 22+ $relationMeaningName, $synTransMeaningName,
 23+ $annotationMeaningName;
 24+
 25+ $definedMeaningObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 26+ $definitionObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 27+ $synonymsAndTranslationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 28+ $possiblySynonymousObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 29+ $relationsObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 30+ $textValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 31+ $urlValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 32+ $translatedTextValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 33+ $optionValueObjectAttributesEditor = new RecordUnorderedListEditor($objectAttributesAttribute, 5);
 34+
 35+ setObjectAttributesEditor($definedMeaningObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $definedMeaningIdAttribute), $definedMeaningMeaningName, new ObjectIdFetcher(0, $definedMeaningIdAttribute));
 36+ setObjectAttributesEditor($definitionObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new DefinitionObjectIdFetcher(0, $definedMeaningIdAttribute), $definitionMeaningName, new ObjectIdFetcher(0, $definedMeaningIdAttribute));
 37+ setObjectAttributesEditor($synonymsAndTranslationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $syntransIdAttribute), $synTransMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 38+ setObjectAttributesEditor($possiblySynonymousObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $possiblySynonymousIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 39+ setObjectAttributesEditor($relationsObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $relationIdAttribute), $relationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 40+ setObjectAttributesEditor($textValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 41+ setObjectAttributesEditor($urlValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $textAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 42+ setObjectAttributesEditor($translatedTextValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $translatedTextAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 43+ setObjectAttributesEditor($optionValueObjectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, new ObjectIdFetcher(0, $optionAttributeIdAttribute), $annotationMeaningName, new ObjectIdFetcher(1, $definedMeaningIdAttribute));
 44+}
 45+
 46+function getTransactionEditor($attribute) {
 47+ global
 48+ $userAttribute, $timestampAttribute;
 49+
 50+ $transactionEditor = new RecordTableCellEditor($attribute);
 51+ $transactionEditor->addEditor(createUserViewer($userAttribute));
 52+ $transactionEditor->addEditor(new TimestampEditor($timestampAttribute, new SimplePermissionController(false), true));
 53+
 54+ return $transactionEditor;
 55+}
 56+
 57+function createTableLifeSpanEditor($attribute) {
 58+ global
 59+ $addTransactionAttribute, $removeTransactionAttribute;
 60+
 61+ $result = new RecordTableCellEditor($attribute);
 62+ $result->addEditor(getTransactionEditor($addTransactionAttribute));
 63+ $result->addEditor(getTransactionEditor($removeTransactionAttribute));
 64+
 65+ return $result;
 66+}
 67+
 68+function addTableLifeSpanEditor($editor, $showRecordLifeSpan) {
 69+ global
 70+ $recordLifeSpanAttribute, $addTransactionAttribute, $removeTransactionAttribute, $wgRequest;
 71+
 72+ if ($wgRequest->getText('action') == 'history' && $showRecordLifeSpan)
 73+ $editor->addEditor(createTableLifeSpanEditor($recordLifeSpanAttribute));
 74+}
 75+
 76+function addTableAuthorityEditor($editor, $showAuthority) {
 77+ global
 78+ $authorityAttribute;
 79+
 80+ if ($showAuthority)
 81+ $editor->addEditor(createShortTextViewer($authorityAttribute));
 82+}
 83+
 84+function addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority) {
 85+ addTableLifeSpanEditor($editor, $showRecordLifeSpan);
 86+ addTableAuthorityEditor($editor, $showAuthority);
 87+}
 88+
 89+function getDefinitionEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
 90+ global
 91+ $definitionAttribute, $translatedTextAttribute, $definitionObjectAttributesEditor;
 92+
 93+ if ($filterLanguageId == 0)
 94+ $controller = new DefinedMeaningDefinitionController();
 95+ else
 96+ $controller = new DefinedMeaningFilteredDefinitionController($filterLanguageId);
 97+
 98+ $editor = new RecordDivListEditor($definitionAttribute);
 99+ $editor->addEditor(getTranslatedTextEditor($translatedTextAttribute, $controller, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
 100+ $editor->addEditor(new PopUpEditor($definitionObjectAttributesEditor, 'Annotation'));
 101+
 102+ return $editor;
 103+}
 104+
 105+function getTranslatedTextEditor($attribute, $controller, $filterLanguageId, $showRecordLifeSpan, $showAuthority) {
 106+ global
 107+ $languageAttribute, $textAttribute;
 108+
 109+ if ($filterLanguageId == 0 || $showRecordLifeSpan || $showAuthority) {
 110+ $editor = new RecordSetTableEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, true, $controller);
 111+
 112+ if ($filterLanguageId == 0)
 113+ $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
 114+
 115+ $editor->addEditor(new TextEditor($textAttribute, new SimplePermissionController(true), true));
 116+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 117+ }
 118+ else
 119+ $editor = new TextEditor($attribute, new SimplePermissionController(true), true, false, 0, $controller);
 120+
 121+ return $editor;
 122+}
 123+
 124+function setObjectAttributesEditor($objectAttributesEditor, $filterLanguageId, $showRecordLifeSpan, $showAuthority, $objectIdFetcher, $levelDefinedMeaningName, $dmObjectIdFetcher) {
 125+ $objectAttributesEditor->addEditor(getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new TextAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
 126+ $objectAttributesEditor->addEditor(getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, new TranslatedTextAttributeValuesController($objectIdFetcher, $filterLanguageId), $levelDefinedMeaningName, $dmObjectIdFetcher));
 127+ $objectAttributesEditor->addEditor(getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new URLAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
 128+ $objectAttributesEditor->addEditor(getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, new OptionAttributeValuesController($objectIdFetcher), $levelDefinedMeaningName, $dmObjectIdFetcher));
 129+}
 130+
 131+function getAlternativeDefinitionsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
 132+ global
 133+ $alternativeDefinitionsAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
 134+
 135+ if ($filterLanguageId == 0)
 136+ $alternativeDefinitionController = new DefinedMeaningAlternativeDefinitionController();
 137+ else
 138+ $alternativeDefinitionController = new DefinedMeaningFilteredAlternativeDefinitionController($filterLanguageId);
 139+
 140+ $editor = new RecordSetTableEditor($alternativeDefinitionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningAlternativeDefinitionsController($filterLanguageId));
 141+ $editor->addEditor(getTranslatedTextEditor($alternativeDefinitionAttribute, $alternativeDefinitionController, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
 142+ $editor->addEditor(new DefinedMeaningReferenceEditor($sourceAttribute, new SimplePermissionController(false), true));
 143+
 144+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 145+
 146+ return $editor;
 147+}
 148+
 149+function getExpressionTableCellEditor($attribute, $filterLanguageId) {
 150+ global
 151+ $languageAttribute, $spellingAttribute;
 152+
 153+ if ($filterLanguageId == 0) {
 154+ $editor = new RecordTableCellEditor($attribute);
 155+ $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
 156+ $editor->addEditor(new SpellingEditor($spellingAttribute, new SimplePermissionController(false), true));
 157+ }
 158+ else
 159+ $editor = new SpellingEditor($attribute, new SimplePermissionController(false), true);
 160+
 161+ return $editor;
 162+}
 163+
 164+function getClassAttributesEditor($showRecordLifeSpan, $showAuthority) {
 165+ global
 166+ $definedMeaningIdAttribute, $classAttributesAttribute, $classAttributeLevelAttribute, $classAttributeAttributeAttribute, $classAttributeTypeAttribute;
 167+
 168+ $tableEditor = new RecordSetTableEditor($classAttributesAttribute, new SimplePermissionController(true), new ShowEditFieldForClassesChecker(0, $definedMeaningIdAttribute), new AllowAddController(true), true, false, new ClassAttributesController());
 169+ $tableEditor->addEditor(new ClassAttributesLevelDefinedMeaningEditor($classAttributeLevelAttribute, new SimplePermissionController(false), true));
 170+ $tableEditor->addEditor(new DefinedMeaningReferenceEditor($classAttributeAttributeAttribute, new SimplePermissionController(false), true));
 171+ $tableEditor->addEditor(new ClassAttributesTypeEditor($classAttributeTypeAttribute, new SimplePermissionController(false), true));
 172+ $tableEditor->addEditor(new PopupEditor(getOptionAttributeOptionsEditor(), 'Options'));
 173+
 174+ addTableMetadataEditors($tableEditor, $showRecordLifeSpan, $showAuthority);
 175+
 176+ return $tableEditor;
 177+}
 178+
 179+function getSynonymsAndTranslationsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority) {
 180+ global
 181+ $synonymsAndTranslationsAttribute, $identicalMeaningAttribute, $expressionIdAttribute,
 182+ $expressionAttribute, $synonymsAndTranslationsObjectAttributesEditor;
 183+
 184+ $tableEditor = new RecordSetTableEditor($synonymsAndTranslationsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new SynonymTranslationController($filterLanguageId));
 185+ $tableEditor->addEditor(getExpressionTableCellEditor($expressionAttribute, $filterLanguageId));
 186+ $tableEditor->addEditor(new BooleanEditor($identicalMeaningAttribute, new SimplePermissionController(true), true, true));
 187+ $tableEditor->addEditor(new PopUpEditor($synonymsAndTranslationsObjectAttributesEditor, 'Annotation'));
 188+
 189+ addTableMetadataEditors($tableEditor, $showRecordLifeSpan, $showAuthority);
 190+
 191+ return $tableEditor;
 192+}
 193+
 194+function getDefinedMeaningRelationsEditor($showRecordLifeSpan, $showAuthority) {
 195+ global
 196+ $relationsAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute,
 197+ $relationsObjectAttributesEditor;
 198+
 199+ $editor = new RecordSetTableEditor($relationsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningRelationController());
 200+ $editor->addEditor(new RelationTypeReferenceEditor($relationTypeAttribute, new SimplePermissionController(false), true));
 201+ $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
 202+ $editor->addEditor(new PopUpEditor($relationsObjectAttributesEditor, 'Annotation'));
 203+
 204+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 205+
 206+ return $editor;
 207+}
 208+
 209+function getDefinedMeaningReciprocalRelationsEditor($showRecordLifeSpan, $showAuthority) {
 210+ global
 211+ $reciprocalRelationsAttribute, $relationTypeAttribute, $otherDefinedMeaningAttribute,
 212+ $relationsObjectAttributesEditor;
 213+
 214+ $editor = new RecordSetTableEditor($reciprocalRelationsAttribute, new SimplePermissionController(false), new ShowEditFieldChecker(true), new AllowAddController(false), false, false, null);
 215+ $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
 216+ $editor->addEditor(new RelationTypeReferenceEditor($relationTypeAttribute, new SimplePermissionController(false), true));
 217+ $editor->addEditor(new PopUpEditor($relationsObjectAttributesEditor, 'Annotation'));
 218+
 219+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 220+
 221+ return $editor;
 222+}
 223+
 224+function getDefinedMeaningClassMembershipEditor($showRecordLifeSpan, $showAuthority) {
 225+ global
 226+ $classMembershipAttribute, $classAttribute;
 227+
 228+ $editor = new RecordSetTableEditor($classMembershipAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningClassMembershipController());
 229+ $editor->addEditor(new ClassReferenceEditor($classAttribute, new SimplePermissionController(false), true));
 230+
 231+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 232+
 233+ return $editor;
 234+}
 235+
 236+function getGroupedRelationTypeEditor($groupedRelationsAttribute, $groupedRelationIdAttribute, $otherDefinedMeaningAttribute, $relationTypeId, $showRecordLifeSpan, $showAuthority, $objectAttributesEditor) {
 237+ $editor = new RecordSetTableEditor(
 238+ $groupedRelationsAttribute,
 239+ new SimplePermissionController(true),
 240+ new ShowEditFieldChecker(true),
 241+ new AllowAddController(true),
 242+ true,
 243+ false,
 244+ new GroupedRelationTypeController($relationTypeId, $groupedRelationIdAttribute, $otherDefinedMeaningAttribute)
 245+ );
 246+
 247+ $editor->addEditor(new DefinedMeaningReferenceEditor($otherDefinedMeaningAttribute, new SimplePermissionController(false), true));
 248+
 249+ if ($objectAttributesEditor != null)
 250+ $editor->addEditor(new PopUpEditor($objectAttributesEditor, 'Annotation'));
 251+
 252+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 253+
 254+ return $editor;
 255+}
 256+
 257+function getDefinedMeaningCollectionMembershipEditor($showRecordLifeSpan, $showAuthority) {
 258+ global
 259+ $collectionMembershipAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute;
 260+
 261+ $editor = new RecordSetTableEditor($collectionMembershipAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new DefinedMeaningCollectionController());
 262+ $editor->addEditor(new CollectionReferenceEditor($collectionMeaningAttribute, new SimplePermissionController(false), true));
 263+ $editor->addEditor(new ShortTextEditor($sourceIdentifierAttribute, new SimplePermissionController(true), true));
 264+
 265+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 266+
 267+ return $editor;
 268+}
 269+
 270+function getTextAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
 271+ global
 272+ $textAttributeAttribute, $textAttribute, $textAttributeValuesAttribute, $textValueObjectAttributesEditor;
 273+
 274+ $editor = new RecordSetTableEditor($textAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
 275+ $editor->addEditor(new TextAttributeEditor($textAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 276+ $editor->addEditor(new TextEditor($textAttribute, new SimplePermissionController(true), true));
 277+ $editor->addEditor(new PopUpEditor($textValueObjectAttributesEditor, 'Annotation'));
 278+
 279+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 280+
 281+ return $editor;
 282+}
 283+
 284+function getURLAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
 285+ global
 286+ $urlAttributeAttribute, $urlAttribute, $urlAttributeValuesAttribute, $urlValueObjectAttributesEditor;
 287+
 288+ $editor = new RecordSetTableEditor($urlAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
 289+ $editor->addEditor(new TextAttributeEditor($urlAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 290+ $editor->addEditor(new URLEditor($urlAttribute, new SimplePermissionController(true), true));
 291+ $editor->addEditor(new PopUpEditor($urlValueObjectAttributesEditor, 'Annotation'));
 292+
 293+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 294+
 295+ return $editor;
 296+}
 297+
 298+function getTranslatedTextAttributeValuesEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
 299+ global
 300+ $translatedTextAttributeAttribute, $translatedTextValueAttribute, $translatedTextAttributeValuesAttribute, $translatedTextValueObjectAttributesEditor;
 301+
 302+ if ($filterLanguageId == 0)
 303+ $translatedTextAttributeValueController = new TranslatedTextAttributeValueController();
 304+ else
 305+ $translatedTextAttributeValueController = new FilteredTranslatedTextAttributeValueController($filterLanguageId);
 306+
 307+ $editor = new RecordSetTableEditor($translatedTextAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
 308+ $editor->addEditor(new TranslatedTextAttributeEditor($translatedTextAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 309+ $editor->addEditor(getTranslatedTextEditor($translatedTextValueAttribute, $translatedTextAttributeValueController, $filterLanguageId, $showRecordLifeSpan, $showAuthority));
 310+ $editor->addEditor(new PopUpEditor($translatedTextValueObjectAttributesEditor, 'Annotation'));
 311+
 312+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 313+
 314+ return $editor;
 315+}
 316+
 317+function getOptionAttributeValuesEditor($showRecordLifeSpan, $showAuthority, $controller, $levelDefinedMeaningName, $objectIdFetcher) {
 318+ global
 319+ $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeValuesAttribute, $optionValueObjectAttributesEditor;
 320+
 321+ $editor = new RecordSetTableEditor($optionAttributeValuesAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, $controller);
 322+
 323+ $editor->addEditor(new OptionAttributeEditor($optionAttributeAttribute, new SimplePermissionController(false), true, $levelDefinedMeaningName, $objectIdFetcher));
 324+ $editor->addEditor(new OptionSelectEditor($optionAttributeOptionAttribute, new SimplePermissionController(false), true));
 325+ $editor->addEditor(new PopUpEditor($optionValueObjectAttributesEditor, 'Annotation'));
 326+
 327+ addTableMetadataEditors($editor, $showRecordLifeSpan, $showAuthority);
 328+
 329+ return $editor;
 330+}
 331+
 332+function getOptionAttributeOptionsEditor() {
 333+ global
 334+ $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsAttribute;
 335+
 336+ $editor = new RecordSetTableEditor($optionAttributeOptionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), true, false, new OptionAttributeOptionsController());
 337+ $editor->addEditor(new DefinedMeaningReferenceEditor($optionAttributeOptionAttribute, new SimplePermissionController(false), true));
 338+ $editor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
 339+
 340+ return $editor;
 341+}
 342+
 343+function getExpressionMeaningsEditor($attribute, $allowAdd, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
 344+ global
 345+ $definedMeaningIdAttribute;
 346+
 347+ $definedMeaningEditor = getDefinedMeaningEditor($filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority);
 348+
 349+ $definedMeaningCaptionEditor = new DefinedMeaningHeaderEditor($definedMeaningIdAttribute, new SimplePermissionController(false), true, 75);
 350+ $definedMeaningCaptionEditor->setAddText("New exact meaning");
 351+
 352+ $expressionMeaningsEditor = new RecordSetListEditor($attribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController($allowAdd), false, $allowAdd, new ExpressionMeaningController($filterLanguageId), 3, false);
 353+ $expressionMeaningsEditor->setCaptionEditor($definedMeaningCaptionEditor);
 354+ $expressionMeaningsEditor->setValueEditor($definedMeaningEditor);
 355+
 356+ return $expressionMeaningsEditor;
 357+}
 358+
 359+function getExpressionsEditor($spelling, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
 360+ global
 361+ $expressionMeaningsAttribute, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute, $expressionAttribute, $languageAttribute, $expressionsAttribute;
 362+
 363+ $expressionMeaningsRecordEditor = new RecordUnorderedListEditor($expressionMeaningsAttribute, 3);
 364+
 365+ $exactMeaningsEditor = getExpressionMeaningsEditor($expressionExactMeaningsAttribute, true, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority);
 366+ $expressionMeaningsRecordEditor->addEditor($exactMeaningsEditor);
 367+ $expressionMeaningsRecordEditor->addEditor(getExpressionMeaningsEditor($expressionApproximateMeaningsAttribute, false, $filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority));
 368+
 369+ $expressionMeaningsRecordEditor->expandEditor($exactMeaningsEditor);
 370+
 371+ if ($filterLanguageId == 0) {
 372+ $expressionEditor = new RecordSpanEditor($expressionAttribute, ': ', ' - ');
 373+ $expressionEditor->addEditor(new LanguageEditor($languageAttribute, new SimplePermissionController(false), true));
 374+
 375+ $expressionsEditor = new RecordSetListEditor($expressionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), false, false, new ExpressionController($spelling, $filterLanguageId), 2, true);
 376+ $expressionsEditor->setCaptionEditor($expressionEditor);
 377+ $expressionsEditor->setValueEditor($expressionMeaningsRecordEditor);
 378+ }
 379+ else {
 380+ $expressionEditor = new RecordSubRecordEditor($expressionAttribute);
 381+ $expressionEditor->setSubRecordEditor($expressionMeaningsRecordEditor);
 382+
 383+ $expressionsEditor = new RecordSetFirstRecordEditor($expressionsAttribute, new SimplePermissionController(true), new ShowEditFieldChecker(true), new AllowAddController(true), false, false, new ExpressionController($spelling, $filterLanguageId));
 384+ $expressionsEditor->setRecordEditor($expressionEditor);
 385+ }
 386+
 387+ return $expressionsEditor;
 388+}
 389+
 390+function getDefinedMeaningEditor($filterLanguageId, $possiblySynonymousRelationTypeId, $showRecordLifeSpan, $showAuthority) {
 391+ global
 392+ $definedMeaningAttribute, $possiblySynonymousIdAttribute, $possiblySynonymousAttribute,
 393+ $possibleSynonymAttribute, $definedMeaningObjectAttributesEditor, $possiblySynonymousObjectAttributesEditor;
 394+
 395+ $definitionEditor = getDefinitionEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority);
 396+ $classAttributesEditor = getClassAttributesEditor($showRecordLifeSpan, $showAuthority);
 397+ $synonymsAndTranslationsEditor = getSynonymsAndTranslationsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority);
 398+ $relationsEditor = getDefinedMeaningRelationsEditor($showRecordLifeSpan, $showAuthority);
 399+ $reciprocalRelationsEditor = getDefinedMeaningReciprocalRelationsEditor($showRecordLifeSpan, $showAuthority);
 400+ $classMembershipEditor = getDefinedMeaningClassMembershipEditor($showRecordLifeSpan, $showAuthority);
 401+ $collectionMembershipEditor = getDefinedMeaningCollectionMembershipEditor($showRecordLifeSpan, $showAuthority);
 402+
 403+ $definedMeaningEditor = new RecordUnorderedListEditor($definedMeaningAttribute, 4);
 404+ $definedMeaningEditor->addEditor($definitionEditor);
 405+ $definedMeaningEditor->addEditor($classAttributesEditor);
 406+ $definedMeaningEditor->addEditor(getAlternativeDefinitionsEditor($filterLanguageId, $showRecordLifeSpan, $showAuthority));
 407+ $definedMeaningEditor->addEditor($synonymsAndTranslationsEditor);
 408+
 409+ if ($possiblySynonymousRelationTypeId != 0)
 410+ $definedMeaningEditor->addEditor(
 411+ getGroupedRelationTypeEditor(
 412+ $possiblySynonymousAttribute,
 413+ $possiblySynonymousIdAttribute,
 414+ $possibleSynonymAttribute,
 415+ $possiblySynonymousRelationTypeId,
 416+ $showRecordLifeSpan,
 417+ $showAuthority,
 418+ $possiblySynonymousObjectAttributesEditor
 419+ )
 420+ );
 421+
 422+ $definedMeaningEditor->addEditor($relationsEditor);
 423+ $definedMeaningEditor->addEditor($reciprocalRelationsEditor);
 424+ $definedMeaningEditor->addEditor($classMembershipEditor);
 425+ $definedMeaningEditor->addEditor($collectionMembershipEditor);
 426+ $definedMeaningEditor->addEditor($definedMeaningObjectAttributesEditor);
 427+
 428+ $definedMeaningEditor->expandEditor($definitionEditor);
 429+ $definedMeaningEditor->expandEditor($synonymsAndTranslationsEditor);
 430+
 431+ return $definedMeaningEditor;
 432+}
 433+
 434+function createTableViewer($attribute) {
 435+ return new RecordSetTableEditor($attribute, new SimplePermissionController(false), new ShowEditFieldChecker(true), new AllowAddController(false), false, false, null);
 436+}
 437+
 438+function createLanguageViewer($attribute) {
 439+ return new LanguageEditor($attribute, new SimplePermissionController(false), false);
 440+}
 441+
 442+function createLongTextViewer($attribute) {
 443+ $result = new TextEditor($attribute, new SimplePermissionController(false), false);
 444+
 445+ return $result;
 446+}
 447+
 448+function createShortTextViewer($attribute) {
 449+ return new ShortTextEditor($attribute, new SimplePermissionController(false), false);
 450+}
 451+
 452+function createURLViewer($attribute) {
 453+ return new URLEditor($attribute, new SimplePermissionController(false), false);
 454+}
 455+
 456+function createBooleanViewer($attribute) {
 457+ return new BooleanEditor($attribute, new SimplePermissionController(false), false, false);
 458+}
 459+
 460+function createDefinedMeaningReferenceViewer($attribute) {
 461+ return new DefinedMeaningReferenceEditor($attribute, new SimplePermissionController(false), false);
 462+}
 463+
 464+function createSuggestionsTableViewer($attribute) {
 465+ $result = createTableViewer($attribute);
 466+ $result->setRowHTMLAttributes(array(
 467+ "class" => "suggestion-row",
 468+ "onclick" => "suggestRowClicked(event, this)",
 469+ "onmouseover" => "mouseOverRow(this)",
 470+ "onmouseout" => "mouseOutRow(this)"
 471+ ));
 472+
 473+ return $result;
 474+}
 475+
 476+function createUserViewer($attribute) {
 477+ return new UserEditor($attribute, new SimplePermissionController(false), false);
 478+}
 479+
 480+function createTranslatedTextViewer($attribute) {
 481+ global
 482+ $languageAttribute, $textAttribute;
 483+
 484+ $result = createTableViewer($attribute);
 485+ $result->addEditor(createLanguageViewer($languageAttribute));
 486+ $result->addEditor(createLongTextViewer($textAttribute));
 487+
 488+ return $result;
 489+}
 490+
 491+?>
\ No newline at end of file
Property changes on: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
___________________________________________________________________
Added: svn:eol-style
1492 + native
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
@@ -0,0 +1,987 @@
 2+<?php
 3+
 4+require_once('OmegaWikiAttributes.php');
 5+require_once('Record.php');
 6+require_once('RecordSet.php');
 7+require_once('Expression.php');
 8+require_once('Transaction.php');
 9+require_once('WikiDataTables.php');
 10+require_once('RecordSetQueries.php');
 11+
 12+function getSynonymSQLForLanguage($languageId, &$definedMeaningIds) {
 13+ return
 14+ "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
 15+ " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
 16+ " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
 17+ " AND " . getLatestTransactionRestriction('uw_syntrans') .
 18+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 19+ " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
 20+ " AND uw_expression_ns.language_id=" . $languageId .
 21+ " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
 22+ " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
 23+ " AND uw_syntrans.identical_meaning=1 " .
 24+ " GROUP BY uw_defined_meaning.defined_meaning_id";
 25+}
 26+
 27+function getSynonymSQLForAnyLanguage(&$definedMeaningIds) {
 28+ return
 29+ "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
 30+ " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
 31+ " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
 32+ " AND " . getLatestTransactionRestriction('uw_syntrans') .
 33+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 34+ " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
 35+ " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
 36+ " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
 37+ " AND uw_syntrans.identical_meaning=1 " .
 38+ " GROUP BY uw_defined_meaning.defined_meaning_id";
 39+}
 40+
 41+function getDefiningSQLForLanguage($languageId, &$definedMeaningIds) {
 42+ return
 43+ "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS label " .
 44+ " FROM uw_defined_meaning, uw_syntrans, uw_expression_ns " .
 45+ " WHERE uw_defined_meaning.defined_meaning_id IN (" . implode(", ", $definedMeaningIds) . ")" .
 46+ " AND " . getLatestTransactionRestriction('uw_syntrans') .
 47+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 48+ " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
 49+ " AND uw_expression_ns.expression_id=uw_syntrans.expression_id " .
 50+ " AND uw_defined_meaning.defined_meaning_id=uw_syntrans.defined_meaning_id " .
 51+ " AND uw_syntrans.identical_meaning=1 " .
 52+ " AND uw_defined_meaning.expression_id=uw_expression_ns.expression_id " .
 53+ " AND uw_expression_ns.language_id=" . $languageId .
 54+ " GROUP BY uw_defined_meaning.defined_meaning_id";
 55+}
 56+
 57+function fetchDefinedMeaningReferenceRecords($sql, &$definedMeaningIds, &$definedMeaningReferenceRecords) {
 58+ global
 59+ $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
 60+ $definedMeaningDefiningExpressionAttribute;
 61+
 62+ $foundDefinedMeaningIds = array();
 63+
 64+ $dbr =& wfGetDB(DB_SLAVE);
 65+ $queryResult = $dbr->query($sql);
 66+
 67+ while ($row = $dbr->fetchObject($queryResult)) {
 68+ $definedMeaningId = $row->defined_meaning_id;
 69+
 70+ $record = new ArrayRecord($definedMeaningReferenceStructure);
 71+ $record->setAttributeValue($definedMeaningIdAttribute, $definedMeaningId);
 72+ $record->setAttributeValue($definedMeaningLabelAttribute, $row->label);
 73+
 74+ $definedMeaningReferenceRecords[$definedMeaningId] = $record;
 75+ $foundDefinedMeaningIds[] = $definedMeaningId;
 76+ }
 77+
 78+ $definedMeaningIds = array_diff($definedMeaningIds, $foundDefinedMeaningIds);
 79+}
 80+
 81+function fetchDefinedMeaningDefiningExpressions(&$definedMeaningIds, &$definedMeaningReferenceRecords) {
 82+ global
 83+ $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
 84+ $definedMeaningDefiningExpressionAttribute;
 85+
 86+ $dbr =& wfGetDB(DB_SLAVE);
 87+ $queryResult = $dbr->query(
 88+ "SELECT uw_defined_meaning.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling" .
 89+ " FROM uw_defined_meaning, uw_expression_ns " .
 90+ " WHERE uw_defined_meaning.expression_id=uw_expression_ns.expression_id " .
 91+ " AND " . getLatestTransactionRestriction('uw_defined_meaning') .
 92+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 93+ " AND uw_defined_meaning.defined_meaning_id IN (". implode(", ", $definedMeaningIds) .")"
 94+ );
 95+
 96+ while ($row = $dbr->fetchObject($queryResult)) {
 97+ $definedMeaningReferenceRecord = $definedMeaningReferenceRecords[$row->defined_meaning_id];
 98+
 99+ if ($definedMeaningReferenceRecord == null) {
 100+ $definedMeaningReferenceRecord = new ArrayRecord($definedMeaningReferenceStructure);
 101+ $definedMeaningReferenceRecord->setAttributeValue($definedMeaningIdAttribute, $row->defined_meaning_id);
 102+ $definedMeaningReferenceRecord->setAttributeValue($definedMeaningLabelAttribute, $row->spelling);
 103+ $definedMeaningReferenceRecords[$row->defined_meaning_id] = $definedMeaningReferenceRecord;
 104+ }
 105+
 106+ $definedMeaningReferenceRecord->setAttributeValue($definedMeaningDefiningExpressionAttribute, $row->spelling);
 107+ }
 108+}
 109+
 110+function getNullDefinedMeaningReferenceRecord() {
 111+ global
 112+ $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
 113+ $definedMeaningDefiningExpressionAttribute;
 114+
 115+ $record = new ArrayRecord($definedMeaningReferenceStructure);
 116+ $record->setAttributeValue($definedMeaningIdAttribute, 0);
 117+ $record->setAttributeValue($definedMeaningLabelAttribute, "");
 118+ $record->setAttributeValue($definedMeaningDefiningExpressionAttribute, "");
 119+
 120+ return $record;
 121+}
 122+
 123+function getDefinedMeaningReferenceRecords($definedMeaningIds) {
 124+ global
 125+ $wgUser;
 126+
 127+// $startTime = microtime(true);
 128+
 129+ $result = array();
 130+ $definedMeaningIdsForExpressions = $definedMeaningIds;
 131+
 132+ if (count($definedMeaningIds) > 0) {
 133+ $userLanguage = getLanguageIdForCode($wgUser->getOption('language'));
 134+
 135+ if ($userLanguage > 0)
 136+ $definingLanguage = $userLanguage;
 137+ else
 138+ $definingLanguage = 85;
 139+
 140+ fetchDefinedMeaningReferenceRecords(
 141+ getDefiningSQLForLanguage($definingLanguage, $definedMeaningIds),
 142+ $definedMeaningIds,
 143+ $result
 144+ );
 145+
 146+ if (count($definedMeaningIds) > 0) {
 147+ if ($userLanguage > 0)
 148+ fetchDefinedMeaningReferenceRecords(
 149+ getSynonymSQLForLanguage($userLanguage, $definedMeaningIds),
 150+ $definedMeaningIds,
 151+ $result
 152+ );
 153+
 154+ if (count($definedMeaningIds) > 0) {
 155+ fetchDefinedMeaningReferenceRecords(
 156+ getSynonymSQLForLanguage(85, $definedMeaningIds),
 157+ $definedMeaningIds,
 158+ $result
 159+ );
 160+
 161+ if (count($definedMeaningIds) > 0) {
 162+ fetchDefinedMeaningReferenceRecords(
 163+ getSynonymSQLForAnyLanguage($definedMeaningIds),
 164+ $definedMeaningIds,
 165+ $result
 166+ );
 167+ }
 168+ }
 169+ }
 170+
 171+ fetchDefinedMeaningDefiningExpressions($definedMeaningIdsForExpressions, $result);
 172+ $result[0] = getNullDefinedMeaningReferenceRecord();
 173+ }
 174+
 175+// $queriesTime = microtime(true) - $startTime;
 176+// echo "<!-- Defined meaning reference queries: " . $queriesTime . " -->\n";
 177+
 178+ return $result;
 179+}
 180+
 181+function expandDefinedMeaningReferencesInRecordSet($recordSet, $definedMeaningAttributes) {
 182+ $definedMeaningReferenceRecords = getDefinedMeaningReferenceRecords(getUniqueIdsInRecordSet($recordSet, $definedMeaningAttributes));
 183+
 184+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 185+ $record = $recordSet->getRecord($i);
 186+
 187+ foreach($definedMeaningAttributes as $definedMeaningAttribute)
 188+ $record->setAttributeValue(
 189+ $definedMeaningAttribute,
 190+ $definedMeaningReferenceRecords[$record->getAttributeValue($definedMeaningAttribute)]
 191+ );
 192+ }
 193+}
 194+
 195+function expandTranslatedContentInRecord($record, $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation) {
 196+ $record->setAttributeValue(
 197+ $translatedContentAttribute,
 198+ getTranslatedContentValue($record->getAttributeValue($idAttribute), $filterLanguageId, $queryTransactionInformation)
 199+ );
 200+}
 201+
 202+function expandTranslatedContentsInRecordSet($recordSet, $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation) {
 203+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++)
 204+ expandTranslatedContentInRecord($recordSet->getRecord($i), $idAttribute, $translatedContentAttribute, $filterLanguageId, $queryTransactionInformation);
 205+}
 206+
 207+function getExpressionReferenceRecords($expressionIds) {
 208+ global
 209+ $expressionStructure, $languageAttribute, $spellingAttribute;
 210+
 211+ if (count($expressionIds) > 0) {
 212+ $dbr =& wfGetDB(DB_SLAVE);
 213+ $queryResult = $dbr->query(
 214+ "SELECT expression_id, language_id, spelling" .
 215+ " FROM uw_expression_ns" .
 216+ " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
 217+ " AND ". getLatestTransactionRestriction('uw_expression_ns')
 218+ );
 219+
 220+ $result = array();
 221+
 222+ while ($row = $dbr->fetchObject($queryResult)) {
 223+ $record = new ArrayRecord($expressionStructure);
 224+ $record->setAttributeValue($languageAttribute, $row->language_id);
 225+ $record->setAttributeValue($spellingAttribute, $row->spelling);
 226+
 227+ $result[$row->expression_id] = $record;
 228+ }
 229+
 230+ return $result;
 231+ }
 232+ else
 233+ return array();
 234+}
 235+
 236+function expandExpressionReferencesInRecordSet($recordSet, $expressionAttributes) {
 237+ $expressionReferenceRecords = getExpressionReferenceRecords(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
 238+
 239+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 240+ $record = $recordSet->getRecord($i);
 241+
 242+ foreach($expressionAttributes as $expressionAttribute)
 243+ $record->setAttributeValue(
 244+ $expressionAttribute,
 245+ $expressionReferenceRecords[$record->getAttributeValue($expressionAttribute)]
 246+ );
 247+ }
 248+}
 249+
 250+function getExpressionSpellings($expressionIds) {
 251+ global
 252+ $expressionAttribute;
 253+
 254+ if (count($expressionIds) > 0) {
 255+ $dbr =& wfGetDB(DB_SLAVE);
 256+ $queryResult = $dbr->query(
 257+ "SELECT expression_id, spelling" .
 258+ " FROM uw_expression_ns" .
 259+ " WHERE expression_id IN (". implode(', ', $expressionIds) .")" .
 260+ " AND ". getLatestTransactionRestriction('uw_expression_ns')
 261+ );
 262+
 263+ $result = array();
 264+
 265+ while ($row = $dbr->fetchObject($queryResult))
 266+ $result[$row->expression_id] = $row->spelling;
 267+
 268+ return $result;
 269+ }
 270+ else
 271+ return array();
 272+}
 273+
 274+function expandExpressionSpellingsInRecordSet($recordSet, $expressionAttributes) {
 275+ $expressionSpellings = getExpressionSpellings(getUniqueIdsInRecordSet($recordSet, $expressionAttributes));
 276+
 277+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 278+ $record = $recordSet->getRecord($i);
 279+
 280+ foreach($expressionAttributes as $expressionAttribute)
 281+ $record->setAttributeValue(
 282+ $expressionAttribute,
 283+ $expressionSpellings[$record->getAttributeValue($expressionAttribute)]
 284+ );
 285+ }
 286+}
 287+
 288+function getTextReferences($textIds) {
 289+ if (count($textIds) > 0) {
 290+ $dbr =& wfGetDB(DB_SLAVE);
 291+ $queryResult = $dbr->query(
 292+ "SELECT old_id, old_text" .
 293+ " FROM text" .
 294+ " WHERE old_id IN (". implode(', ', $textIds) .")"
 295+ );
 296+
 297+ $result = array();
 298+
 299+ while ($row = $dbr->fetchObject($queryResult))
 300+ $result[$row->old_id] = $row->old_text;
 301+
 302+ return $result;
 303+ }
 304+ else
 305+ return array();
 306+}
 307+
 308+function expandTextReferencesInRecordSet($recordSet, $textAttributes) {
 309+ $textReferences = getTextReferences(getUniqueIdsInRecordSet($recordSet, $textAttributes));
 310+
 311+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 312+ $record = $recordSet->getRecord($i);
 313+
 314+ foreach($textAttributes as $textAttribute)
 315+ $record->setAttributeValue(
 316+ $textAttribute,
 317+ $textReferences[$record->getAttributeValue($textAttribute)]
 318+ );
 319+ }
 320+}
 321+
 322+function getExpressionMeaningsRecordSet($expressionId, $exactMeaning, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
 323+ global
 324+ $expressionMeaningStructure, $definedMeaningIdAttribute;
 325+
 326+ if ($exactMeaning)
 327+ $identicalMeaning = 1;
 328+ else
 329+ $identicalMeaning = 0;
 330+
 331+ $recordSet = new ArrayRecordSet($expressionMeaningStructure, new Structure($definedMeaningIdAttribute));
 332+
 333+ $dbr =& wfGetDB(DB_SLAVE);
 334+ $queryResult = $dbr->query("SELECT defined_meaning_id FROM uw_syntrans" .
 335+ " WHERE expression_id=$expressionId AND identical_meaning=" . $identicalMeaning .
 336+ " AND ". getLatestTransactionRestriction('uw_syntrans'));
 337+
 338+ while($definedMeaning = $dbr->fetchObject($queryResult)) {
 339+ $definedMeaningId = $definedMeaning->defined_meaning_id;
 340+ $recordSet->addRecord(
 341+ array(
 342+ $definedMeaningId,
 343+ getDefinedMeaningDefinition($definedMeaningId),
 344+ getDefinedMeaningRecord($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation)
 345+ )
 346+ );
 347+ }
 348+
 349+ return $recordSet;
 350+}
 351+
 352+function getExpressionMeaningsRecord($expressionId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
 353+ global
 354+ $expressionMeaningsStructure, $expressionExactMeaningsAttribute, $expressionApproximateMeaningsAttribute;
 355+
 356+ $record = new ArrayRecord($expressionMeaningsStructure);
 357+ $record->setAttributeValue($expressionExactMeaningsAttribute, getExpressionMeaningsRecordSet($expressionId, true, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
 358+ $record->setAttributeValue($expressionApproximateMeaningsAttribute, getExpressionMeaningsRecordSet($expressionId, false, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
 359+
 360+ return $record;
 361+}
 362+
 363+function getExpressionsRecordSet($spelling, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
 364+ global
 365+ $expressionIdAttribute, $expressionAttribute, $languageAttribute, $expressionMeaningsAttribute;
 366+
 367+ if ($filterLanguageId != 0)
 368+ $languageRestriction = " AND language_id=$filterLanguageId";
 369+ else
 370+ $languageRestriction = "";
 371+
 372+ $dbr =& wfGetDB(DB_SLAVE);
 373+ $queryResult = $dbr->query(
 374+ "SELECT expression_id, language_id " .
 375+ " FROM uw_expression_ns" .
 376+ " WHERE spelling=BINARY " . $dbr->addQuotes($spelling) .
 377+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 378+ $languageRestriction .
 379+ " AND EXISTS (" .
 380+ "SELECT expression_id " .
 381+ " FROM uw_syntrans " .
 382+ " WHERE uw_syntrans.expression_id=uw_expression_ns.expression_id" .
 383+ " AND ". getLatestTransactionRestriction('uw_syntrans')
 384+ .")"
 385+ );
 386+
 387+ $result = new ArrayRecordSet(new Structure($expressionIdAttribute, $expressionAttribute, $expressionMeaningsAttribute), new Structure($expressionIdAttribute));
 388+ $expressionStructure = new Structure($languageAttribute);
 389+
 390+ while($expression = $dbr->fetchObject($queryResult)) {
 391+ $expressionRecord = new ArrayRecord($expressionStructure);
 392+ $expressionRecord->setAttributeValue($languageAttribute, $expression->language_id);
 393+
 394+ $result->addRecord(array(
 395+ $expression->expression_id,
 396+ $expressionRecord,
 397+ getExpressionMeaningsRecord($expression->expression_id, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation)
 398+ ));
 399+ }
 400+
 401+ return $result;
 402+}
 403+
 404+function getExpressionIdThatHasSynonyms($spelling, $languageId) {
 405+ $dbr =& wfGetDB(DB_SLAVE);
 406+ $queryResult = $dbr->query(
 407+ "SELECT expression_id, language_id " .
 408+ " FROM uw_expression_ns" .
 409+ " WHERE spelling=BINARY " . $dbr->addQuotes($spelling) .
 410+ " AND " . getLatestTransactionRestriction('uw_expression_ns') .
 411+ " AND language_id=$languageId" .
 412+ " AND EXISTS (" .
 413+ "SELECT expression_id " .
 414+ " FROM uw_syntrans " .
 415+ " WHERE uw_syntrans.expression_id=uw_expression_ns.expression_id" .
 416+ " AND ". getLatestTransactionRestriction('uw_syntrans')
 417+ .")"
 418+ );
 419+
 420+ if ($expression = $dbr->fetchObject($queryResult))
 421+ return $expression->expression_id;
 422+ else
 423+ return 0;
 424+}
 425+
 426+function getDefinedMeaningRecord($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
 427+ global
 428+ $definedMeaningAttribute, $definitionAttribute, $classAttributesAttribute,
 429+ $alternativeDefinitionsAttribute, $synonymsAndTranslationsAttribute,
 430+ $relationsAttribute, $reciprocalRelationsAttribute,
 431+ $classMembershipAttribute, $collectionMembershipAttribute, $objectAttributesAttribute,
 432+ $possiblySynonymousAttribute;
 433+
 434+ $record = new ArrayRecord($definedMeaningAttribute->type->getStructure());
 435+ $record->setAttributeValue($definitionAttribute, getDefinedMeaningDefinitionRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
 436+ $record->setAttributeValue($classAttributesAttribute, getClassAttributesRecordSet($definedMeaningId, $queryTransactionInformation));
 437+ $record->setAttributeValue($alternativeDefinitionsAttribute, getAlternativeDefinitionsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
 438+ $record->setAttributeValue($synonymsAndTranslationsAttribute, getSynonymAndTranslationRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
 439+
 440+ $filterRelationTypes = array();
 441+
 442+ if ($possiblySynonymousRelationTypeId != 0) {
 443+ $record->setAttributeValue($possiblySynonymousAttribute, getPossiblySynonymousRecordSet($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation));
 444+ $filterRelationTypes[] = $possiblySynonymousRelationTypeId;
 445+ }
 446+
 447+ $record->setAttributeValue($relationsAttribute, getDefinedMeaningRelationsRecordSet($definedMeaningId, $filterLanguageId, $filterRelationTypes, $queryTransactionInformation));
 448+ $record->setAttributeValue($reciprocalRelationsAttribute, getDefinedMeaningReciprocalRelationsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
 449+ $record->setAttributeValue($classMembershipAttribute, getDefinedMeaningClassMembershipRecordSet($definedMeaningId, $queryTransactionInformation));
 450+ $record->setAttributeValue($collectionMembershipAttribute, getDefinedMeaningCollectionMembershipRecordSet($definedMeaningId, $queryTransactionInformation));
 451+ $record->setAttributeValue($objectAttributesAttribute, getObjectAttributesRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation));
 452+
 453+ return $record;
 454+}
 455+
 456+function getClassAttributesRecordSet($definedMeaningId, $queryTransactionInformation) {
 457+ global
 458+ $classAttributesTable, $classAttributeIdAttribute, $classAttributeLevelAttribute, $classAttributeAttributeAttribute, $classAttributeTypeAttribute, $optionAttributeOptionsAttribute;
 459+
 460+ $recordSet = queryRecordSet(
 461+ $queryTransactionInformation,
 462+ $classAttributeIdAttribute,
 463+ array(
 464+ 'object_id' => $classAttributeIdAttribute,
 465+ 'level_mid' => $classAttributeLevelAttribute,
 466+ 'attribute_mid' => $classAttributeAttributeAttribute,
 467+ 'attribute_type' => $classAttributeTypeAttribute
 468+ ),
 469+ $classAttributesTable,
 470+ array("class_mid=$definedMeaningId")
 471+ );
 472+
 473+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($classAttributeLevelAttribute ,$classAttributeAttributeAttribute));
 474+ expandOptionAttributeOptionsInRecordSet($recordSet, $classAttributeIdAttribute, $queryTransactionInformation);
 475+
 476+ return $recordSet;
 477+}
 478+
 479+function expandOptionAttributeOptionsInRecordSet($recordSet, $attributeIdAttribute, $queryTransactionInformation) {
 480+ global
 481+ $definedMeaningIdAttribute, $optionAttributeOptionsAttribute;
 482+
 483+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 484+ $record = $recordSet->getRecord($i);
 485+
 486+ $record->setAttributeValue($optionAttributeOptionsAttribute, getOptionAttributeOptionsRecordSet($record->getAttributeValue($attributeIdAttribute), $queryTransactionInformation));
 487+ }
 488+}
 489+
 490+function getAlternativeDefinitionsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
 491+ global
 492+ $alternativeDefinitionsTable, $definitionIdAttribute, $alternativeDefinitionAttribute, $sourceAttribute;
 493+
 494+ $recordSet = queryRecordSet(
 495+ $queryTransactionInformation,
 496+ $definitionIdAttribute,
 497+ array(
 498+ 'meaning_text_tcid' => $definitionIdAttribute,
 499+ 'source_id' => $sourceAttribute
 500+ ),
 501+ $alternativeDefinitionsTable,
 502+ array("meaning_mid=$definedMeaningId")
 503+ );
 504+
 505+ $recordSet->getStructure()->attributes[] = $alternativeDefinitionAttribute;
 506+
 507+ expandTranslatedContentsInRecordSet($recordSet, $definitionIdAttribute, $alternativeDefinitionAttribute, $filterLanguageId, $queryTransactionInformation);
 508+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($sourceAttribute));
 509+
 510+ return $recordSet;
 511+}
 512+
 513+function getDefinedMeaningDefinitionRecord($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
 514+ global
 515+ $definitionAttribute, $translatedTextAttribute, $objectAttributesAttribute;
 516+
 517+ $definitionId = getDefinedMeaningDefinitionId($definedMeaningId);
 518+ $record = new ArrayRecord($definitionAttribute->type->getStructure());
 519+ $record->setAttributeValue($translatedTextAttribute, getTranslatedContentValue($definitionId, $filterLanguageId, $queryTransactionInformation));
 520+ $record->setAttributeValue($objectAttributesAttribute, getObjectAttributesRecord($definitionId, $filterLanguageId, $queryTransactionInformation));
 521+
 522+ return $record;
 523+}
 524+
 525+function getObjectAttributesRecord($objectId, $filterLanguageId, $queryTransactionInformation) {
 526+ global
 527+ $objectAttributesAttribute, $objectIdAttribute,
 528+ $urlAttributeValuesAttribute, $textAttributeValuesAttribute,
 529+ $translatedTextAttributeValuesAttribute, $optionAttributeValuesAttribute;
 530+
 531+ $record = new ArrayRecord($objectAttributesAttribute->type->getStructure());
 532+
 533+ $record->setAttributeValue($objectIdAttribute, $objectId);
 534+ $record->setAttributeValue($textAttributeValuesAttribute, getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
 535+ $record->setAttributeValue($translatedTextAttributeValuesAttribute, getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
 536+ $record->setAttributeValue($urlAttributeValuesAttribute, getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
 537+ $record->setAttributeValue($optionAttributeValuesAttribute, getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation));
 538+
 539+ return $record;
 540+}
 541+
 542+function getTranslatedContentValue($translatedContentId, $filterLanguageId, $queryTransactionInformation) {
 543+ global
 544+ $textAttribute;
 545+
 546+ if ($filterLanguageId == 0)
 547+ return getTranslatedContentRecordSet($translatedContentId, $queryTransactionInformation);
 548+ else {
 549+ $recordSet = getFilteredTranslatedContentRecordSet($translatedContentId, $filterLanguageId, $queryTransactionInformation);
 550+
 551+ if (count($queryTransactionInformation->versioningAttributes()) > 0)
 552+ return $recordSet;
 553+ else {
 554+ if ($recordSet->getRecordCount() > 0)
 555+ return $recordSet->getRecord(0)->getAttributeValue($textAttribute);
 556+ else
 557+ return "";
 558+ }
 559+ }
 560+}
 561+
 562+function getTranslatedContentRecordSet($translatedContentId, $queryTransactionInformation) {
 563+ global
 564+ $translatedContentTable, $languageAttribute, $textAttribute;
 565+
 566+ $recordSet = queryRecordSet(
 567+ $queryTransactionInformation,
 568+ $languageAttribute,
 569+ array(
 570+ 'language_id' => $languageAttribute,
 571+ 'text_id' => $textAttribute
 572+ ),
 573+ $translatedContentTable,
 574+ array("translated_content_id=$translatedContentId")
 575+ );
 576+
 577+ expandTextReferencesInRecordSet($recordSet, array($textAttribute));
 578+
 579+ return $recordSet;
 580+}
 581+
 582+function getFilteredTranslatedContentRecordSet($translatedContentId, $filterLanguageId, $queryTransactionInformation) {
 583+ global
 584+ $translatedContentTable, $languageAttribute, $textAttribute;
 585+
 586+ $recordSet = queryRecordSet(
 587+ $queryTransactionInformation,
 588+ $languageAttribute,
 589+ array(
 590+ 'language_id' => $languageAttribute,
 591+ 'text_id' => $textAttribute
 592+ ),
 593+ $translatedContentTable,
 594+ array(
 595+ "translated_content_id=$translatedContentId",
 596+ "language_id=$filterLanguageId"
 597+ )
 598+ );
 599+
 600+ expandTextReferencesInRecordSet($recordSet, array($textAttribute));
 601+
 602+ return $recordSet;
 603+}
 604+
 605+function getSynonymAndTranslationRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
 606+ global
 607+ $syntransTable, $syntransIdAttribute, $expressionAttribute, $identicalMeaningAttribute, $objectAttributesAttribute;
 608+
 609+ $restrictions = array("defined_meaning_id=$definedMeaningId");
 610+
 611+ if ($filterLanguageId != 0)
 612+ $restrictions[] =
 613+ "expression_id IN (" .
 614+ "SELECT expressions.expression_id" .
 615+ " FROM uw_expression_ns AS expressions" .
 616+ " WHERE expressions.expression_id=expression_id" .
 617+ " AND language_id=$filterLanguageId" .
 618+ " AND " . getLatestTransactionRestriction('expressions') .
 619+ ")";
 620+
 621+ $recordSet = queryRecordSet(
 622+ $queryTransactionInformation,
 623+ $syntransIdAttribute,
 624+ array(
 625+ 'syntrans_sid' => $syntransIdAttribute,
 626+ 'expression_id' => $expressionAttribute,
 627+ 'identical_meaning' => $identicalMeaningAttribute
 628+ ),
 629+ $syntransTable,
 630+ $restrictions
 631+ );
 632+
 633+ if ($filterLanguageId == 0)
 634+ expandExpressionReferencesInRecordSet($recordSet, array($expressionAttribute));
 635+ else
 636+ expandExpressionSpellingsInRecordSet($recordSet, array($expressionAttribute));
 637+
 638+ //add object attributes attribute to the generated structure
 639+ //and expand the records
 640+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 641+ expandObjectAttributesAttribute($recordSet, $syntransIdAttribute, $filterLanguageId, $queryTransactionInformation);
 642+ return $recordSet;
 643+}
 644+
 645+function expandObjectAttributesAttribute($recordSet, $objectIdAttribute, $filterLanguageId, $queryTransactionInformation) {
 646+ global
 647+ $objectAttributesAttribute;
 648+
 649+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 650+ $record = $recordSet->getRecord($i);
 651+ $record->setAttributeValue(
 652+ $objectAttributesAttribute,
 653+ getObjectAttributesRecord(
 654+ $record->getAttributeValue($objectIdAttribute),
 655+ $filterLanguageId,
 656+ $queryTransactionInformation
 657+ )
 658+ );
 659+ }
 660+}
 661+
 662+function getDefinedMeaningReferenceRecord($definedMeaningId) {
 663+ global
 664+ $definedMeaningReferenceStructure, $definedMeaningIdAttribute, $definedMeaningLabelAttribute,
 665+ $definedMeaningDefiningExpressionAttribute;
 666+
 667+ $record = new ArrayRecord($definedMeaningReferenceStructure);
 668+ $record->setAttributeValue($definedMeaningIdAttribute, $definedMeaningId);
 669+ $record->setAttributeValue($definedMeaningLabelAttribute, definedMeaningExpression($definedMeaningId));
 670+ $record->setAttributeValue($definedMeaningDefiningExpressionAttribute, definingExpression($definedMeaningId));
 671+
 672+ return $record;
 673+}
 674+
 675+function getDefinedMeaningRelationsRecordSet($definedMeaningId, $filterLanguageId, $filterRelationTypes, $queryTransactionInformation) {
 676+ global
 677+ $meaningRelationsTable, $relationIdAttribute, $relationTypeAttribute,
 678+ $objectAttributesAttribute, $otherDefinedMeaningAttribute;
 679+
 680+ $restrictions = array("meaning1_mid=$definedMeaningId");
 681+
 682+ if (count($filterRelationTypes) > 0)
 683+ $restrictions[] = "relationtype_mid NOT IN (". implode(", ", $filterRelationTypes) .")";
 684+
 685+ $recordSet = queryRecordSet(
 686+ $queryTransactionInformation,
 687+ $relationIdAttribute,
 688+ array(
 689+ 'relation_id' => $relationIdAttribute,
 690+ 'relationtype_mid' => $relationTypeAttribute,
 691+ 'meaning2_mid' => $otherDefinedMeaningAttribute
 692+ ),
 693+ $meaningRelationsTable,
 694+ $restrictions,
 695+ array('add_transaction_id')
 696+ );
 697+
 698+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
 699+
 700+ //add object attributes attribute to the generated structure
 701+ //and expand the records
 702+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 703+ expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $filterLanguageId, $queryTransactionInformation);
 704+
 705+ return $recordSet;
 706+}
 707+
 708+function getDefinedMeaningReciprocalRelationsRecordSet($definedMeaningId, $filterLanguageId, $queryTransactionInformation) {
 709+ global
 710+ $meaningRelationsTable, $relationIdAttribute, $relationTypeAttribute,
 711+ $otherDefinedMeaningAttribute, $objectAttributesAttribute;
 712+
 713+ $recordSet = queryRecordSet(
 714+ $queryTransactionInformation,
 715+ $relationIdAttribute,
 716+ array(
 717+ 'relation_id' => $relationIdAttribute,
 718+ 'relationtype_mid' => $relationTypeAttribute,
 719+ 'meaning1_mid' => $otherDefinedMeaningAttribute
 720+ ),
 721+ $meaningRelationsTable,
 722+ array("meaning2_mid=$definedMeaningId"),
 723+ array('relationtype_mid')
 724+ );
 725+
 726+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($relationTypeAttribute, $otherDefinedMeaningAttribute));
 727+
 728+ //add object attributes attribute to the generated structure
 729+ //and expand the records
 730+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 731+ expandObjectAttributesAttribute($recordSet, $relationIdAttribute, $filterLanguageId, $queryTransactionInformation);
 732+
 733+ return $recordSet;
 734+}
 735+
 736+function getPossiblySynonymousRecordSet($definedMeaningId, $filterLanguageId, $possiblySynonymousRelationTypeId, $queryTransactionInformation) {
 737+ global
 738+ $meaningRelationsTable, $possiblySynonymousIdAttribute, $possibleSynonymAttribute,
 739+ $objectAttributesAttribute, $otherDefinedMeaningAttribute;
 740+
 741+ $recordSet = queryRecordSet(
 742+ $queryTransactionInformation,
 743+ $possiblySynonymousIdAttribute,
 744+ array(
 745+ 'relation_id' => $possiblySynonymousIdAttribute,
 746+ 'meaning2_mid' => $possibleSynonymAttribute
 747+ ),
 748+ $meaningRelationsTable,
 749+ array(
 750+ "meaning1_mid=$definedMeaningId",
 751+ "relationtype_mid=" . $possiblySynonymousRelationTypeId
 752+ ),
 753+ array('add_transaction_id')
 754+ );
 755+
 756+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($possibleSynonymAttribute));
 757+
 758+ //add object attributes attribute to the generated structure
 759+ //and expand the records
 760+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 761+ expandObjectAttributesAttribute($recordSet, $possiblySynonymousIdAttribute, $filterLanguageId, $queryTransactionInformation);
 762+
 763+ return $recordSet;
 764+}
 765+
 766+function getDefinedMeaningCollectionMembershipRecordSet($definedMeaningId, $queryTransactionInformation) {
 767+ global
 768+ $collectionMembershipsTable, $collectionIdAttribute, $collectionMeaningAttribute, $sourceIdentifierAttribute;
 769+
 770+ $recordSet = queryRecordSet(
 771+ $queryTransactionInformation,
 772+ $collectionIdAttribute,
 773+ array(
 774+ 'collection_id' => $collectionIdAttribute,
 775+ 'internal_member_id' => $sourceIdentifierAttribute
 776+ ),
 777+ $collectionMembershipsTable,
 778+ array("member_mid=$definedMeaningId")
 779+ );
 780+
 781+ $recordSet->getStructure()->atttributes[] = $collectionMeaningAttribute;
 782+
 783+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 784+ $record = $recordSet->getRecord($i);
 785+ $record->setAttributeValue($collectionMeaningAttribute, getCollectionMeaningId($record->getAttributeValue($collectionIdAttribute)));
 786+ }
 787+
 788+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($collectionMeaningAttribute));
 789+
 790+ return $recordSet;
 791+}
 792+
 793+function getTextAttributesValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
 794+ global
 795+ $textAttributeValuesTable, $textAttributeIdAttribute, $textAttributeObjectAttribute,
 796+ $textAttributeAttribute, $textAttribute, $objectAttributesAttribute;
 797+
 798+ $recordSet = queryRecordSet(
 799+ $queryTransactionInformation,
 800+ $textAttributeIdAttribute,
 801+ array(
 802+ 'value_id' => $textAttributeIdAttribute,
 803+ 'object_id' => $textAttributeObjectAttribute,
 804+ 'attribute_mid' => $textAttributeAttribute,
 805+ 'text' => $textAttribute
 806+ ),
 807+ $textAttributeValuesTable,
 808+ array("object_id=$objectId")
 809+ );
 810+
 811+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($textAttributeAttribute));
 812+
 813+ //add object attributes attribute to the generated structure
 814+ //and expand the records
 815+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 816+ expandObjectAttributesAttribute($recordSet, $textAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
 817+
 818+ return $recordSet;
 819+}
 820+
 821+function getURLAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
 822+ global
 823+ $urlAttributeValuesTable, $urlAttributeIdAttribute, $urlAttributeObjectAttribute,
 824+ $urlAttributeAttribute, $urlAttribute, $objectAttributesAttribute;
 825+
 826+ $recordSet = queryRecordSet(
 827+ $queryTransactionInformation,
 828+ $urlAttributeIdAttribute,
 829+ array(
 830+ 'value_id' => $urlAttributeIdAttribute,
 831+ 'object_id' => $urlAttributeObjectAttribute,
 832+ 'attribute_mid' => $urlAttributeAttribute,
 833+ 'url' => $urlAttribute
 834+ ),
 835+ $urlAttributeValuesTable,
 836+ array("object_id=$objectId")
 837+ );
 838+
 839+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($urlAttributeAttribute));
 840+
 841+ //add object attributes attribute to the generated structure
 842+ //and expand the records
 843+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 844+ expandObjectAttributesAttribute($recordSet, $urlAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
 845+
 846+ return $recordSet;
 847+}
 848+
 849+function getTranslatedTextAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
 850+ global
 851+ $translatedTextAttributeIdAttribute, $translatedContentAttributeValuesTable, $translatedTextAttributeAttribute,
 852+ $objectAttributesAttribute, $translatedTextValueAttribute, $translatedTextValueIdAttribute;
 853+
 854+ $recordSet = queryRecordSet(
 855+ $queryTransactionInformation,
 856+ $translatedTextAttributeIdAttribute,
 857+ array(
 858+ 'value_id' => $translatedTextAttributeIdAttribute,
 859+ 'attribute_mid' => $translatedTextAttributeAttribute,
 860+ 'value_tcid' => $translatedTextValueIdAttribute
 861+ ),
 862+ $translatedContentAttributeValuesTable,
 863+ array("object_id=$objectId")
 864+ );
 865+
 866+ $recordSet->getStructure()->attributes[] = $translatedTextValueAttribute;
 867+
 868+ expandTranslatedContentsInRecordSet($recordSet, $translatedTextValueIdAttribute, $translatedTextValueAttribute, $filterLanguageId, $queryTransactionInformation);
 869+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($translatedTextAttributeAttribute));
 870+
 871+ //add object attributes attribute to the generated structure
 872+ //and expand the records
 873+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 874+ expandObjectAttributesAttribute($recordSet, $translatedTextAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
 875+ return $recordSet;
 876+}
 877+
 878+function getOptionAttributeOptionsRecordSet($attributeId, $queryTransactionInformation) {
 879+ global
 880+ $optionAttributeOptionIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $languageAttribute, $optionAttributeOptionsTable;
 881+
 882+ $recordSet = queryRecordSet(
 883+ $queryTransactionInformation,
 884+ $optionAttributeOptionIdAttribute,
 885+ array(
 886+ 'option_id' => $optionAttributeOptionIdAttribute,
 887+ 'attribute_id' => $optionAttributeAttribute,
 888+ 'option_mid' => $optionAttributeOptionAttribute,
 889+ 'language_id' => $languageAttribute
 890+ ),
 891+ $optionAttributeOptionsTable,
 892+ array('attribute_id = ' . $attributeId)
 893+ );
 894+
 895+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($optionAttributeOptionAttribute));
 896+
 897+ return $recordSet;
 898+}
 899+
 900+function getOptionAttributeValuesRecordSet($objectId, $filterLanguageId, $queryTransactionInformation) {
 901+ global
 902+ $optionAttributeIdAttribute, $optionAttributeObjectAttribute, $optionAttributeOptionIdAttribute, $optionAttributeAttribute,$optionAttributeOptionAttribute, $optionAttributeValuesTable, $objectAttributesAttribute;
 903+
 904+ $recordSet = queryRecordSet(
 905+ $queryTransactionInformation,
 906+ $optionAttributeIdAttribute,
 907+ array(
 908+ 'value_id' => $optionAttributeIdAttribute,
 909+ 'object_id' => $optionAttributeObjectAttribute,
 910+ 'option_id' => $optionAttributeOptionIdAttribute
 911+ ),
 912+ $optionAttributeValuesTable,
 913+ array('object_id = ' . $objectId)
 914+ );
 915+
 916+ expandOptionsInRecordSet($recordSet, $queryTransactionInformation);
 917+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($optionAttributeAttribute, $optionAttributeOptionAttribute));
 918+
 919+ /* Add object attributes attribute to the generated structure
 920+ and expand the records. */
 921+ $recordSet->getStructure()->attributes[] = $objectAttributesAttribute;
 922+ expandObjectAttributesAttribute($recordSet, $optionAttributeIdAttribute, $filterLanguageId, $queryTransactionInformation);
 923+
 924+ return $recordSet;
 925+}
 926+
 927+/* XXX: This can probably be combined with other functions. In fact, it probably should be. Do it. */
 928+function expandOptionsInRecordSet($recordSet, $queryTransactionInformation) {
 929+ global
 930+ $optionAttributeOptionIdAttribute, $optionAttributeIdAttribute, $optionAttributeAttribute, $optionAttributeOptionAttribute, $optionAttributeOptionsTable, $classAttributesTable;
 931+
 932+ for ($i = 0; $i < $recordSet->getRecordCount(); $i++) {
 933+ $record = $recordSet->getRecord($i);
 934+
 935+ $optionRecordSet = queryRecordSet(
 936+ $queryTransactionInformation,
 937+ $optionAttributeOptionIdAttribute,
 938+ array(
 939+ 'attribute_id' => $optionAttributeIdAttribute,
 940+ 'option_mid' => $optionAttributeOptionAttribute
 941+ ),
 942+ $optionAttributeOptionsTable,
 943+ array('option_id = ' . $record->getAttributeValue($optionAttributeOptionIdAttribute))
 944+ );
 945+
 946+ $optionRecord = $optionRecordSet->getRecord(0);
 947+ $record->setAttributeValue(
 948+ $optionAttributeOptionAttribute,
 949+ $optionRecord->getAttributeValue($optionAttributeOptionAttribute)
 950+ );
 951+
 952+ $optionRecordSet = queryRecordSet(
 953+ $queryTransactionInformation,
 954+ $optionAttributeIdAttribute,
 955+ array('attribute_mid' => $optionAttributeAttribute),
 956+ $classAttributesTable,
 957+ array('object_id = ' . $optionRecord->getAttributeValue($optionAttributeIdAttribute))
 958+ );
 959+
 960+ $optionRecord = $optionRecordSet->getRecord(0);
 961+ $record->setAttributeValue(
 962+ $optionAttributeAttribute,
 963+ $optionRecord->getAttributeValue($optionAttributeAttribute)
 964+ );
 965+ }
 966+}
 967+
 968+function getDefinedMeaningClassMembershipRecordSet($definedMeaningId, $queryTransactionInformation) {
 969+ global
 970+ $classMembershipsTable, $classMembershipIdAttribute, $classAttribute;
 971+
 972+ $recordSet = queryRecordSet(
 973+ $queryTransactionInformation,
 974+ $classMembershipIdAttribute,
 975+ array(
 976+ 'class_membership_id' => $classMembershipIdAttribute,
 977+ 'class_mid' => $classAttribute
 978+ ),
 979+ $classMembershipsTable,
 980+ array("class_member_mid=$definedMeaningId")
 981+ );
 982+
 983+ expandDefinedMeaningReferencesInRecordSet($recordSet, array($classAttribute));
 984+
 985+ return $recordSet;
 986+}
 987+
 988+?>
Property changes on: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiRecordSets.php
___________________________________________________________________
Added: svn:eol-style
1989 + native
Index: trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php
@@ -0,0 +1,123 @@
 2+<?php
 3+
 4+require_once('Wikidata.php');
 5+require_once('Transaction.php');
 6+require_once('Expression.php');
 7+require_once('forms.php');
 8+require_once('Attribute.php');
 9+require_once('type.php');
 10+require_once('languages.php');
 11+require_once('HTMLtable.php');
 12+require_once('OmegaWikiRecordSets.php');
 13+require_once('OmegaWikiEditors.php');
 14+
 15+/**
 16+ * Load and modify content in a OmegaWiki-enabled
 17+ * namespace.
 18+ *
 19+ */
 20+class OmegaWiki extends DefaultWikidataApplication {
 21+ public function view() {
 22+ global
 23+ $wgOut, $wgTitle;
 24+
 25+ parent::view();
 26+
 27+ $spelling = $wgTitle->getText();
 28+
 29+ $wgOut->addHTML(
 30+ getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, $this->shouldShowAuthorities)->view(
 31+ $this->getIdStack(),
 32+ getExpressionsRecordSet(
 33+ $spelling,
 34+ $this->filterLanguageId,
 35+ $this->possiblySynonymousRelationTypeId,
 36+ $this->viewQueryTransactionInformation
 37+ )
 38+ )
 39+ );
 40+
 41+ $wgOut->addHTML(DefaultEditor::getExpansionCss());
 42+ $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
 43+ }
 44+
 45+ public function history() {
 46+ global
 47+ $wgOut, $wgTitle;
 48+
 49+ parent::history();
 50+
 51+ $spelling = $wgTitle->getText();
 52+
 53+ $wgOut->addHTML(
 54+ getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, $this->showRecordLifeSpan, false)->view(
 55+ $this->getIdStack(),
 56+ getExpressionsRecordSet(
 57+ $spelling,
 58+ $this->filterLanguageId,
 59+ $this->possiblySynonymousRelationTypeId,
 60+ $this->queryTransactionInformation
 61+ )
 62+ )
 63+ );
 64+
 65+ $wgOut->addHTML(DefaultEditor::getExpansionCss());
 66+ $wgOut->addHTML("<script language='javascript'><!--\nexpandEditors();\n--></script>");
 67+ }
 68+
 69+ protected function save($referenceTransaction) {
 70+ global
 71+ $wgTitle;
 72+
 73+ parent::save($referenceTransaction);
 74+
 75+ $spelling = $wgTitle->getText();
 76+
 77+ getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, false)->save(
 78+ $this->getIdStack(),
 79+ getExpressionsRecordSet(
 80+ $spelling,
 81+ $this->filterLanguageId,
 82+ $this->possiblySynonymousRelationTypeId,
 83+ $referenceTransaction
 84+ )
 85+ );
 86+ }
 87+
 88+ public function edit() {
 89+ global
 90+ $wgOut, $wgTitle, $wgUser;
 91+
 92+ parent::edit();
 93+ $this->outputEditHeader();
 94+
 95+ $spelling = $wgTitle->getText();
 96+
 97+ $wgOut->addHTML(
 98+ getExpressionsEditor($spelling, $this->filterLanguageId, $this->possiblySynonymousRelationTypeId, false, false)->edit(
 99+ $this->getIdStack(),
 100+ getExpressionsRecordSet(
 101+ $spelling,
 102+ $this->filterLanguageId,
 103+ $this->possiblySynonymousRelationTypeId,
 104+ new QueryLatestTransactionInformation()
 105+ )
 106+ )
 107+ );
 108+
 109+ $this->outputEditFooter();
 110+ }
 111+
 112+ public function getTitle() {
 113+ global
 114+ $wgTitle;
 115+
 116+ return "Disambiguation: " . $wgTitle->getText();
 117+ }
 118+
 119+ protected function getIdStack() {
 120+ return new IdStack("expression");
 121+ }
 122+}
 123+
 124+?>
Property changes on: trunk/extensions/Wikidata/OmegaWiki/OmegaWiki.php
___________________________________________________________________
Added: svn:eol-style
1125 + native