function execute( $par ) { global $wgOut, $wgUser, $wgRequest; $wgOut->setPageTitle( 'Add Collection' ); if ( !$wgUser->isAllowed( 'addcollection' ) ) { $wgOut->addHTML( 'You do not have permission to add a collection.' ); return false; } $dbr = wfGetDB( DB_MASTER ); if ( $wgRequest->getText( 'collection' ) ) { require_once( 'WikiDataAPI.php' ); require_once( 'Transaction.php' ); $dc = $wgRequest->getText( 'dataset' ); $collectionName = $wgRequest->getText( 'collection' ); startNewTransaction( $wgUser->getID(), wfGetIP(), 'Add collection ' . $collectionName ); bootstrapCollection( $collectionName, $wgRequest->getText( 'language' ), $wgRequest->getText( 'type' ), $dc ); $wgOut->addHTML( wfMsg( 'ow_collection_added', $collectionName ) . "<br />" ); } $datasets = wdGetDatasets(); $datasetarray[''] = wfMsgSc( "none_selected" ); foreach ( $datasets as $datasetid => $dataset ) { $datasetarray[$datasetid] = $dataset->fetchName(); } $wgOut->addHTML( getOptionPanel( array( 'Collection name:' => getTextBox( 'collection' ), 'Language of name:' => getSuggest( 'language', 'language' ), 'Collection type:' => getSelect( 'type', array( '' => 'None', 'RELT' => 'RELT', 'LEVL' => 'LEVL', 'CLAS' => 'CLAS', 'MAPP' => 'MAPP' ) ), 'Dataset:' => getSelect( 'dataset', $datasetarray ) ), '', array( 'create' => wfMsg( 'ow_create' ) ) ) ); }
$result = $dbr->query( "select user_id from user where user_name = '$userName'" ); if ( $row = $dbr->fetchObject( $result ) ) { return $row->user_id; } else { return - 1; } } $userId = getUserId( 'Root' ); if ( $userId == - 1 ) { echo "root user undefined\n"; die; } setUser( $userId ); $datasets = getDatasets(); $dbr = wfGetDB( DB_SLAVE ); foreach ( $datasets as $dataset ) { foreach ( $datasets as $otherdataset ) { if ( $dataset != $otherdataset ) { echo "mapping between $otherdataset and $dataset\n"; setDefaultDC( $otherdataset ); startNewTransaction( $userId, wfGetIP(), 'Add collection ', $dataset ); bootstrapCollection( $dataset, '85', 'MAPP' ); } } } ?>
function bootStrappedDefinedMeanings( $dc ) { global $definedMeaningMeaningName, $definitionMeaningName, $relationMeaningName, $synTransMeaningName, $annotationMeaningName, $wgCommandLineMode; $wgCommandLineMode = true; $dbr = wfGetDB( DB_MASTER ); $dbr->query( "DROP TABLE IF EXISTS `{$dc}_bootstrapped_defined_meanings`;" ); $dbr->query( "CREATE TABLE `{$dc}_bootstrapped_defined_meanings` ( `name` VARCHAR(255) NOT NULL , `defined_meaning_id` INT NOT NULL);" ); $userId = getUserId( 'Root' ); if ( $userId == - 1 ) { echo "root user undefined\n"; return; } setUser( $userId ); setDefaultDC( $dc ); $rdc = wdGetDataSetContext(); startNewTransaction( $userId, 0, "Script bootstrap class attribute meanings", $dc ); $languageId = 85; $collectionId = bootstrapCollection( "Class attribute levels", $languageId, "LEVL" ); $meanings = array(); $meanings[$definedMeaningMeaningName] = bootstrapDefinedMeaning( $definedMeaningMeaningName, $languageId, "The combination of an expression and definition in one language defining a concept." ); $meanings[$definitionMeaningName] = bootstrapDefinedMeaning( $definitionMeaningName, $languageId, "A paraphrase describing a concept." ); $meanings[$synTransMeaningName] = bootstrapDefinedMeaning( $synTransMeaningName, $languageId, "A translation or a synonym that is equal or near equal to the concept defined by the defined meaning." ); $meanings[$relationMeaningName] = bootstrapDefinedMeaning( $relationMeaningName, $languageId, "The association of two defined meanings through a specific relation type." ); $meanings[$annotationMeaningName] = bootstrapDefinedMeaning( $annotationMeaningName, $languageId, "Characteristic information of a concept." ); foreach ( $meanings as $internalName => $meaningId ) { addDefinedMeaningToCollection( $meaningId, $collectionId, $internalName ); $dbr->query( "INSERT INTO `{$dc}_bootstrapped_defined_meanings` (name, defined_meaning_id) " . "VALUES (" . $dbr->addQuotes( $internalName ) . ", " . $meaningId . ")" ); } $timestamp = wfTimestampNow(); $dbr->query( "INSERT INTO {$dc}_script_log (time, script_name, comment) " . "VALUES (" . $timestamp . "," . $dbr->addQuotes( '23 - Bootstrap class attribute meanings.php' ) . "," . $dbr->addQuotes( 'create bootstrap class attribute meanings' ) . ")" ); }
`name` VARCHAR(255) NOT NULL , `defined_meaning_id` INT NOT NULL);" ); $userId = getUserId( 'Root' ); if ( $userId == - 1 ) { echo "root user undefined\n"; die; } setUser( $userId ); startNewTransaction( $userId, 0, "Script bootstrap class attribute meanings" ); $languageId = 85; $collectionId = bootstrapCollection( "Class attribute levels", $languageId, "LEVL" ); $meanings = array(); $meanings[$definedMeaningMeaningName] = bootstrapDefinedMeaning( $definedMeaningMeaningName, $languageId, "The combination of an expression and definition in one language defining a concept." ); $meanings[$definitionMeaningName] = bootstrapDefinedMeaning( $definitionMeaningName, $languageId, "A paraphrase describing a concept." ); $meanings[$synTransMeaningName] = bootstrapDefinedMeaning( $synTransMeaningName, $languageId, "A translation or a synonym that is equal or near equal to the concept defined by the defined meaning." ); $meanings[$relationMeaningName] = bootstrapDefinedMeaning( $relationMeaningName, $languageId, "The association of two defined meanings through a specific relation type." ); $meanings[$annotationMeaningName] = bootstrapDefinedMeaning( $annotationMeaningName, $languageId, "Characteristic information of a concept." ); foreach ( $meanings as $internalName => $meaningId ) { addDefinedMeaningToCollection( $meaningId, $collectionId, $internalName ); $dbr->query( "INSERT INTO `{$dc}_bootstrapped_defined_meanings` (name, defined_meaning_id) " . "VALUES (" . $dbr->addQuotes( $internalName ) . ", " . $meaningId . ")" ); } $dbr->query( "INSERT INTO {$dc}_script_log (time, script_name, comment) " .
public function __construct( $collectionId, $collectionName, $languageId, $collectionType = "" ) { $this->collectionId = $collectionId; $this->languageId = $languageId; if ( $this->collectionId == 0 ) $this->collectionId = bootstrapCollection( $collectionName, $languageId, $collectionType ); $this->contents = getCollectionContents( $this->collectionId ); }
function importUMLSFromDatabase( $server, $databaseName, $userName, $password, $sources = null ) { $result = new UMLSImportResult; openDatabase( $server, $databaseName, $userName, $password ); $languageId = 85; echo "Creating UMLS collections\n"; $umlsCollectionId = bootstrapCollection( "UMLS", $languageId, "" ); $result->umlsCollectionId = $umlsCollectionId; $relationCollectionId = bootstrapCollection( "UMLS Relation Types 2005", $languageId, "RELT" ); addDefinedMeaningToCollection( getCollectionMeaningId( $relationCollectionId ), $umlsCollectionId, "rel" ); $relationAttributesCollectionId = bootstrapCollection( "UMLS Relation Attributes 2005", $languageId, "RELT" ); addDefinedMeaningToCollection( $relationAttributesCollectionId, $umlsCollectionId, "rela" ); $semanticNetworkSemanticTypesCollectionId = bootstrapCollection( "Semantic Network 2005AC Semantic Types", $languageId, "CLAS" ); addDefinedMeaningToCollection( getCollectionMeaningId( $semanticNetworkSemanticTypesCollectionId ), $umlsCollectionId, "STY" ); $semanticNetworkRelationTypesCollectionId = bootstrapCollection( "Semantic Network 2005AC Relation Types", $languageId, "RELT" ); addDefinedMeaningToCollection( getCollectionMeaningId( $semanticNetworkRelationTypesCollectionId ), $umlsCollectionId, "RL" ); echo "Loading source abbreviations\n"; $sourceAbbreviations = loadSourceAbbreviations( $sources ); echo "Loading languages\n"; $isoLanguages = loadIsoLanguages(); echo "Importing UMLS terms per source\n"; $i = 1; foreach ( $sourceAbbreviations as $sab => $source ) { $collectionId = bootstrapCollection( $source, $languageId, "" ); $result->sourceAbbreviations[$sab] = $collectionId; echo " $i: $sab - $source\n"; importUMLSTerms( $sab, $umlsCollectionId, $collectionId, $languageId, $isoLanguages ); $i++; } echo "Importing UMLS definitions per source\n"; $i = 1; foreach ( $sourceAbbreviations as $sab => $source ) { echo " $i: $sab - $source\n"; importUMLSDefinitions( $sab, $umlsCollectionId, $result->sourceAbbreviations[$sab], $languageId ); $i++; } echo "Importing UMLS relation types\n"; importUMLSRelationTypes( $relationCollectionId, $languageId ); echo "Importing UMLS attribute types\n"; importUMLSRelationAttributes( $relationAttributesCollectionId, $languageId ); echo "Importing UMLS relations per source\n"; $relationCollection = getCollectionContents( $relationCollectionId ); $relationAttributesCollection = getCollectionContents( $relationAttributesCollectionId ); $i = 1; foreach ( $sourceAbbreviations as $sab => $source ) { echo " $i: $sab - $source\n"; $query = "select cui1, cui2, rel from MRREL where sab like '$sab'"; importUMLSRelations( $umlsCollectionId , $relationCollection, $query ); $query = "select cui1, cui2, rela from MRREL where sab like '$sab' and rela!=''"; importUMLSRelations( $umlsCollectionId , $relationAttributesCollection, $query ); $i++; } echo "Importing semantic network types\n"; importSNTypes( $semanticNetworkSemanticTypesCollectionId, "SELECT semtypeab,type,definition FROM srdef WHERE type='STY'", $languageId ); importSNTypes( $semanticNetworkRelationTypesCollectionId, "SELECT semtypeab,type,definition FROM srdef WHERE type='RL'", $languageId ); echo "Importing semantic network relations\n"; importSemanticTypeRelations( $semanticNetworkSemanticTypesCollectionId, $relationCollection, "SELECT SEMTYPE1, RELATION, SEMTYPE2 from semtypehier" ); importSemanticTypeRelations( $semanticNetworkRelationTypesCollectionId, $relationCollection, "SELECT RELTYPE1, RELATION, RELTYPE2 from semrelhier" ); echo "Importing UMLS semantic type relations per source\n"; $attributeTypes = getCollectionContents( $semanticNetworkSemanticTypesCollectionId ); $i = 1; foreach ( $sourceAbbreviations as $sab => $source ) { echo " " . $i++ . ": $sab - $source\n"; importUMLSSemanticTypes( $sab, $umlsCollectionId, $attributeTypes ); } return $result; }