|
24 | 24 | fileName = raw_input('Enter the CSV file of headings to reconcile (including \'.csv\'): ') |
25 | 25 |
|
26 | 26 | startTime = time.time() |
27 | | -date = datetime.datetime.today().strftime('%Y-%m-%d') |
| 27 | +date = datetime.datetime.now().strftime('%Y-%m-%d %H.%M.%S') |
28 | 28 |
|
29 | 29 | #import rdf file into graph |
30 | 30 | g = Graph() |
31 | 31 | g.parse(rdfFileName, format='n3') |
| 32 | +originalTripleCount = len(g) |
32 | 33 |
|
33 | 34 | #creating dict of existing labels for comparison |
34 | 35 | q = prepareQuery('SELECT ?s ?o WHERE { ?s skos:prefLabel ?o }', initNs = {'skos': SKOS}) |
|
62 | 63 | uriNum += 1 |
63 | 64 | subjectUri = 'http://www.library.jhu.edu/identities/'+str(uriNum) |
64 | 65 | g.add((URIRef(subjectUri), SKOS.prefLabel, Literal(prefLabel))) |
65 | | - if altLabel != prefLabel and altLabel != '': |
| 66 | + f.writerow([subjectUri]+[SKOS.prefLabel]+[prefLabel]) |
| 67 | + if altLabel != prefLabel: |
66 | 68 | g.add((URIRef(subjectUri), SKOS.altLabel, Literal(altLabel))) |
67 | 69 | f.writerow([subjectUri]+[SKOS.altLabel]+[altLabel]) |
68 | 70 | g.add((URIRef(subjectUri), DC.date, Literal(date))) |
69 | | - existingLabels[prefLabel] = subjectUri |
70 | | - f.writerow([subjectUri]+[SKOS.prefLabel]+[prefLabel]) |
71 | 71 | f.writerow([subjectUri]+[DC.date]+[date]) |
| 72 | + existingLabels[prefLabel] = subjectUri |
72 | 73 | f.writerow([]) |
73 | 74 |
|
74 | 75 | #create rdf file |
75 | 76 | g.serialize(format='n3', destination=open(rdfFileName[:rdfFileName.index('.')]+'Updated.n3','wb')) |
76 | 77 | print g.serialize(format='n3') |
| 78 | +print 'Original triples count: ', originalTripleCount |
| 79 | +print 'Updated triples count: ', len(g) |
77 | 80 |
|
78 | 81 | #extract altLabels and prefLabels to csv |
79 | | -f=csv.writer(open(rdfFileName[:rdfFileName.index('.')]+'labelFindAndReplace.csv','wb')) |
| 82 | +f=csv.writer(open(rdfFileName[:rdfFileName.index('.')]+'FindAndReplace.csv','wb')) |
80 | 83 | f.writerow(['replacedValue']+['replacementValue']) |
81 | 84 | q = prepareQuery('SELECT ?altLabel ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel. ?s skos:altLabel ?altLabel }', initNs = {'skos': SKOS}) |
82 | 85 | results = g.query(q) |
|
0 commit comments