Skip to content

Commit 5225450

Browse files
committed
updates
1 parent 331b3cf commit 5225450

3 files changed

Lines changed: 102 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ Based on user input, adds triples to a specified RDF file from a specified CSV f
66
#### [buildRdfFile.py](buildRdfFile.py)
77
Based on user input, builds an RDF file from a specified CSV file.
88

9+
#### [rdfDataEntryForm.html](rdfDataEntryForm.html)
10+
A sample RDF data entry form that prompts the user for a CSV file containing URIs and labels that will be loaded into the "Subject" drop-down menu. The download button exports the RDF triples as a N-Triples file.
11+
912
#### [rdfFileReconciliation.py](rdfFileReconciliation.py)
1013
Based on user input, compares a specified CSV file to a specified RDF file and finds potential matches. A threshold may be specified, otherwise the script will default to 70 % similarity.

addTriplesToRdfFile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@
9898

9999
#extract prefLabels to csv
100100
f=csv.writer(open(os.path.join('prefLabels','prefLabels'+timeStamp+'.csv'),'wb'))
101-
f.writerow(['prefLabel'])
102-
q = prepareQuery('SELECT ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel }', initNs = {'skos': SKOS})
101+
f.writerow(['uri']+['prefLabel'])
102+
q = prepareQuery('SELECT ?s ?prefLabel WHERE { ?s skos:prefLabel ?prefLabel }', initNs = {'skos': SKOS})
103103
results = g.query(q)
104104
for row in results:
105-
f.writerow([row[0].encode('utf-8')])
105+
f.writerow([row[1].encode('utf-8')]+[row[0].encode('utf-8')])
106106

107107
#extract all triples to csv
108108
f=csv.writer(open(os.path.join('allTriples','allTriples'+timeStamp+'.csv'),'wb'))

rdfDataEntryForm.html

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>RDF Data Entry Form</title>
5+
<meta charset="UTF-8"></meta>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
8+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
9+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
10+
</head>
11+
<body>
12+
<h2 class="jumbotron">RDF Data Entry Form</h2>
13+
<input class="well" id="csv" type="file"></input>
14+
<table class="table table-bordered">
15+
<tr>
16+
</tr>
17+
<tr>
18+
<th><h3>Subject</h3></th>
19+
<th><h3>Predicate</h3></th>
20+
<th><h3>Object</h3></th>
21+
</tr>
22+
<tr>
23+
<td>
24+
<select id="subject">
25+
</select>
26+
</td>
27+
<td>
28+
<select id="predicate">
29+
<option value="http://www.w3.org/2004/02/skos/core#altLabel">skos:altLabel</option>
30+
<option value="http://www.w3.org/2004/02/skos/core#prefLabel">skos:prefLabel</option>
31+
</select>
32+
</td>
33+
<td>
34+
<textarea id="object"></textarea>
35+
</td>
36+
</tr>
37+
</table>
38+
39+
<h3>Add Triples</h3>
40+
<div class="well">
41+
<h4>File name</h4>
42+
<button onclick="addTriples()">Add Triples</button>
43+
<p id="display"><p>
44+
</div>
45+
46+
<h3>Download</h3>
47+
<form class="well" onsubmit="downloadRdf(this['name'].value, triplesRdf)">
48+
<input type="text" name="name" value="triples">
49+
<input type="submit" value="Download RDF">
50+
51+
<script>
52+
var subject = document.querySelector("#subject");
53+
var predicate = document.querySelector("#predicate")
54+
var object = document.querySelector("#object")
55+
var triplesRdf = ""
56+
var triplesHtml = ""
57+
58+
function addTriples() {
59+
triplesRdf = triplesRdf + "<" + subject.value + "> <" + predicate.value + "> \"" + object.value + "\".\r\n"
60+
triplesHtml = triplesHtml + "<p>" + subject.value + " -- " + predicate.value + " -- " + object.value + "</p>"
61+
document.querySelector("#display").innerHTML = triplesHtml
62+
}
63+
64+
function downloadRdf(filename, text) {
65+
var date = Date.now()
66+
var element = document.createElement('a');
67+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
68+
element.setAttribute('download', filename + ".nt");
69+
element.style.display = 'none';
70+
document.body.appendChild(element);
71+
element.click();
72+
document.body.removeChild(element);
73+
}
74+
75+
var fileInput = document.getElementById("csv")
76+
77+
readFile = function () {
78+
var reader = new FileReader();
79+
var select = document.querySelector("#subject")
80+
reader.onload = function () {
81+
var array = reader.result.split('\n');
82+
array.sort()
83+
for (i = 1; i < array.length; i++) {
84+
optionText = array[i].split('",')
85+
var optionElement = document.createElement("option");
86+
optionElement.text = optionText[0].replace("\"","");
87+
optionElement.value = String(optionText[1].replace("\"",""));
88+
select.appendChild(optionElement);
89+
}
90+
};
91+
reader.readAsText(fileInput.files[0]);
92+
};
93+
fileInput.addEventListener('change', readFile);
94+
</script>
95+
</body>
96+
</html>

0 commit comments

Comments
 (0)