Ejegg has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371701 )

Change subject: Add reciprocal claims to harvested targets
......................................................................

Add reciprocal claims to harvested targets

For example, if you are harvesting 'has part' claims for data items
in a category, -reciprocal:P463 will also add 'member of' claims to
the targets of each 'has part' link pointing back to the data item.

Bug: T173238
Change-Id: I5506df8f92c360ee6b9dd2c17dfc4264d7ed3cc7
---
M scripts/harvest_template.py
1 file changed, 13 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/01/371701/1

diff --git a/scripts/harvest_template.py b/scripts/harvest_template.py
index f676f0e..fc25ff9 100755
--- a/scripts/harvest_template.py
+++ b/scripts/harvest_template.py
@@ -121,6 +121,7 @@
         'exists': '',
         'islink': False,
         'multi': False,
+        'reciprocal': '',
     }
 
 
@@ -142,12 +143,15 @@
         @type islink: bool
         @keyword multi: Whether multiple values should be extracted from a 
single parameter
         @type multi: bool
+        @keyword reciprocal: a property to populate on the target, pointing to 
the page item
+        @type reciprocal: string
         """
         self.availableOptions.update({
             'always': True,
             'exists': '',
             'islink': False,
             'multi': False,
+            'reciprocal': '',
         })
         super(HarvestRobot, self).__init__(**kwargs)
         self.generator = generator
@@ -325,10 +329,17 @@
                     claims.append(claim)
                 for add_claim in claims:
                     # A generator might yield pages from multiple sites
+                    exists_option = self._get_option_with_fallback(options, 
'exists')
                     self.user_add_claim_unless_exists(
-                        item, add_claim, self._get_option_with_fallback(
-                            options, 'exists'),
+                        item, add_claim, exists_option,
                         page.site, pywikibot.output)
+                    reciprocal = self._get_option_with_fallback(options, 
'reciprocal')
+                    if reciprocal != '':
+                        reciprocal_claim = pywikibot.Claim(self.repo, 
reciprocal)
+                        reciprocal_claim.setTarget(item)
+                        self.user_add_claim_unless_exists(
+                            add_claim.getTarget(), reciprocal_claim,
+                            exists_option, page.site, pywikibot.output)
 
 
 def main(*args):

-- 
To view, visit https://gerrit.wikimedia.org/r/371701
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5506df8f92c360ee6b9dd2c17dfc4264d7ed3cc7
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to