Beispiel #1
0
import json
import lwb

with open('D:/LexBib/terms/langdict.json', encoding="utf-8") as f:
    langdict = json.load(f)

with open('D:/LexBib/languages/publangs.txt', encoding="utf-8") as f:
    publangs = f.read().split('\n')

count = 0
for lang in publangs:
    count += 1
    print('\nLine [' + str(count) + '] of ' + str(len(publangs)) + ': ' + lang)

    qid = lwb.getqid(["Q8"], lang)  # class Language
    statement = lwb.updateclaim(qid, "P4", langdict[lang]['wdqid'], "url")
    statement = lwb.updateclaim(qid, "P32", lang, "url")
    for label in langdict[lang]['labels']:
        statement = lwb.setlabel(qid, label, langdict[lang]['labels'][label])
    print('OK. ' + str(len(publangs) - count) + ' languages left.')

print('\nFinished.\n')
Beispiel #2
0
    "http://www.w3.org/2004/02/skos/core#exactMatch": "P78",
    "http://www.w3.org/2004/02/skos/core#relatedMatch": "P79",
    "http://www.w3.org/2004/02/skos/core#definition": "P80"
}

with open('D:/LexBib/terms/SKOS4lwb.json', encoding="utf-8") as f:
    data = json.load(f)['results']['bindings']

count = 1
for row in data:
    print('\nTriple [' + str(count) + '], ' + str(len(data) - count) +
          ' triples left.')
    lwbs = lwb.getqid("Q7", row['s']['value'])

    if row['p']['value'] in propmap:
        if row['o']['type'] == "literal":
            statement = lwb.updateclaim(lwbs, propmap[row['p']['value']],
                                        row['o']['value'].rstrip(), "string")
        else:
            lwbo = lwb.getqid("Q7", row['o']['value'].rstrip())
            statement = lwb.updateclaim(lwbs, propmap[row['p']['value']], lwbo,
                                        "item")
    elif row['p']['value'] == "http://www.w3.org/2004/02/skos/core#prefLabel":
        lwb.setlabel(lwbs, row['o']['xml:lang'], row['o']['value'].rstrip())
    elif row['p']['value'] == "http://www.w3.org/2004/02/skos/core#altLabel":
        lwb.setlabel(lwbs,
                     row['o']['xml:lang'],
                     row['o']['value'].rstrip(),
                     type="alias")
    count += 1
Beispiel #3
0
done = False
while (not done):
    try:
        r = requests.get(url)
        bindings = r.json()['results']['bindings']
    except Exception as ex:
        print('Error: SPARQL request failed: ' + str(ex))
        time.sleep(2)
        continue
    done = True
#print(str(bindings))

print(
    'Found ' + str(len(bindings)) +
    ' BibItems without label. Will proceed to set them using the BibItem title...\n'
)
time.sleep(3)

count = 0
for item in bindings:
    count += 1
    bibitem = item['bibItem']['value'].replace(
        "http://data.lexbib.org/entity/", "")
    title = item['dct_title']['value']
    wikilang = item['wikilang']['value']
    label = lwb.setlabel(bibitem, wikilang, title)
    if wikilang != "en":  # always add title as English label, also if not English
        label = lwb.setlabel(bibitem, "en", title)
    if label:
        print('OK. ' + str(len(bindings) - count) + ' items left.\n')
Beispiel #4
0
                            container = container.replace("-", "")
                            container = container.replace(
                                "isbn:", "http://worldcat.org/isbn/")
                            container = container.replace(
                                "oclc:", "http://worldcat.org/oclc/")
                        elif container.startswith('doi:'):
                            container = container.replace(
                                "doi:", "http://doi.org/")
                        # check container type
                        if item['type'] == "article-journal":
                            qid = lwb.getqid("Q1907", container)
                        else:
                            qid = lwb.getqid("Q12", container)
                        if item['type'] != "chapter" and "title-short" in item and item[
                                'title-short'] not in seen_titles:
                            lwb.setlabel(qid, "en", item['title-short'])
                            seen_titles.append(item['title-short'])
                        propvals.append({
                            "property": "P9",
                            "datatype": "item",
                            "value": qid
                        })  # container relation

                    if tag["tag"].startswith(':type '):
                        type = tag["tag"].replace(":type ", "")
                        if type == "Review":
                            propvals.append({
                                "property": "P5",
                                "datatype": "item",
                                "value": "Q15"
                            })
Beispiel #5
0
        regexp = re.compile(r'Q\d+')
        if regexp.search(label):
            label = ""

    except Exception as ex:
        print("ISSN " + issn +
              " not found on wikidata, skipping, will add to orphaned list.")
        orphaned += issn + '\tnot found on wikidata.\n'
        continue

    # create lwb serial for this orphaned issn
    lwbqid = lwb.getqid("Q20", wdqid)  # for serials, wdqid is also lexbib uri
    statement = lwb.updateclaim(lwbqid, "P3", wdqid, "url")
    statement = lwb.updateclaim(lwbqid, "P20", issn, "string")
    statement = lwb.updateclaim(lwbqid, "P4", wdqid, "url")
    statement = lwb.setlabel(lwbqid, "en", label)

    # add P46 "contained in serial" to bibitems with that issn
    # get bibitems

    url = "https://data.lexbib.org/query/sparql?format=json&query=PREFIX%20lwb%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fentity%2F%3E%0APREFIX%20ldp%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fprop%2Fdirect%2F%3E%0A%0Aselect%20%3FbibItem%20%3Fissn%20%3Fjournal%20where%0A%7B%20%3FbibItem%20ldp%3AP5%20lwb%3AQ3%20.%0A%20%20%3FbibItem%20ldp%3AP20%20%3Fissn%20.%0A%20%3Fjournal%20ldp%3AP5%20lwb%3AQ20%20.%0A%20%3Fjournal%20ldp%3AP20%20%3Fissn%20.%0A%20FILTER%20%28%3Fissn%20%3D%20%22" + issn + "%22%29%7D"
    done = False
    while (not done):
        try:
            r2 = requests.get(url)
            bindings2 = r2.json()['results']['bindings']
        except Exception as ex:
            print('Error: SPARQL request failed: ' + str(ex))
            time.sleep(2)
            continue
        done = True
            lwb.updateclaim(creatorqid, "P41", item['lastName'], "string")
        claim = lwb.getclaimfromstatement(oldStatement)
        if "P39" in claim:
            newprop = "P12"
            listpos = claim["P39"][0]['qualifiers']["P33"][0]['datavalue'][
                'value']
        elif "P42" in claim:
            newprop = "P13"
            listpos = claim["P42"][0]['qualifiers']["P33"][0]['datavalue'][
                'value']
        else:
            print(
                '*** Something is wrong with this supposed creator literal statement'
            )
            time.sleep(10)

        newStatement = lwb.updateclaim(bibitemqid, newprop, creatorqid, "item")
        lwb.setqualifier(bibitemqid, newprop, newStatement, "P33", listpos,
                         "string")
        lwb.setqualifier(bibitemqid, newprop, newStatement, "P67",
                         item["firstName"] + " " + item["lastName"], "string")
        if creatorPrefLabel != item['firstName'] + " " + item['lastName']:
            lwb.setlabel(creatorqid,
                         "en",
                         item['firstName'] + " " + item['lastName'],
                         type="alias")
        lwb.removeclaim(oldStatement)

        time.sleep(1)
        count += 1
                try:
                    r = requests.get(
                        "https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&props=labels&ids="
                        + wdqid + "&languages=en").json()
                    #print(str(r))
                    if "labels" in r['entities'][wdqid]:
                        label = r['entities'][wdqid]['labels']['en']['value']
                        done = True

                except Exception as ex:
                    print(
                        'Wikidata: Getlabels operation failed, will try again...\n'
                        + str(ex))
                    time.sleep(4)

            lwb.setlabel(lwbqid, "en", label)
            itemcount += 1
    else:
        # get wikidata equivalent prop
        wdprop = lwb.getclaims(prop, "P2")
        if bool(wdprop):
            wdprop = wdprop['P2'][0]['mainsnak']['datavalue']['value'].replace(
                "http://www.wikidata.org/entity/", "")
            print('Wikidata Prop for LWB prop ' + prop + ' is: ' + wdprop)
        else:
            print('*** No equivalent Wikidata property found for ' + prop +
                  '.')
            continue
        itemcount = 1
        for item in lwbitems:
            print('\nItem [' + str(itemcount) + '], ' +
Beispiel #8
0
url = "https://data.lexbib.org/query/sparql?format=json&query=PREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20lwb%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fentity%2F%3E%0APREFIX%20ldp%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fprop%2Fdirect%2F%3E%0APREFIX%20lp%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fprop%2F%3E%0APREFIX%20lps%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fprop%2Fstatement%2F%3E%0APREFIX%20lpq%3A%20%3Chttp%3A%2F%2Fdata.lexbib.org%2Fprop%2Fqualifier%2F%3E%0A%0Aselect%20distinct%20%3Fauthor%20%3FauthorLabel%20%3Fauthornamevar%20%0Awhere%20%7B%0A%20%20%3Fauthor%20ldp%3AP5%20lwb%3AQ5%20.%0A%20%20%3Fauthor%20rdfs%3Alabel%20%3FauthorLabel%20.%0A%20%20%3FbibItem%20lp%3AP12%20%3Fauthorstatement%20.%0A%20%20%3Fauthorstatement%20lps%3AP12%20%3Fauthor%20.%0A%20%20%3Fauthorstatement%20lpq%3AP67%20%3Fauthornamevar%20.%0A%20%20FILTER%20%28str%28%3Fauthornamevar%29%20%21%3D%20str%28%3FauthorLabel%29%29%0A%20%0A%20%20%0A%20%20%7D%20ORDER%20BY%20%3Fauthor%20%3FauthorLabel%20%3Fauthornamevar%20"

done = False
while (not done):
    try:
        r = requests.get(url)
        bindings = r.json()['results']['bindings']
    except Exception as ex:
        print('Error: SPARQL request failed: ' + str(ex))
        time.sleep(2)
        continue
    done = True
#print(str(bindings))

print(
    'Found ' + str(len(bindings)) +
    ' creator name variants (that do not match with the author prefLabel)...\n'
)
time.sleep(3)

count = 0
for item in bindings:
    count += 1
    creatorqid = item['author']['value'].replace(
        "http://data.lexbib.org/entity/", "")
    namevar = item['authornamevar']['value']
    altlabel = lwb.setlabel(creatorqid, "en", namevar, type="alias")
    if altlabel:
        print('OK. ' + str(len(bindings) - count) + ' namevars left.\n')
Beispiel #9
0
import json
import lwb

with open('D:/LexBib/countries/query.json', encoding="utf-8") as f:
    dict = json.load(f)

count = 0
for item in dict:
    count += 1
    lwbqid = lwb.getqid("Q8654", item['country'])
    lwb.setlabel(lwbqid, "en", item['countryLabel'])
    lwb.stringclaim(lwbqid, "P4", item['country'])

    print('OK. ' + str(len(dict) - count) + ' countries left.')