Skip to content

Commit 1282515

Browse files
committed
updates
1 parent fde4fb8 commit 1282515

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

addTriplesToRdfFile.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@
5454
prefLabel = row['standardizedLabel']
5555
try:
5656
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([])
6061
except:
6162
uriNum += 1
6263
subjectUri = 'http://www.library.jhu.edu/identities/'+str(uriNum)
6364
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])
6568
g.add((URIRef(subjectUri), DC.date, Literal(date)))
6669
existingLabels[prefLabel] = subjectUri
6770
f.writerow([subjectUri]+[SKOS.prefLabel]+[prefLabel])
68-
f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel])
6971
f.writerow([subjectUri]+[DC.date]+[date])
7072
f.writerow([])
7173

@@ -76,12 +78,18 @@
7678
#extract altLabels and prefLabels to csv
7779
f=csv.writer(open('labelFindAndReplace.csv','wb'))
7880
f.writerow(['replacedValue']+['replacementValue'])
79-
8081
q = prepareQuery('SELECT ?altLabel ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel. ?s skos:altLabel ?altLabel }', initNs = {'skos': SKOS})
8182
results = g.query(q)
8283
for row in results:
8384
f.writerow([row[0].encode('utf-8')]+[row[1].encode('utf-8')])
8485

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+
8593
elapsedTime = time.time() - startTime
8694
m, s = divmod(elapsedTime, 60)
8795
h, m = divmod(m, 60)

buildRdfFile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
else:
1919
fileName = raw_input('Enter the file name of the CSV of source data (including \'.csv\'): ')
2020

21-
fileName = 'editedFacultyNamesUpdated.csv'
22-
2321
startTime = time.time()
2422
date = datetime.datetime.today().strftime('%Y-%m-%d')
2523
nameUriDict = {}
@@ -41,12 +39,14 @@
4139
date = date
4240
try:
4341
subjectUri = nameUriDict[prefLabel]
44-
g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel)))
42+
if altLabel != prefLabel and altLabel != '':
43+
g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel)))
4544
except:
4645
uriNum += 1
4746
subjectUri = 'http://www.library.jhu.edu/identities/'+str(uriNum)
4847
g.add((URIRef(subjectUri), SKOS.prefLabel, Literal(prefLabel)))
49-
g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel)))
48+
if altLabel != prefLabel:
49+
g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel)))
5050
g.add((URIRef(subjectUri), DC.date, Literal(date)))
5151
nameUriDict[prefLabel] = subjectUri
5252

0 commit comments

Comments
 (0)