text stringlengths 0 93.6k |
|---|
except WikiBaseError as e: |
pywikibot.error(e) |
return |
if not isinstance(obj, pywikibot.PropertyPage): |
pywikibot.warning(f'{pred} is not a valid property id') |
return |
claim = obj.newClaim() |
del obj |
if not self.set_target(claim, split[2].strip()): |
return |
add_new = True |
if not self.opt['noresolve']: |
for other in self.current.claims.get(pred, []): |
if other.same_as(claim, ignore_rank=True, ignore_quals=True, |
ignore_refs=True): |
claim = other |
add_new = False |
break |
if minus: |
if add_new: |
pywikibot.warning('No matching claim to remove found') |
else: |
self.current.removeClaim(claim, summary=summary) |
return |
if add_new: |
self.current.addClaim(claim, summary=summary) |
qualifiers = [] |
references = [] |
for prop, value in zip(split[3::2], split[4::2]): |
if prop.startswith('S'): |
collection = references |
prop = 'P' + prop[1:] |
key = 'is_reference' |
else: |
collection = qualifiers |
key = 'is_qualifier' |
# fixme: ideally, validation would be done upstream |
# snak = pywikibot.Claim(self.repo, prop, **{key: True}) |
try: |
obj = self.repo.get_entity_for_entity_id(prop) |
except WikiBaseError as e: |
pywikibot.error(e) |
return |
if not isinstance(obj, pywikibot.PropertyPage): |
pywikibot.warning(f'{prop} is not a valid property id') |
return |
snak = obj.newClaim(**{key: True}) |
del obj |
ok = self.set_target(snak, value.strip()) |
if not ok: |
return |
collection.append(snak) |
has_qualifiers = list(chain(*claim.qualifiers.values())) |
for qual in qualifiers: |
if qual not in has_qualifiers: |
claim.addQualifier(qual) |
has_qualifiers.append(qual) |
if references: |
# TODO: check for duplicity |
claim.addSources(references) |
def run(self): |
for line in self.generator: |
line = line.rstrip() |
if line: |
self.handle_line(line) |
def main(*args): |
options = {} |
local_args = pywikibot.handle_args(args) |
site = pywikibot.Site() |
for arg in local_args: |
if arg.startswith('-'): |
arg, sep, value = arg.partition(':') |
if value != '': |
options[arg[1:]] = value if not value.isdigit() else int(value) |
else: |
options[arg[1:]] = True |
with open(options.pop('file'), 'r', encoding='utf-8') as file: |
bot = QuickStatementsBot(file, site=site, **options) |
bot.run() |
if __name__ == '__main__': |
main() |
# <FILESEP> |
"""Capsule layer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.