本文整理匯總了Python中pywikibot.Claim方法的典型用法代碼示例。如果您正苦於以下問題:Python pywikibot.Claim方法的具體用法?Python pywikibot.Claim怎麽用?Python pywikibot.Claim使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pywikibot
的用法示例。
在下文中一共展示了pywikibot.Claim方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setClaim
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def setClaim (item, claim_id, claim_target, source_id, source_target, prompt=False) :
claim = pb.Claim(repo, claim_id)
target = pb.ItemPage(repo, claim_target)
claim.setTarget(target)
pb.output('Adding %s --> %s' % (claim.getID(), claim.getTarget()))
try :
item.addClaim(claim)
except Exception as e:
raise e
if source_id is not None and source_target is not None :
source_claim = pb.Claim(repo, source)
source_claim.setTarget(pb.ItemPage(repo, source_target))
try :
claim.addSource(source_claim)
except Exception as e:
raise e
if prompt :
prompt = '>'
raw_input(prompt)
return True
示例2: check_references
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def check_references(claim, references):
source_claims = claim.getSources()
if len(source_claims) != 1:
logging.info('Claim contains incorrect number of references')
return False
else:
if len(source_claims[0]) != len(references):
logging.info('Claim contains incorrect number of items in reference')
return False
else:
for k, v in source_claims[0].items():
if k in references:
prop_type = references[k][0]
source_val = None
if prop_type == 'id':
source_val = v[0].getTarget().id
elif prop_type == 'url':
source_val = v[0].getTarget()
if source_val != references[k][1]:
logging.info('Reference value [{}] incorrect for key: {}'.format(v[0].getTarget(), k))
return False
else:
logging.info('Reference contained incorrect property')
return False
return True
示例3: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addItemStatement(self, item, pid, qid):
'''
Helper function to add a statement
'''
if not qid:
return False
claims = item.get().get('claims')
if pid in claims:
return
newclaim = pywikibot.Claim(self.repo, pid)
destitem = pywikibot.ItemPage(self.repo, qid)
newclaim.setTarget(destitem)
pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
item.addClaim(newclaim)
return newclaim
#self.addReference(item, newclaim, url)
示例4: main
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def main():
lookuptable = makeLookupTable()
#print lookuptable
site = pywikibot.Site()
repo = site.data_repository()
query = u'SELECT ?item WHERE { ?item wdt:P359 [] . MINUS {?item wdt:P31 []} }'
itemGen = pagegenerators.PreloadingItemGenerator(pagegenerators.WikidataSPARQLPageGenerator(query, site=repo))
for item in itemGen:
pywikibot.output(item.title())
data = item.get()
claims = data.get('claims')
if u'P359' in claims:
rijksid = claims.get(u'P359')[0].getTarget()
if u'P31' not in claims:
if rijksid in lookuptable:
summary = u'Adding instance of %s based on %s' % (lookuptable[rijksid], rijksid)
typeItem = pywikibot.ItemPage(repo, title=lookuptable[rijksid])
newclaim = pywikibot.Claim(repo, u'P31')
newclaim.setTarget(typeItem)
pywikibot.output('Adding instance claim to %s' % item)
item.addClaim(newclaim, summary=summary)
示例5: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addItemStatement(self, item, pid, qid, url):
'''
Helper function to add a statement
'''
if not qid:
return False
claims = item.get().get('claims')
if pid in claims:
return
newclaim = pywikibot.Claim(self.repo, pid)
destitem = pywikibot.ItemPage(self.repo, qid)
newclaim.setTarget(destitem)
pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
item.addClaim(newclaim)
self.addReference(item, newclaim, url)
示例6: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addItemStatement(self, item, pid, qid, url):
'''
Helper function to add a statement
'''
if not qid:
return False
claims = item.get().get('claims')
if pid in claims:
return
newclaim = pywikibot.Claim(self.repo, pid)
destitem = pywikibot.ItemPage(self.repo, qid)
if destitem.isRedirectPage():
destitem = destitem.getRedirectTarget()
newclaim.setTarget(destitem)
pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
item.addClaim(newclaim)
self.addReference(item, newclaim, url)
示例7: addReference
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addReference(self, item, newclaim, url):
"""
Add a reference with a retrieval url and todays date
"""
pywikibot.output('Adding new reference claim to %s' % item)
statedin = pywikibot.Claim(self.repo, u'P248')
rkdartistsitem = pywikibot.ItemPage(self.repo,u'Q17299517')
statedin.setTarget(rkdartistsitem)
refurl = pywikibot.Claim(self.repo, u'P854') # Add url, isReference=True
refurl.setTarget(url)
refdate = pywikibot.Claim(self.repo, u'P813')
today = datetime.datetime.today()
date = pywikibot.WbTime(year=today.year, month=today.month, day=today.day)
refdate.setTarget(date)
newclaim.addSources([statedin, refurl, refdate])
示例8: addCollection
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addCollection(repo, item, metadata):
collections = { u'Private collection' : u'Q768717',
u'Otterlo, Kröller-Müller Museum' : u'Q1051928',
u'The Hague, Haags Gemeentemuseum' : u'Q1499958',
u'Den Bosch, Noordbrabants Museum' : u'Q12013217',
}
data = item.get()
claims = data.get('claims')
collection = metadata.get(u'collection')
if u'P195'not in claims:
if collection in collections:
collectionitem = pywikibot.ItemPage(repo, title=collections.get(collection))
newclaim = pywikibot.Claim(repo, u'P195')
newclaim.setTarget(collectionitem)
item.addClaim(newclaim)
addReference(repo, item, newclaim, metadata.get(u'url'))
elif collection not in collections:
print u'Did not find the collection %s for %s' % (collection, item.title(), )
示例9: addRkdimagesLink
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addRkdimagesLink(itemTitle, rkdid, summary):
repo = pywikibot.Site().data_repository()
item = pywikibot.ItemPage(repo, title=itemTitle)
if not item.exists():
return False
if item.isRedirectPage():
return False
data = item.get()
claims = data.get('claims')
if u'P350' in claims:
claim = claims.get('P350')[0]
if claim.getTarget()==u'%s' % (rkdid,):
pywikibot.output(u'Already got the right link on %s to rkdid %s!' % (itemTitle, rkdid))
return True
pywikibot.output(u'Already got a link to %s on %s, I\'m trying to add %s' % (claim.getTarget(),
itemTitle,
rkdid))
return False
newclaim = pywikibot.Claim(repo, u'P350')
newclaim.setTarget(u'%s' % (rkdid,))
pywikibot.output(summary)
item.addClaim(newclaim, summary=summary)
return True
示例10: addItemStatement
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def addItemStatement(self, item, pid, qid):
'''
Helper function to add a statement
'''
if not qid:
return False
claims = item.get().get('claims')
if pid in claims:
return
newclaim = pywikibot.Claim(self.repo, pid)
destitem = pywikibot.ItemPage(self.repo, qid)
newclaim.setTarget(destitem)
pywikibot.output(u'Adding %s->%s to %s' % (pid, qid, item))
item.addClaim(newclaim)
return newclaim
#self.addReference(item, newclaim, url)
示例11: formatter
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def formatter(self, textvalue):
prop = self.current_page
if prop.type not in ['commonsMedia', 'external-id', 'string']:
pywikibot.output('"%s" datatype doesn\'t make use of formatter'
'' % prop.type)
return True
for match in self.get_formatter_regex().findall(textvalue):
if any(map(methodcaller('target_equals', match),
prop.claims.get('P1630', []))):
pywikibot.output('"%s" already has "%s" as the formatter URL'
'' % (prop.title(), match))
continue
if match.strip() in ['http://', 'https://']:
continue # ???
claim = pywikibot.Claim(self.repo, 'P1630')
claim.setTarget(match)
self.user_edit_entity(prop, {'claims':[claim.toJSON()]},
summary=self.make_summary('P1630', match),
asynchronous=True)
return True
示例12: proposed_by
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def proposed_by(self, textvalue):
prop = self.current_page
if 'P3254' not in prop.claims:
try:
int(textvalue)
except:
pywikibot.exception()
else:
claim = pywikibot.Claim(self.repo, 'P3254')
target = ('https://www.wikidata.org/wiki/'
'Wikidata:Property_proposal/Archive/%s#%s'
) % (textvalue, prop.id)
claim.setTarget(target)
self.user_edit_entity(
prop, {'claims':[claim.toJSON()]}, asynchronous=True,
summary=self.make_summary('P3254', target))
return False
示例13: create_item
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def create_item(self, item, labels, relation, to_add):
new_item = pywikibot.ItemPage(self.repo)
data = {'labels': labels}
self.user_edit_entity(
new_item, data, summary='based on data in %s' % item.title(
asLink=True, insite=self.repo))
claim = pywikibot.Claim(self.repo, 'P31')
claim.setTarget(pywikibot.ItemPage(self.repo, 'Q5'))
self.user_add_claim(new_item, claim)
if relation == 'twin':
claim = pywikibot.Claim(self.repo, 'P31')
claim.setTarget(pywikibot.ItemPage(self.repo, 'Q159979'))
self.user_add_claim(new_item, claim)
claim = pywikibot.Claim(self.repo, 'P361')
claim.setTarget(item)
self.user_add_claim(new_item, claim)
for json in to_add:
self.user_edit_entity(
new_item, {'claims':[json]},
summary='moving [[Property:%s]] from %s' % (
json['mainsnak']['property'],
item.title(asLink=True, insite=self.repo)))
return new_item
示例14: handle_source
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def handle_source(self, claim, source, target):
for prop in self.ref_props:
keys = set(source.keys())
if not (keys & set([prop])):
continue
if keys - (self.whitelist_props | set([prop])):
continue
if len(source[prop]) > 1:
#continue?
return
fake = next(iter(source[prop]))
items = list(item_ids) + [target]
if any(fake.target_equals(tgt) for tgt in items):
good_sources = list(chain.from_iterable(
source[p] for p in keys - set([prop])))
snak = pywikibot.Claim(self.repo, self.inferred_from,
isReference=True)
snak.setTarget(target)
claim.addSources(good_sources + [snak])
claim.removeSources(good_sources + [fake])
示例15: check_claim
# 需要導入模塊: import pywikibot [as 別名]
# 或者: from pywikibot import Claim [as 別名]
def check_claim(claim, val, qualifiers, year):
try:
#0 - claim matches
#1 - remove claim
#2 - skip claim
claim_status = 0
p_in_time = qualifiers[0][0]
det_method = qualifiers[1][0]
amt = claim.getTarget().amount
if p_in_time in claim.qualifiers:
clm_yr = claim.qualifiers[p_in_time][0].getTarget().year
if clm_yr == int(year):
if amt == val:
if det_method in claim.qualifiers:
if claim.qualifiers[det_method][0].getTarget().id != qualifiers[1][1][1]:
logging.info('Status [1] - Qualifier [{}] value incorrect'.format(qualifiers[1][0]))
claim_status = 1
else:
logging.info('Status [1] - Qualifier [{}] missing'.format(qualifiers[1][0]))
claim_status = 1
else:
logging.info('Year: {}, Value: {:,}'.format(clm_yr, amt))
logging.info('Status [1] - Value incorrect')
claim_status = 1
else:
logging.info('Status [2] - Skipping Claim')
claim_status = 2
else:
logging.info('Status [1] - Qualifier [point in time] missing')
claim_status = 1
return claim_status
except:
raise