-
Notifications
You must be signed in to change notification settings - Fork 5
/
verbTester.html
95 lines (94 loc) · 3.85 KB
/
verbTester.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
<html>
<head>
<meta charset="UTF-8">
<title>Verb Tester</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<span id='verb-count'>0</span> verbs in list (<span id='queue'>0</span> in queue)
<input id='regex' style='width: 100%'>
<span id='valid'><span id='matches'>0</span> matches</span>
<span id='invalid' style='color: darkred;'>Invalid regular expression: <span></span></span>
<table class='table'>
<thead>
<tr><th>Verb</th><th>´</th><th>Class</th><th>Root</th><th>Infinitive</th><th>Perfect</th><th>Supine</th><th>Parts</th></tr>
</thead>
<tbody></tbody>
</table>
<!-- <script src="//code.jquery.com/jquery-2.1.4.min.js"></script> -->
<script src="jquery.min.js"></script>
<script>var exports = {};</script>
<script src="verbFunctions.js"></script>
<script>
$(function($){
$('#regex').val(localStorage.verbRegex||'');
$.getJSON('output/verbs.json',function(verbs){
window.verbs = verbs;
$('#verb-count').text(verbs.length);
var $tbody = $('tbody');
var i=0;
var verbRegex = / v\. (?:[n|a]|inch|dep|impers|act|neutral)[\.,\s]/;
verbs.forEach(function(verb){
var parts = getVerbParts(verb.orthography, verb.verbMatch);
if(JSON.stringify(parts) != JSON.stringify(verb.parts)) {
console.info(verb.orthography + ' has changed');
if(JSON.stringify(verb.parts.supine) != JSON.stringify(parts.supine)) {
console.info(parts.supine + ' (' + verb.parts.supine + ')');
}
if(JSON.stringify(verb.parts.perfect) != JSON.stringify(parts.perfect)) {
console.info(parts.perfect + ' (' + verb.parts.perfect + ')');
}
}
verb.parts = parts;
var conjugation = conjugateVerb(parts);
var accentedParts = conjugation.map(function(orth){return orth.getAccentedForm(); });
var tr = $('<tr/>');
tr.append($('<td/>').text(verb.orthography).attr('title',conjugation.join(', ')));
tr.append($('<td/>').html(accentedParts.slice(0,2).join('<br>')).attr('title',accentedParts.join(', ')));
tr.append($('<td/>').text(verb.verbMatch[1] && verb.verbMatch[1].join(', ') || ''));
tr.append($('<td/>').text((parts.root || ['UNDETERMINED']).join(', ')));
tr.append($('<td/>').text((parts.infinitive || ['UNDETERMINED']).join(', ')));
tr.append($('<td/>').text((parts.perfect || ['UNDETERMINED']).join(', ')));
tr.append($('<td/>').text((parts.supine || ['UNDETERMINED']).join(', ')));
tr.append($('<td/>').text(verb.verbMatch.slice(2).join(' | ')));
var match = verbRegex.exec(verb.fullText);
if(!match) {
console.info(verb.fullText);
tr.show();
}
else {
verb.verbParts = verb.fullText.slice(0,match.index+match[0].length);
//tr.append($('<td/>').html(verb.verbParts.replace(verb.verbType,'<b>'+verb.verbType+'</b>')));
}
$tbody.append(tr);
});
$rows = $('tbody>tr');
//$('#regex').keyup();
});
var $rows = $('tbody>tr');
$('#regex').on('keyup', function(){
var curVal = localStorage.verbRegex = $(this).val();
var regex;
try {
regex = new RegExp(curVal,'i');
} catch(e) {
$('#valid').hide();
$('#invalid').text(e.toString()).show();
console.info(e);
return;
}
$('#valid').show(); $('#invalid').hide();
[].concat(verbs[0].verbMatch[2],verbs[0].verbMatch[3])
$('#matches').text(verbs.reduce(function(count, verb, index){
var match = [].concat(verb.verbMatch[2],verb.verbMatch[3]).reduce(function(matching, ending, index){
if(!matching && ending) return ending.match(regex);
return matching;
}, false);
var $row = $($rows.get(index)).toggle(!!match);
return count + (match? 1 : 0);
},0));
});
});
</script>
</body>
</html>