Hiong3-eng5 has uploaded a new change for review. https://gerrit.wikimedia.org/r/88936
Change subject: added classes and collections to owd csv ...................................................................... added classes and collections to owd csv Change-Id: I0c5684956de440fb49bd3657b6d243ccb010c02d --- M OmegaWiki/WikiDataAPI.php M includes/jobs/OWOwdListJob.php 2 files changed, 140 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiLexicalData refs/changes/36/88936/1 diff --git a/OmegaWiki/WikiDataAPI.php b/OmegaWiki/WikiDataAPI.php index a91296a..af22f95 100644 --- a/OmegaWiki/WikiDataAPI.php +++ b/OmegaWiki/WikiDataAPI.php @@ -4,7 +4,6 @@ require_once( 'Transaction.php' ); require_once( 'WikiDataGlobals.php' ); - function getExpression( $expressionId, $dc = null ) { if ( is_null( $dc ) ) { $dc = wdGetDataSetContext(); @@ -2762,3 +2761,109 @@ return $dmlist; } + +class Collections { + + public static function getDefinedMeaningIdCollectionMembershipExpressions( $definedMeaningId, $languageId ) { + $dc = wdGetDataSetContext(); + $dbr = wfGetDB( DB_SLAVE ); + + $queryResult = $dbr->select( + array( + 'exp' => "{$dc}_expression", + 'synt' => "{$dc}_syntrans", + 'cc' => "{$dc}_collection_contents" + ), + 'collection_id', + array( + 'member_mid' => $definedMeaningId, + 'exp.remove_transaction_id' => null, + 'synt.remove_transaction_id' => null, + 'cc.remove_transaction_id' => null, + 'exp.expression_id = synt.expression_id', + 'synt.defined_meaning_id = member_mid' + ), __METHOD__, + array( + 'DISTINCT' + ) + ); + + $expressions = array(); + + foreach ( $queryResult as $collectionId ) { + $definedMeaningId = getCollectionMeaningId( $collectionId->collection_id ); + $tempExpressions = Expressions::getDefinedMeaningIdAndLanguageIdExpressions( $languageId, $definedMeaningId ); + if ( $tempExpressions ){ + $expressions[] = array( + 'expression' => $tempExpressions[0], + 'definedMeaningId' => $definedMeaningId + ); + } else { + $expressions[] = array( + 'expression' => '', + 'definedMeaningId' => $definedMeaningId + ); + } + } + + return $expressions; + + } +} + +class WLD_Class { + + /** Get a list of Class Expressions where the Defined Meaning Id is a member of. + * + * @param definedMeaningId + * @param languageId + * + * @return list of array expressions + * @return array() when none + */ + public static function getDefinedMeaningIdClassMembershipExpressions( $definedMeaningId, $languageId ) { + $dc = wdGetDataSetContext(); + $dbr = wfGetDB( DB_SLAVE ); + $Expressions = new Expressions; + + $queryResult = $dbr->select( + array( + 'exp' => "{$dc}_expression", + 'synt' => "{$dc}_syntrans", + 'cm' => "{$dc}_class_membership" + ), + 'class_mid', + array( + 'class_member_mid' => $definedMeaningId, + 'exp.remove_transaction_id' => null, + 'synt.remove_transaction_id' => null, + 'cm.remove_transaction_id' => null, + 'exp.expression_id = synt.expression_id', + 'synt.defined_meaning_id = class_mid' + ), __METHOD__, + array( + 'DISTINCT' + ) + ); + + $expressions = array(); + + foreach ( $queryResult as $definedMeaningId ) { + $tempExpressions = Expressions::getDefinedMeaningIdAndLanguageIdExpressions( $languageId, $definedMeaningId->class_mid ); + if ( $tempExpressions ){ + $expressions[] = array( + 'expression' => $tempExpressions[0], + 'definedMeaningId' => $definedMeaningId->class_mid + ); + } else { + $expressions[] = array( + 'expression' => '', + 'definedMeaningId' => $definedMeaningId->class_mid + ); + } + } + + return $expressions; + + } +} diff --git a/includes/jobs/OWOwdListJob.php b/includes/jobs/OWOwdListJob.php index 909df6d..f1a30b6 100644 --- a/includes/jobs/OWOwdListJob.php +++ b/includes/jobs/OWOwdListJob.php @@ -27,7 +27,7 @@ */ public function run() { // Load data from $this->params and $this->title - $this->version = '1.0'; + $this->version = '1.1'; if ( isset( $this->params['langcode'] ) ) { $languageId = $this->params['langcode']; } @@ -120,7 +120,7 @@ $fhsyn = fopen ( $tempSynFileName, 'a' ); $fhatt = fopen ( $tempAttFileName, 'a' ); $fhini = fopen ( $tempIniFileName, 'a' ); - $fhmia = fopen ( $tempMiaFileName, 'w' ); + $fhmia = fopen ( $tempMiaFileName, 'a' ); } // Add data $ctr = 0; @@ -129,6 +129,8 @@ $this->Attributes = new Attributes; $this->Expressions = new Expressions; $this->Transactions = new Transactions; + $this->ClassAttribute = new WLD_Class; + $this->Collections = new Collections; $enId = array( 'IPA' => Attributes::getClassAttributeId( 'International Phonetic Alphabet', WLD_ENGLISH_LANG_ID ), 'pinyin' => Attributes::getClassAttributeId( 'pinyin', WLD_ENGLISH_LANG_ID ), @@ -365,13 +367,41 @@ ); } } - $subject = $this->removeAllEndSemiColon( $subject ); + $subject = trim( $this->removeAllEndSemiColon( $subject ) ); + + // Get Class Attributes + $classes = $this->ClassAttribute->getDefinedMeaningIdClassMembershipExpressions( $definedMeaningId, $languageId ); + $classAttribute = null; + foreach ( $classes as $row ) { + if ( $row['expression'] ) { + $classAttribute .= $row['expression'] . ';'; + } else { + $classAttribute .= '<' . $row['definedMeaningId'] . '/>;'; + } + } + $classes = array(); + $classAttribute = trim( $this->removeAllEndSemiColon( $classAttribute ) ); + + // Get Collection Attributes + $collections = $this->Collections->getDefinedMeaningIdCollectionMembershipExpressions( $definedMeaningId, $languageId ); + $collection = null; + foreach ( $collections as $row ) { + if ( $row['expression'] ) { + $collection .= $row['expression'] . ';'; + } else { + $collection .= '<' . $row['definedMeaningId'] . '/>;'; + } + } + $classes = array(); + $collection = trim( $this->removeAllEndSemiColon( $collection ) ); fwrite( $fh, $definedMeaningId . ',' . $languageId . ',' . $text . - ',' . $subject . + ',' . $csv->formatCSVcolumn( $subject ) . + ',' . $csv->formatCSVcolumn( $classAttribute ) . + ',' . $csv->formatCSVcolumn( $collection ) . "\n" ); $ctr ++; -- To view, visit https://gerrit.wikimedia.org/r/88936 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0c5684956de440fb49bd3657b6d243ccb010c02d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikiLexicalData Gerrit-Branch: master Gerrit-Owner: Hiong3-eng5 <hiong3.e...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits