From b3051059b92f55d568c805ff5777544b77f2f882 Mon Sep 17 00:00:00 2001 From: Myst <1592048+LeMyst@users.noreply.github.com> Date: Fri, 17 Dec 2021 10:20:50 +0100 Subject: [PATCH] Create lexeme_update.ipynb (#263) --- notebooks/lexeme_update.ipynb | 293 ++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 notebooks/lexeme_update.ipynb diff --git a/notebooks/lexeme_update.ipynb b/notebooks/lexeme_update.ipynb new file mode 100644 index 00000000..980bae66 --- /dev/null +++ b/notebooks/lexeme_update.ipynb @@ -0,0 +1,293 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Update an existing Lexeme" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from wikibaseintegrator import WikibaseIntegrator, wbi_login, datatypes\n", + "from wikibaseintegrator.models import Reference, References\n", + "from wikibaseintegrator.models.qualifiers import Qualifiers\n", + "from wikibaseintegrator.wbi_config import config" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "outputs": [], + "source": [ + "WDUSER = ''\n", + "WDPASS = ''" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Set default variables" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 3, + "outputs": [], + "source": [ + "config['MEDIAWIKI_API_URL'] = 'https://test.wikidata.org/w/api.php'\n", + "config['USER_AGENT'] = 'Lexeme Write Notebook'" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Create login and WikibaseIntegrator object" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 4, + "outputs": [], + "source": [ + "login = wbi_login.Login(auth_method='login', user=WDUSER, password=WDPASS,\n", + " mediawiki_api_url='https://test.wikidata.org/w/api.php')\n", + "wbi = WikibaseIntegrator(login=login)" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Get existing lexeme entity" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 5, + "outputs": [], + "source": [ + "lexeme = wbi.lexeme.get(entity_id='L42')" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Set french lemmas" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "source": [ + "# Lemmas\n", + "lexeme.lemmas.set(language='fr', value='réponse')" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + }, + "execution_count": 6, + "outputs": [ + { + "data": { + "text/plain": "" + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ] + }, + { + "cell_type": "markdown", + "source": [ + "## Create a new claim" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 7, + "outputs": [], + "source": [ + "# Claims\n", + "claim_references = References() # Create a group of references\n", + "\n", + "claim_reference1 = Reference()\n", + "claim_reference1.add(datatypes.String(prop_nr='P828', value='Claim string reference'))\n", + "\n", + "claim_reference2 = Reference()\n", + "claim_reference2.add(datatypes.String(prop_nr='P828', value='Another claim string reference'))\n", + "\n", + "# Add each reference to the group of references\n", + "claim_references.add(claim_reference1)\n", + "claim_references.add(claim_reference2)\n", + "\n", + "claim_qualifiers = Qualifiers()\n", + "claim_qualifiers.add(datatypes.String(prop_nr='P828', value='Claim qualifier'))\n", + "\n", + "claim = datatypes.String(prop_nr='P828', value=\"Create a string claim for claim\", references=claim_references,\n", + " qualifiers=claim_qualifiers)\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Add claim to lexeme" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 8, + "outputs": [ + { + "data": { + "text/plain": " _Snak__property_number='P77771' _Snak__hash='5362eb3a0f7cba043a1b2afbc0352fc16463b0de' _Snak__datavalue={'value': {'entity-type': 'form', 'id': 'L41-F1'}, 'type': 'wikibase-entityid'} _Snak__datatype='wikibase-form'> _Claim__type='statement' _Claim__qualifiers= _Claim__qualifiers_order=[] _Claim__id='L42$7bd50233-4080-3f02-5fc3-c01b905a58ed' _Claim__rank= _Claim__removed=False _Claim__references=>,
_Snak__property_number='P77771' _Snak__hash='1ad1672f2ebc9e96628b20091d1c0f7f17f2ec65' _Snak__datavalue={'value': {'entity-type': 'form', 'id': 'L103-F1'}, 'type': 'wikibase-entityid'} _Snak__datatype='wikibase-form'> _Claim__type='statement' _Claim__qualifiers= _Claim__qualifiers_order=[] _Claim__id='L42$e6a6d9c6-4874-05b9-b7e6-433e7904e624' _Claim__rank= _Claim__removed=False _Claim__references=>], 'P828': [ _Snak__property_number='P828' _Snak__hash='dc920cec98f0e830c30011cd496108be8d50afab' _Snak__datavalue={'value': 'Create a string claim for claim', 'type': 'string'} _Snak__datatype='string'> _Claim__type='statement' _Claim__qualifiers= _Snak__property_number='P828' _Snak__hash='351f871bfe166697d3270cc0df7df8d09603efb0' _Snak__datavalue={'value': 'Claim qualifier', 'type': 'string'} _Snak__datatype='string'>]}> _Claim__qualifiers_order=['P828'] _Claim__id='L42$1B581F6D-71B6-4861-8300-6C5CFEE80337' _Claim__rank= _Claim__removed=False _Claim__references= _Snak__property_number='P828' _Snak__hash='bae62d7b26cff18d5a9d277e04475fcb6bd9bcfb' _Snak__datavalue={'value': 'Claim string reference', 'type': 'string'} _Snak__datatype='string'>]}> _Reference__snaks_order=['P828']>, _Snak__property_number='P828' _Snak__hash='dcd0b956c352f2036bb7da153c4db941e74a803f' _Snak__datavalue={'value': 'Another claim string reference', 'type': 'string'} _Snak__datatype='string'>]}> _Reference__snaks_order=['P828']>]>>]}>" + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lexeme.claims.add(claim)" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + }, + { + "cell_type": "markdown", + "source": [ + "## Write the lexeme to the Wikibase" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%% md\n" + } + } + }, + { + "cell_type": "code", + "execution_count": 9, + "outputs": [ + { + "data": { + "text/plain": "\n\t lastrevid=553469\n\t type='lexeme'\n\t id='L42'\n\t claims= _Snak__property_number='P77771' _Snak__hash='5362eb3a0f7cba043a1b2afbc0352fc16463b0de' _Snak__datavalue={'value': {'entity-type': 'form', 'id': 'L41-F1'}, 'type': 'wikibase-entityid'} _Snak__datatype='wikibase-form'> _Claim__type='statement' _Claim__qualifiers= _Claim__qualifiers_order=[] _Claim__id='L42$7bd50233-4080-3f02-5fc3-c01b905a58ed' _Claim__rank= _Claim__removed=False _Claim__references=>, _Snak__property_number='P77771' _Snak__hash='1ad1672f2ebc9e96628b20091d1c0f7f17f2ec65' _Snak__datavalue={'value': {'entity-type': 'form', 'id': 'L103-F1'}, 'type': 'wikibase-entityid'} _Snak__datatype='wikibase-form'> _Claim__type='statement' _Claim__qualifiers= _Claim__qualifiers_order=[] _Claim__id='L42$e6a6d9c6-4874-05b9-b7e6-433e7904e624' _Claim__rank= _Claim__removed=False _Claim__references=>], 'P828': [ _Snak__property_number='P828' _Snak__hash='dc920cec98f0e830c30011cd496108be8d50afab' _Snak__datavalue={'value': 'Create a string claim for claim', 'type': 'string'} _Snak__datatype='string'> _Claim__type='statement' _Claim__qualifiers= _Snak__property_number='P828' _Snak__hash='351f871bfe166697d3270cc0df7df8d09603efb0' _Snak__datavalue={'value': 'Claim qualifier', 'type': 'string'} _Snak__datatype='string'>]}> _Claim__qualifiers_order=['P828'] _Claim__id='L42$1B581F6D-71B6-4861-8300-6C5CFEE80337' _Claim__rank= _Claim__removed=False _Claim__references= _Snak__property_number='P828' _Snak__hash='bae62d7b26cff18d5a9d277e04475fcb6bd9bcfb' _Snak__datavalue={'value': 'Claim string reference', 'type': 'string'} _Snak__datatype='string'>]}> _Reference__snaks_order=['P828']>, _Snak__property_number='P828' _Snak__hash='dcd0b956c352f2036bb7da153c4db941e74a803f' _Snak__datavalue={'value': 'Another claim string reference', 'type': 'string'} _Snak__datatype='string'>]}> _Reference__snaks_order=['P828']>]>>]}>\n\t lemmas=, 'fr': }>\n\t lexical_category='Q1084'\n\t language='Q1860'\n\t forms=\n\t senses=>" + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lexeme.write()\n" + ], + "metadata": { + "collapsed": false, + "pycharm": { + "name": "#%%\n" + } + } + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file