Index: trunk/extensions/Wikidata/WP/UMLSImport.php |
— | — | @@ -162,7 +162,8 @@ |
163 | 163 | |
164 | 164 | while ($umlsTerm = mysql_fetch_object($queryResult)) { |
165 | 165 | $definedMeaningId = getDefinedMeaningFromCollection($umlsCollectionId, $umlsTerm->cui); |
166 | | - $expression = findOrCreateExpression(trim($umlsTerm->str), $isoLanguages[strtolower($umlsTerm->lat)]); |
| 166 | + $string = str_replace('_', ' ', trim($umlsTerm->str)); |
| 167 | + $expression = findOrCreateExpression($string, $isoLanguages[strtolower($umlsTerm->lat)]); |
167 | 168 | |
168 | 169 | if(!$definedMeaningId) { |
169 | 170 | $definedMeaningId = addDefinedMeaning($expression->id); |
Index: trunk/extensions/Wikidata/WP/DataImport.php |
— | — | @@ -26,28 +26,30 @@ |
27 | 27 | //$nlmUserID = 1; |
28 | 28 | //$sibUserID = 1; |
29 | 29 | |
30 | | -$linkEC2GoFileName = "LinksEC2Go.txt"; |
31 | | -$linkSwissProtKeyWord2GoFileName = "LinksSP2Go.txt"; |
32 | | -$swissProtXMLFileName = "uniprot_sprot.xml"; |
33 | | -//$swissProtXMLFileName = "100000lines.xml"; |
| 30 | +//$linkEC2GoFileName = "LinksEC2Go.txt"; |
| 31 | +//$linkSwissProtKeyWord2GoFileName = "LinksSP2Go.txt"; |
| 32 | +//$swissProtXMLFileName = "uniprot_sprot.xml"; |
| 33 | +$swissProtXMLFileName = "100000lines.xml"; |
34 | 34 | |
35 | 35 | $wgUser->setID($nlmUserID); |
36 | 36 | startNewTransaction($nlmUserID, 0, "UMLS Import"); |
37 | 37 | echo "Importing UMLS\n"; |
38 | | -$umlsImport = importUMLSFromDatabase("localhost", "umls", "root", "nicheGod");//, array("NCI", "GO")); |
39 | | -//$umlsImport = importUMLSFromDatabase("localhost", "umls", "root", NULL, array("NCI", "GO", "SRC")); |
| 38 | +//$umlsImport = importUMLSFromDatabase("localhost", "umls", "root", "nicheGod");//, array("NCI", "GO")); |
| 39 | +$umlsImport = importUMLSFromDatabase("localhost", "umls", "root", "nicheGod", array("GO", "SRC", "NCI", "HUGO")); |
| 40 | +//$umlsImport = importUMLSFromDatabase("localhost", "umls", "root", NULL, array("GO", "SRC", "NCI", "HUGO")); |
40 | 41 | |
41 | | -$EC2GoMapping = loadEC2GoMapping($linkEC2GoFileName); |
42 | | -$SP2GoMapping = loadSwissProtKeyWord2GoMapping($linkSwissProtKeyWord2GoFileName); |
| 42 | +//$EC2GoMapping = loadEC2GoMapping($linkEC2GoFileName); |
| 43 | +//$SP2GoMapping = loadSwissProtKeyWord2GoMapping($linkSwissProtKeyWord2GoFileName); |
43 | 44 | |
44 | 45 | $wgUser->setID($sibUserID); |
45 | 46 | startNewTransaction($sibUserID, 0, "Swiss-Prot Import"); |
46 | 47 | echo "\nImporting Swiss-Prot\n"; |
47 | 48 | //$umlsImport = new UMLSImportResult; |
48 | 49 | //$umlsImport->umlsCollectionId = 5; |
49 | | -//$umlsImport->sourceAbbreviations['GO'] = 236810; |
| 50 | +//$umlsImport->sourceAbbreviations['GO'] = 30; |
| 51 | +//$umlsImport->sourceAbbreviations['HUGO'] = 69912; |
50 | 52 | |
51 | | -importSwissProt($swissProtXMLFileName, $umlsImport->umlsCollectionId, $umlsImport->sourceAbbreviations['GO'], $EC2GoMapping, $SP2GoMapping); |
| 53 | +importSwissProt($swissProtXMLFileName, $umlsImport->umlsCollectionId, $umlsImport->sourceAbbreviations['GO'], $umlsImport->sourceAbbreviations['HUGO'], $EC2GoMapping, $SP2GoMapping); |
52 | 54 | //importSwissProt($swissProtXMLFileName); |
53 | 55 | |
54 | 56 | $endTime = time(); |
Index: trunk/extensions/Wikidata/WP/SwissProtImport.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | /* |
9 | 9 | * Import Swiss-Prot from the XML file. Be sure to have started a transaction first! |
10 | 10 | */ |
11 | | -function importSwissProt($xmlFileName, $umlsCollectionId = 0, $goCollectionId = 0, $EC2GoMapping = array(), $keyword2GoMapping = array()) { |
| 11 | +function importSwissProt($xmlFileName, $umlsCollectionId = 0, $goCollectionId = 0, $hugoCollectionId = 0, $EC2GoMapping = array(), $keyword2GoMapping = array()) { |
12 | 12 | // Create mappings from EC numbers and SwissProt keywords to GO term meaning id's: |
13 | 13 | $EC2GoMeaningId = array(); |
14 | 14 | $keyword2GoMeaningId = array(); |
— | — | @@ -15,31 +15,35 @@ |
16 | 16 | if ($goCollectionId != 0) { |
17 | 17 | $goCollection = getCollectionContents($goCollectionId); |
18 | 18 | |
19 | | - foreach ($EC2GoMapping as $EC => $GO) { |
20 | | - if (array_key_exists($GO, $goCollection)) { |
21 | | - $goMeaningId = $goCollection[$GO]; |
22 | | - $EC2GoMeaningId[$EC] = $goMeaningId; |
23 | | - } |
24 | | - } |
| 19 | +// foreach ($EC2GoMapping as $EC => $GO) { |
| 20 | +// if (array_key_exists($GO, $goCollection)) { |
| 21 | +// $goMeaningId = $goCollection[$GO]; |
| 22 | +// $EC2GoMeaningId[$EC] = $goMeaningId; |
| 23 | +// } |
| 24 | +// } |
| 25 | +// |
| 26 | +// foreach ($keyword2GoMapping as $keyword => $GO) { |
| 27 | +// if (array_key_exists($GO, $goCollection)) { |
| 28 | +// $goMeaningId = $goCollection[$GO]; |
| 29 | +// $keyword2GoMeaningId[$keyword] = $goMeaningId; |
| 30 | +// } |
| 31 | +// } |
| 32 | + } |
25 | 33 | |
26 | | - foreach ($keyword2GoMapping as $keyword => $GO) { |
27 | | - if (array_key_exists($GO, $goCollection)) { |
28 | | - $goMeaningId = $goCollection[$GO]; |
29 | | - $keyword2GoMeaningId[$keyword] = $goMeaningId; |
30 | | - } |
31 | | - } |
| 34 | + if($hugoCollectionId != 0) { |
| 35 | + $hugoCollection = getCollectionContents($hugoCollectionId); |
32 | 36 | } |
33 | 37 | |
34 | 38 | // SwissProt import: |
35 | 39 | $numberOfBytes = filesize($xmlFileName); |
36 | 40 | initializeProgressBar($numberOfBytes, 5000000); |
37 | 41 | $fileHandle = fopen($xmlFileName, "r"); |
38 | | - importEntriesFromXMLFile($fileHandle, $umlsCollectionId, $EC2GoMeaningId, $keyword2GoMeaningId); |
| 42 | + importEntriesFromXMLFile($fileHandle, $umlsCollectionId, $goCollection, $hugoCollection, $EC2GoMeaningId, $keyword2GoMeaningId); |
39 | 43 | |
40 | 44 | fclose($fileHandle); |
41 | 45 | } |
42 | 46 | |
43 | | -function importEntriesFromXMLFile($fileHandle, $umlsCollectionId, $EC2GoMeaningIdMapping, $keyword2GoMeaningIdMapping) { |
| 47 | +function importEntriesFromXMLFile($fileHandle, $umlsCollectionId, $goCollection, $hugoCollection, $EC2GoMeaningIdMapping, $keyword2GoMeaningIdMapping) { |
44 | 48 | $languageId = 85; |
45 | 49 | $collectionId = bootstrapCollection("Swiss-Prot", $languageId, ""); |
46 | 50 | $classCollectionId = bootstrapCollection("Swiss-Prot classes", $languageId, "CLAS"); |
— | — | @@ -56,6 +60,8 @@ |
57 | 61 | $xmlParser->ECCollectionId = $ECCollectionId; |
58 | 62 | $xmlParser->EC2GoMeaningIdMapping = $EC2GoMeaningIdMapping; |
59 | 63 | $xmlParser->keyword2GoMeaningIdMapping = $keyword2GoMeaningIdMapping; |
| 64 | + $xmlParser->goCollection = $goCollection; |
| 65 | + $xmlParser->hugoCollection = $hugoCollection; |
60 | 66 | |
61 | 67 | // Find some UMLS concepts for cross references from SwissProt: |
62 | 68 | if ($umlsCollectionId != 0) { |
— | — | @@ -65,6 +71,12 @@ |
66 | 72 | $xmlParser->proteinFragmentConceptId = getCollectionMemberId($umlsCollectionId, "C1335533"); |
67 | 73 | } |
68 | 74 | |
| 75 | + if ($goCollection) { |
| 76 | + $xmlParser->molecularFunctionConceptId = $goCollection["GO:0003674"]; |
| 77 | + $xmlParser->biologicalProcessConceptId = $goCollection["GO:0008150"]; |
| 78 | + $xmlParser->cellularComponentConceptId = $goCollection["GO:0005575"]; |
| 79 | + } |
| 80 | + |
69 | 81 | $xmlParser->initialize(); |
70 | 82 | |
71 | 83 | parseXML($fileHandle, $xmlParser); |
— | — | @@ -79,6 +91,8 @@ |
80 | 92 | public $ECCollectionId; |
81 | 93 | public $EC2GoMeaningIdMapping; |
82 | 94 | public $keyword2GoMeaningIdMapping; |
| 95 | + public $goCollection; |
| 96 | + public $hugoCollection; |
83 | 97 | public $numberOfEntries = 0; |
84 | 98 | |
85 | 99 | public $proteins = array(); |
— | — | @@ -100,6 +114,9 @@ |
101 | 115 | public $functionalDomainConceptId = 0; |
102 | 116 | public $proteinComponentConceptId = 0; |
103 | 117 | public $referencedByConceptId = 0; |
| 118 | + public $biologicalProcessConceptId = 0; |
| 119 | + public $molecularFunctionConceptId = 0; |
| 120 | + public $cellularComponentConceptId = 0; |
104 | 121 | public $keywordConceptId = 0; |
105 | 122 | public $includesConceptId = 0; |
106 | 123 | public $includedInConceptId = 0; |
— | — | @@ -144,6 +161,15 @@ |
145 | 162 | if ($this->referencedByConceptId == 0) |
146 | 163 | $this->referencedByConceptId = $this->bootstrapDefinedMeaning("referenced by", "referenced by"); |
147 | 164 | |
| 165 | + if ($this->biologicalProcessConceptId == 0) |
| 166 | + $this->biologicalProcessConceptId = $this->bootstrapDefinedMeaning("biological process", "biological process"); |
| 167 | + |
| 168 | + if ($this->molecularFunctionConceptId == 0) |
| 169 | + $this->molecularFunctionConceptId = $this->bootstrapDefinedMeaning("molecular function", "molecular function"); |
| 170 | + |
| 171 | + if ($this->cellularComponentConceptId == 0) |
| 172 | + $this->cellularComponentConceptId = $this->bootstrapDefinedMeaning("cellular component", "cellular component"); |
| 173 | + |
148 | 174 | if ($this->keywordConceptId == 0) |
149 | 175 | $this->keywordConceptId = $this->bootstrapDefinedMeaning("keyword", "keyword"); |
150 | 176 | |
— | — | @@ -191,6 +217,9 @@ |
192 | 218 | addDefinedMeaningToCollectionIfNotPresent($this->organismSpecificGeneConceptId, $this->relationTypeCollectionId, "organism specific gene"); |
193 | 219 | addDefinedMeaningToCollectionIfNotPresent($this->organismConceptId, $this->relationTypeCollectionId, "organism"); |
194 | 220 | addDefinedMeaningToCollectionIfNotPresent($this->activityConceptId, $this->relationTypeCollectionId, "activity"); |
| 221 | + addDefinedMeaningToCollectionIfNotPresent($this->biologicalProcessConceptId, $this->relationTypeCollectionId, "biological process"); |
| 222 | + addDefinedMeaningToCollectionIfNotPresent($this->molecularFunctionConceptId, $this->relationTypeCollectionId, "molecular function"); |
| 223 | + addDefinedMeaningToCollectionIfNotPresent($this->cellularComponentConceptId, $this->relationTypeCollectionId, "cellular component"); |
195 | 224 | addDefinedMeaningToCollectionIfNotPresent($this->keywordConceptId, $this->relationTypeCollectionId, "keyword"); |
196 | 225 | addDefinedMeaningToCollectionIfNotPresent($this->includesConceptId, $this->relationTypeCollectionId, "includes"); |
197 | 226 | addDefinedMeaningToCollectionIfNotPresent($this->includedInConceptId, $this->relationTypeCollectionId, "included in"); |
— | — | @@ -226,7 +255,7 @@ |
227 | 256 | |
228 | 257 | if ($entry->gene != "") { |
229 | 258 | $geneMeaningId = $this->addGene($entry->gene); |
230 | | - $organismSpecificGene = $this->addOrgansimSpecificGene($organismSpeciesMeaningId, $geneMeaningId, $entry->organism, $entry->gene, $entry->geneSynonyms); |
| 259 | + $organismSpecificGene = $this->addOrgansimSpecificGene($organismSpeciesMeaningId, $geneMeaningId, $entry->organism, $entry->gene, $entry->geneSynonyms, $entry->HGNCReference); |
231 | 260 | } |
232 | 261 | else |
233 | 262 | $organismSpecificGene = -1; |
— | — | @@ -318,32 +347,36 @@ |
319 | 348 | return $definedMeaningId; |
320 | 349 | } |
321 | 350 | |
322 | | - public function addOrgansimSpecificGene($organismSpeciesMeaningId, $geneMeaningId, $organismName, $geneName, $synonyms) { |
| 351 | + public function addOrgansimSpecificGene($organismSpeciesMeaningId, $geneMeaningId, $organismName, $geneName, $synonyms, $hgncReference) { |
323 | 352 | $key = $geneMeaningId . "-" . $organismSpeciesMeaningId; |
324 | 353 | $description = $geneName . " in " . $organismName; |
325 | 354 | if (array_key_exists($key, $this->organismSpecificGenes)) { |
326 | 355 | $definedMeaningId = $this->organismSpecificGenes[$key]; |
327 | 356 | } |
328 | 357 | else { |
329 | | - $definedMeaningId = $this->addExpressionAsDefinedMeaning($description, $description, $geneName, $this->collectionId); |
| 358 | + if(!($this->hugoCollection && ($hgncReference != 0) && ($definedMeaningId = $this->hugoCollection[$hgncReference]))){ |
| 359 | + $definedMeaningId = $this->addExpressionAsDefinedMeaning($description, $description, $geneName, $this->collectionId); |
| 360 | + } |
330 | 361 | addSynonymOrTranslation($geneName, $this->languageId, $definedMeaningId, true); |
331 | | - $this->organismSpecificGenes[$key] = $definedMeaningId; |
332 | | - } |
| 362 | + $this->organismSpecificGenes[$key] = $definedMeaningId; |
| 363 | + } |
333 | 364 | |
334 | 365 | addClassMembership($definedMeaningId, $this->organismSpecificGeneConceptId); |
335 | 366 | |
336 | 367 | //add relation between specific gene and organism |
337 | 368 | addRelation($definedMeaningId, $this->organismConceptId, $organismSpeciesMeaningId); |
338 | | - addRelation($organismSpeciesMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 369 | +// addRelation($organismSpeciesMeaningId, $this->referencedByConceptId, $definedMeaningId); |
339 | 370 | |
340 | 371 | //add relation between specific gene and gene |
341 | 372 | addRelation($definedMeaningId, $this->geneConceptId, $geneMeaningId); |
342 | | - addRelation($geneMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 373 | +// addRelation($geneMeaningId, $this->referencedByConceptId, $definedMeaningId); |
343 | 374 | |
344 | 375 | foreach ($synonyms as $key => $synonym) { |
345 | 376 | addSynonymOrTranslation($synonym, $this->languageId, $definedMeaningId, true); |
346 | 377 | } |
347 | 378 | |
| 379 | + |
| 380 | + |
348 | 381 | return $definedMeaningId; |
349 | 382 | } |
350 | 383 | |
— | — | @@ -370,18 +403,18 @@ |
371 | 404 | |
372 | 405 | // set the protein of the swiss prot entry and relate the protein to the entry: |
373 | 406 | addRelation($definedMeaningId, $this->proteinConceptId, $proteinMeaningId); |
374 | | - addRelation($proteinMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 407 | +// addRelation($proteinMeaningId, $this->referencedByConceptId, $definedMeaningId); |
375 | 408 | |
376 | 409 | // set the gene of the swiss prot entry and relate the gene to the entry: |
377 | 410 | if($organismSpecificGene >= 0) { |
378 | 411 | //add realtion between entry and gene |
379 | 412 | addRelation($definedMeaningId, $this->organismSpecificGeneConceptId, $organismSpecificGene); |
380 | | - addRelation($organismSpecificGene, $this->referencedByConceptId, $definedMeaningId); |
| 413 | +// addRelation($organismSpecificGene, $this->referencedByConceptId, $definedMeaningId); |
381 | 414 | } |
382 | 415 | |
383 | 416 | // set the species of the swiss prot entry and relate the species to the entry: |
384 | 417 | addRelation($definedMeaningId, $this->organismConceptId, $organismSpeciesMeaningId); |
385 | | - addRelation($organismSpeciesMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 418 | +// addRelation($organismSpeciesMeaningId, $this->referencedByConceptId, $definedMeaningId); |
386 | 419 | |
387 | 420 | // add the comment fields as text attributes: |
388 | 421 | foreach ($entry->comments as $key => $comment) { |
— | — | @@ -398,18 +431,40 @@ |
399 | 432 | if($entry->EC != ""){ |
400 | 433 | $ECNumberMeaningId = $this->getOrCreateECNumberMeaningId($entry->EC); |
401 | 434 | addRelation($definedMeaningId, $this->activityConceptId, $ECNumberMeaningId); |
402 | | - addRelation($ECNumberMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 435 | +// addRelation($ECNumberMeaningId, $this->referencedByConceptId, $definedMeaningId); |
403 | 436 | } |
404 | 437 | |
405 | 438 | // add keywords: |
406 | | - foreach ($entry->keywords as $key => $keyword) { |
407 | | - if (array_key_exists($keyword, $this->keyword2GoMeaningIdMapping)) { |
408 | | - $goMeaningId = $this->keyword2GoMeaningIdMapping[$keyword]; |
409 | | - addRelation($definedMeaningId, $this->keywordConceptId, $goMeaningId); |
410 | | - addRelation($goMeaningId, $this->referencedByConceptId, $definedMeaningId); |
411 | | - } |
| 439 | +// foreach ($entry->keywords as $key => $keyword) { |
| 440 | +// if (array_key_exists($keyword, $this->keyword2GoMeaningIdMapping)) { |
| 441 | +// $goMeaningId = $this->keyword2GoMeaningIdMapping[$keyword]; |
| 442 | +// addRelation($definedMeaningId, $this->keywordConceptId, $goMeaningId); |
| 443 | +// addRelation($goMeaningId, $this->referencedByConceptId, $definedMeaningId); |
| 444 | +// } |
| 445 | +// } |
| 446 | + |
| 447 | + if($this->goCollection) { |
| 448 | + foreach ($entry->GOReference as $key => $goReference) { |
| 449 | + $relationConcept = 0; |
| 450 | + switch($goReference->type) { |
| 451 | + case("biological process"): |
| 452 | + $relationConcept = $this->biologicalProcessConceptId; |
| 453 | + break; |
| 454 | + case("molecular function"): |
| 455 | + $relationConcept = $this->molecularFunctionConceptId; |
| 456 | + break; |
| 457 | + case("cellular component"): |
| 458 | + $relationConcept = $this->cellularComponentConceptId; |
| 459 | + break; |
| 460 | + } |
| 461 | + |
| 462 | + if($relationConcept && ($goConcept = $this->goCollection[$goReference->goCode])) { |
| 463 | + addRelation($definedMeaningId, $relationConcept, $goConcept); |
| 464 | + } |
| 465 | + } |
412 | 466 | } |
413 | 467 | |
| 468 | + |
414 | 469 | // Add 'included' functional domains: |
415 | 470 | foreach ($entry->protein->domains as $key => $domain) { |
416 | 471 | $domainMeaningId = $this->addFunctionalDomain($domain); |
— | — | @@ -523,6 +578,9 @@ |
524 | 579 | case "COMMENT": |
525 | 580 | $result = new CommentXMLElementHandler(); |
526 | 581 | break; |
| 582 | + case "DBREFERENCE": |
| 583 | + $result = new dbReferenceXMLElement(); |
| 584 | + break; |
527 | 585 | default: |
528 | 586 | $result = DefaultXMLElementHandler::getHandlerForNewElement($name); |
529 | 587 | break; |
— | — | @@ -550,6 +608,18 @@ |
551 | 609 | if ($childHandler->comment != "") |
552 | 610 | $this->entry->comments[] = $childHandler->comment; |
553 | 611 | } |
| 612 | + elseif (is_a($childHandler, dbReferenceXMLElement)) { |
| 613 | + if ($childHandler->type == "EC") { |
| 614 | + $this->entry->EC = $childHandler->id; |
| 615 | + } |
| 616 | + if ($childHandler->type == "GO") { |
| 617 | + $this->entry->GOReference[] = new GOReference($childHandler->id, $childHandler->property["term"]); |
| 618 | + } |
| 619 | + if ($childHandler->type == "HGNC") { |
| 620 | + $position = strpos($childHandler->id, ":"); |
| 621 | + $this->entry->HGNCReference = substr($childHandler->id, $position + 1); |
| 622 | + } |
| 623 | + } |
554 | 624 | elseif($childHandler->name == "ACCESSION") { |
555 | 625 | if ($this->entry->accession == "") { |
556 | 626 | $this->entry->accession = $childHandler->data; |
— | — | @@ -561,9 +631,6 @@ |
562 | 632 | elseif($childHandler->name == "NAME") { |
563 | 633 | $this->entry->name = $childHandler->data; |
564 | 634 | } |
565 | | - elseif($childHandler->name == "DBREFERENCE" && array_key_exists("TYPE", $childHandler->attributes) && $childHandler->attributes["TYPE"] == "EC"){ |
566 | | - $this->entry->EC = $childHandler->attributes["ID"]; |
567 | | - } |
568 | 635 | elseif($childHandler->name == "KEYWORD") { |
569 | 636 | $this->entry->keywords[] = $childHandler->attributes["ID"]; |
570 | 637 | } |
— | — | @@ -728,6 +795,23 @@ |
729 | 796 | } |
730 | 797 | } |
731 | 798 | |
| 799 | +class dbReferenceXMLElement extends DefaultXMLElementHandler { |
| 800 | + public $type; |
| 801 | + public $id; |
| 802 | + public $property = array(); |
| 803 | + |
| 804 | + public function setAttributes($attributes) { |
| 805 | + DefaultXMLElementHandler::setAttributes($attributes); |
| 806 | + |
| 807 | + $this->type = $attributes["TYPE"]; |
| 808 | + $this->id = $attributes["ID"]; |
| 809 | + } |
| 810 | + |
| 811 | + public function notify($childHandler) { |
| 812 | + $this->property[$childHandler->attributes["TYPE"]] = $childHandler->attributes["VALUE"]; |
| 813 | + } |
| 814 | +} |
| 815 | + |
732 | 816 | class SwissProtEntry { |
733 | 817 | public $name = ""; |
734 | 818 | public $accession = ""; |
— | — | @@ -740,6 +824,8 @@ |
741 | 825 | public $organismTranslations = array(); |
742 | 826 | public $comments = array(); |
743 | 827 | public $keywords = array(); |
| 828 | + public $GOReference = array(); |
| 829 | + public $HGNCReference; |
744 | 830 | } |
745 | 831 | |
746 | 832 | class Comment { |
— | — | @@ -756,5 +842,25 @@ |
757 | 843 | public $components = array(); |
758 | 844 | } |
759 | 845 | |
| 846 | +class GOReference { |
| 847 | + public $type; |
| 848 | + public $goCode; |
| 849 | + |
| 850 | + public function __construct($goCode, $term) { |
| 851 | + $this->goCode = $goCode; |
| 852 | + $typeAbbreviation = substr($term, 0, 1); |
| 853 | + switch($typeAbbreviation) { |
| 854 | + case("P"): |
| 855 | + $this->type = "biological process"; |
| 856 | + break; |
| 857 | + case("F"): |
| 858 | + $this->type = "molecular function"; |
| 859 | + break; |
| 860 | + case("C"): |
| 861 | + $this->type = "cellular component"; |
| 862 | + break; |
| 863 | + } |
| 864 | + } |
| 865 | +} |
760 | 866 | |
761 | 867 | ?> |
Index: trunk/extensions/Wikidata/WiktionaryZ/SpecialDatasearch.php |
— | — | @@ -0,0 +1,49 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +if (!defined('MEDIAWIKI')) die(); |
| 5 | + |
| 6 | +$wgExtensionFunctions[] = 'wfSpecialDatasearch'; |
| 7 | + |
| 8 | +function wfSpecialDatasearch() { |
| 9 | + class SpecialDatasearch extends SpecialPage { |
| 10 | + function SpecialDatasearch() { |
| 11 | + SpecialPage::SpecialPage('Datasearch'); |
| 12 | + } |
| 13 | + |
| 14 | + function execute( $par ) { |
| 15 | + global |
| 16 | + $wgOut, $wgTitle; |
| 17 | + |
| 18 | + $spelling = ltrim($_GET['search-text']); |
| 19 | + |
| 20 | + //possible to make a difference between Go and Search, now both have the same result |
| 21 | + $go = $_GET['go']; |
| 22 | + $fulltext = $_GET['fulltext']; |
| 23 | + |
| 24 | + $wgOut->addHTML('<h1>Words matching <i>'. $spelling . '</i> and associated meanings</h1>'); |
| 25 | + $wgOut->addHTML('<p>Showing only a maximum of 100 matches.</p>'); |
| 26 | + $wgOut->addHTML($this->searchText($spelling)); |
| 27 | + } |
| 28 | + |
| 29 | + function searchText($text) { |
| 30 | + require_once("Search.php"); |
| 31 | + |
| 32 | + $dbr = &wfGetDB(DB_SLAVE); |
| 33 | + |
| 34 | + $sql = "SELECT INSTR(LCASE(uw_expression_ns.spelling), LCASE(". $dbr->addQuotes("$text") .")) as position, uw_syntrans.defined_meaning_id AS defined_meaning_id, uw_expression_ns.spelling AS spelling, uw_expression_ns.language_id AS language_id ". |
| 35 | + "FROM uw_expression_ns, uw_syntrans ". |
| 36 | + "WHERE uw_expression_ns.expression_id=uw_syntrans.expression_id AND uw_syntrans.endemic_meaning=1 " . |
| 37 | + " AND " . getLatestTransactionRestriction('uw_syntrans'). |
| 38 | + " AND spelling LIKE " . $dbr->addQuotes("%$text%") . |
| 39 | + " ORDER BY position ASC, uw_expression_ns.spelling ASC limit 100"; |
| 40 | + |
| 41 | + $queryResult = $dbr->query($sql); |
| 42 | + list($relation, $editor) = getDefinedMeaningAsRelation($queryResult); |
| 43 | + return $editor->view(new IdStack("expression"), $relation); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + SpecialPage::addPage(new SpecialDatasearch()); |
| 48 | +} |
| 49 | + |
| 50 | +?> |
\ No newline at end of file |