|
54 | 54 | prefLabel = row['standardizedLabel'] |
55 | 55 | try: |
56 | 56 | subjectUri = existingLabels[prefLabel] |
57 | | - g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel))) |
58 | | - f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel]) |
59 | | - f.writerow([]) |
| 57 | + if altLabel != prefLabel and altLabel != '': |
| 58 | + g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel))) |
| 59 | + f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel]) |
| 60 | + f.writerow([]) |
60 | 61 | except: |
61 | 62 | uriNum += 1 |
62 | 63 | subjectUri = 'http://www.library.jhu.edu/identities/'+str(uriNum) |
63 | 64 | g.add((URIRef(subjectUri), SKOS.prefLabel, Literal(prefLabel))) |
64 | | - g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel))) |
| 65 | + if altLabel != prefLabel and altLabel != '': |
| 66 | + g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel))) |
| 67 | + f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel]) |
65 | 68 | g.add((URIRef(subjectUri), DC.date, Literal(date))) |
66 | 69 | existingLabels[prefLabel] = subjectUri |
67 | 70 | f.writerow([subjectUri]+[SKOS.prefLabel]+[prefLabel]) |
68 | | - f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel]) |
69 | 71 | f.writerow([subjectUri]+[DC.date]+[date]) |
70 | 72 | f.writerow([]) |
71 | 73 |
|
|
76 | 78 | #extract altLabels and prefLabels to csv |
77 | 79 | f=csv.writer(open('labelFindAndReplace.csv','wb')) |
78 | 80 | f.writerow(['replacedValue']+['replacementValue']) |
79 | | - |
80 | 81 | q = prepareQuery('SELECT ?altLabel ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel. ?s skos:altLabel ?altLabel }', initNs = {'skos': SKOS}) |
81 | 82 | results = g.query(q) |
82 | 83 | for row in results: |
83 | 84 | f.writerow([row[0].encode('utf-8')]+[row[1].encode('utf-8')]) |
84 | 85 |
|
| 86 | +f=csv.writer(open('prefLabels.csv','wb')) |
| 87 | +f.writerow(['prefLabel']) |
| 88 | +q = prepareQuery('SELECT ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel}', initNs = {'skos': SKOS}) |
| 89 | +results = g.query(q) |
| 90 | +for row in results: |
| 91 | + f.writerow([row[0].encode('utf-8')]) |
| 92 | + |
85 | 93 | elapsedTime = time.time() - startTime |
86 | 94 | m, s = divmod(elapsedTime, 60) |
87 | 95 | h, m = divmod(m, 60) |
|
0 commit comments