-
Notifications
You must be signed in to change notification settings - Fork 2
/
view2.html
287 lines (232 loc) · 8.19 KB
/
view2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="diff_match_patch_uncompressed.js"></script>
<script src="papaparse.min.js" type="text/javascript"></script>
<style>
body{
height: 100vh;
padding: 0;
margin: 0;
}
.outerWrapper {
/* border-top: 1px solid black;
padding: 10px; */
flex-grow: 1;
flex-basis: 0;
height: 100vh;
overflow: scroll
}
#textWrapper {
display: flex;
justify-content: space-between;
height: 100vh;
}
.navBar{
padding: 10px;
margin: 5px;
border-bottom: 1px dotted black;
}
.relatedItem{
}
.text{
padding: 10px;
margin: 10px;
transition: all .5s ease-in-out;
-webkit-transition: all .5s ease-in-out;
}
.label{
font-weight: bold;
padding-right: 2px;
cursor: pointer;
}
.selected{
position: fixed;
top: 10vh;
height: 60vh;
left: 10%;
width: 70%;
background-color: white;
font-size: 25px;
line-height: 200%;
padding: 5%;
box-shadow: 10px 10px 8px 10px #888888;
overflow: scroll;
transition: all 1s ease-in-out;
-webkit-transition: all 1s ease-in-out;
}
</style>
</head>
<body>
<div id="textWrapper">
<div class="outerWrapper">
<div class="navbar"></div>
<div id="BaseContainerDiv" class="relatedItem"><img class="spinner" src="http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif"/></div>
</div>
</div>
<script>
function State() {
this.baseText = "";
}
function getUrlVar() {
var result = {};
var location = window.location.href.split('#');
var parts = location[0].replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
result [key] = value;
});
return result;
}
//get manifestations (loop through manifestsions, add promises to array)
const sparqlEndpoint = "http://sparql-docker.scta.info/ds/query"
function displayCollation(blockId, wrapper, baseTextSlug, state){
var query = [
"SELECT ?transcription ?next ?previous ?shortId ",
"WHERE",
"{",
"<" + blockId + "> <http://scta.info/property/isPartOfStructureItem> ?item .",
"OPTIONAL {",
"<" + blockId + "> <http://scta.info/property/next> ?next .",
"}",
"OPTIONAL {",
"<" + blockId + "> <http://scta.info/property/previous> ?previous .",
"}",
"?item <http://scta.info/property/hasManifestation> ?manifestation .",
"?manifestation <http://scta.info/property/hasTranscription> ?transcription .",
"<" + blockId + "> <http://scta.info/property/shortId> ?shortId .",
"}"].join('');
$.get(sparqlEndpoint, {query: query}, function(data){
var results = data.results.bindings;
$("#" + wrapper).prev(".navbar").append("Collation for " + blockId);
if (results[0].previous){
$("#" + wrapper).prev(".navbar").append("<a href='?id=" + results[0].previous.value + "&m=" + baseTextSlug + "'> Previous </a> | ");
}
if (results[0].next){
$("#" + wrapper).prev(".navbar").append("<a href='?id=" + results[0].next.value + "&m=" + baseTextSlug + "'>Next </a> ");
}
promiseArray = results.map(function(r){
var textPromise = new Promise(function(resolve, reject){
var urlSlug = r.transcription.value.split("http://scta.info/resource/")[1]
$.get("https://exist.scta.info/exist/apps/scta-app/csv/" + urlSlug, function(data){
var parsedData = Papa.parse(data);
var hashTable = {}
parsedData.data.forEach(function(d){
hashTable[d[0]] = d[1]
});
var dataObject = {
"text": hashTable[r.shortId.value],
"id": r.transcription.value.split("/")[5]
}
resolve(dataObject)
});
});
return textPromise
});
Promise.all(promiseArray).then(function(values){
let baseText = ""
let counterStart = 0
if (!state.baseText){
const base = values.find((o) => {
if (o.id === baseTextSlug)
return o
})
baseText = base ? base.text : values[0].text
baseTextId = base ? base.id : values[0].id
$(".spinner").remove()
$("#" + wrapper).append("<div class='text'><span class='label'>" + baseTextId + "</span>" + baseText + "</div>")
state.baseText = baseText
counterStart++
}
else{
baseText = state.baseText
}
values.forEach(function(v){
if (v.id != baseTextId){
displayText = runGoogleDiffPatch(baseText, v.text, v.id)
const link = "view2.html?id=" + blockId + "&m=" + v.id
$(".spinner").remove()
$("#" + wrapper).append("<div class='text'><a href='" + link + "' class='label' data-id='" + v.id + "'>" + v.id + "</a>" + displayText + "</div>")
}
})
});
});
}
function runGoogleDiffPatch(base, compare, id){
const dmp = new diff_match_patch();
//const diff = dmp.diff_main(base, compare); basic character level div
const diff = diff_wordMode(base.toLowerCase(), compare.toLowerCase()) // word level diff
// Result: [(-1, "Hell"), (1, "G"), (0, "o"), (1, "odbye"), (0, " World.")]
console.log(diff)
const diffArray = diff.map((d, i) => {
if (d[0] !== 0){
const diff = {
id: id + "." + i,
diff: d,
}
return diff
}
})
const newArray = diffArray.filter(function(val) { return val !== undefined; })
console.log(newArray)
//dmp.diff_cleanupSemantic(diff);
//console.log(test)
const ds = dmp.diff_prettyHtml(diff);
// Result: [(-1, "Hello"), (1, "Goodbye"), (0, " World.")]
return ds
}
function diff_wordMode(text1, text2) {
var dmp = new diff_match_patch();
var a = dmp.diff_wordsToChars_(text1, text2);
var lineText1 = a.chars1;
var lineText2 = a.chars2;
var lineArray = a.lineArray;
var diffs = dmp.diff_main(lineText1, lineText2, false);
dmp.diff_charsToLines_(diffs, lineArray);
return diffs;
}
function displayRelated(blockId){
const isRelatedToQuery = [
"SELECT ?isRelatedTo ?shortId ",
"WHERE",
"{",
"{",
"<" + blockId + "> <http://scta.info/property/isRelatedTo> ?isRelatedTo .",
"}",
"UNION",
"{",
"<" + blockId + "> <http://scta.info/property/abbreviates> ?isRelatedTo .",
"}",
"UNION",
"{",
"<" + blockId + "> <http://scta.info/property/abbreviatedBy> ?isRelatedTo .",
"}",
"?isRelatedTo <http://scta.info/property/shortId> ?shortId .",
"}"].join('');
$.get(sparqlEndpoint, {query: isRelatedToQuery}, function(data){
const results = data.results.bindings;
results.forEach(function(item){
$("#textWrapper").append("<div class='outerWrapper'><div class='navbar'></div><div id='" + item.shortId.value + "' class='relatedItem'>" + item.isRelatedTo.value + "</div></div>");
});
});
}
$(document).ready(function(){
var state = new State();
var baseTextSlug = getUrlVar()['m'];
var blockId = getUrlVar()['id'];
$(document).on("click", ".relatedItem", function(e){
shortId = e.target.id
url = e.target.innerText
$("#" + shortId).html("<img class='spinner' src='http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif'/>");
displayCollation(url, shortId, baseTextSlug, state)
});
$(document).on("click", ".text", function(e){
$(this).toggleClass("selected");
})
displayCollation(blockId, "BaseContainerDiv", baseTextSlug, state)
displayRelated(blockId)
});
</script>
</body>
</html>