Пример #1
0
  FILTER(lang(?title) = "und")
} LIMIT 100
"""

def fix_lang(claims, labels):
    for claim in claims:
        if claim.getSnakType() != 'value':
            continue
        target = claim.getTarget()
        print(target)
        if not isinstance(target, pywikibot.WbMonolingualText):
            continue
        if target.language != 'und':
            continue
        for lablang in labels:
            if labels[lablang] == target.text:
                print("Found match: %s:%s" % (lablang, labels[lablang]))
                target.language = lablang
                claim.changeTarget(target, summary="Fixing title language")
                break

results = sparql_query.get_items(TITLES_QUERY, item_name="p")
for itemID in results:
    item = pywikibot.ItemPage(repo, itemID)
    item.get()
    print("Processing %s" % itemID)
    if 'P1705' in item.claims:
        fix_lang(item.claims['P1705'], item.labels)
    if 'P1476' in item.claims:
        fix_lang(item.claims['P1476'], item.labels)
Пример #2
0
SELECT ?id ?idLabel WHERE {
    ?id p:P2067/psv:P2067 [ wikibase:quantityUnit wd:Q199 ] .
    ?id wdt:P31 wd:Q848944 .
    FILTER(?id != wd:Q4115189 && ?id != wd:Q13406268 && ?id != wd:Q15397819)
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
"""
TON = 'http://www.wikidata.org/entity/Q752079'
VOLUME = 'P2234'

site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
site.throttle.setDelays(writedelay=1)

sparql_query = SparqlQuery()
items = sparql_query.get_items(QUERY, item_name="id")

print("%d items found" % len(items))
for item in items:
    qid = item.strip()
    if qid[0:5] == 'http:':
        # strip http://www.wikidata.org/entity/
        qid = qid[31:]
    item = pywikibot.ItemPage(repo, qid)
    item.get()
    if PROP not in item.claims:
        print("No %s for %s, skip!" % (PROP, qid))
        continue
    badclaims = []
    for claim in item.claims[PROP]:
        if claim.getSnakType() != 'value':
Пример #3
0
  ?st a wikibase:BestRank .
# Another claim
  ?s ?prop ?st2 .
  FILTER(?st2 != ?st)
# with an end time
  ?st2 q:P585 ?t3 .
# and it's not a dead person
  OPTIONAL { ?s wdt:P570 ?d }
  FILTER(!bound(?d))
  ?st2 wikibase:rank wikibase:NormalRank.
  ?st2 a wikibase:BestRank .
} LIMIT 10
"""

with open(sys.argv[1]) as f:
    items = f.readlines()

print("Got %d items" % len(items))

for item in items:
    item = item.strip()
    se_query = START_END_QUERY % item
    pit_query = POINT_QUERY % item
    print("Checking %s..." % item)
    results = sparql_query.get_items(se_query, item_name="s")
    if len(results) > 0:
        print(" %d start/end results for %s" % (len(results), item))
    results = sparql_query.get_items(pit_query, item_name="s")
    if len(results) > 0:
        print(" %d PIT results for %s" % (len(results), item))