Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User action logger #209

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions standalone/annotator.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ <h5 class="modal-title" id="helpModalLabel">User guide</h5>
<button id="enhanced" type="button" class="btn btn-outline-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
<i class="fa fa-tree" title="Toggle enhanced / basic dependencies"></i>
</button>
<button id="logger" type="button" class="btn btn-outline-primary" data-toggle="button" aria-pressed="false" autocomplete="off">
<i id="log" class="fa fa-video-camera" title="Enable / Disable Logger"></i>
</button>

</div>
<!--p>
Expand Down
1 change: 1 addition & 0 deletions standalone/lib/annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function bindHanlers() {
$("#indata").bind("keyup", fitTable);
$("#indata").bind("keyup", formatTabsView);
$("#RTL").on("click", switchRtlMode);
$("#logger").on("click", switchLogger);
$("#vertical").on("click", switchAlignment);
$("#enhanced").on("click", switchEnhanced);
document.getElementById('filename').addEventListener('change', loadFromFile, false);
Expand Down
11 changes: 10 additions & 1 deletion standalone/lib/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @param {String} text Input text (sentence)
* @return {String} Sentence in CoNLL-U format
*/
var anno_time = 0;
function plainSent2Conllu(text) {
// TODO: if there's punctuation in the middle of a sentence,
// indices shift when drawing an arc
Expand All @@ -14,7 +15,15 @@ function plainSent2Conllu(text) {
console.log('plainSent2Conllu() ' + text);

var sent = new conllu.Sentence();
var lines = ["# sent_id = _" + "\n# text = " + text]; // creating comment

// creating comments
var lines;
if (LOGGER_ENABLED) {
anno_time = Date.now(); // Get first edit time
lines = ["# sent_id = _" + "\n# text = " + text.replace('\n', '' + '\n# anno_time = ' + anno_time)];
} else {
lines = ["# sent_id = _" + "\n# text = " + text];
}
var tokens = text.split(" ");

// enumerating tokens
Expand Down
85 changes: 84 additions & 1 deletion standalone/lib/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ function writeArc(sourceNode, destNode) {
// For some reason we need all of this code otherwise stuff becomes undefined
var idx = findConlluId(destNode)[1];
var sent = buildSent();

// Log changes
var outerIndex = indices[1];
var innerIndex = indices[2];
logger(sent, outerIndex, innerIndex)

var tokens = sent.tokens;
console.log(idx + ' ' + tokens);
var thisToken = tokens[idx];
Expand Down Expand Up @@ -449,8 +455,12 @@ function writeDeprel(deprelInp, indices) { // TODO: DRY
}

var sent = buildSent();


// Log changes
var outerIndex = indices[1];
var innerIndex = indices[2];
logger(sent, outerIndex, innerIndex);

var cur = parseInt(sent.tokens[outerIndex].id);
var head = parseInt(sent.tokens[outerIndex].head);
console.log('writeDeprel');
Expand Down Expand Up @@ -554,6 +564,72 @@ function writeWF(wfInp) {
}
}

function logger(sent, outerIndex, innerIndex) {
// Log last changed time
if (LOGGER_ENABLED) {
var hasTimeSet = true;

var unixTime = Date.now();
var timeDelta;
if(anno_time == 0) {
anno_time = Date.now();
hasTimeSet = false;
}
timeDelta = unixTime - anno_time;

if(innerIndex != undefined) {
var misc = sent.tokens[outerIndex].tokens[innerIndex].misc;
if(misc != undefined) {
if(misc.indexOf('AnnoTime=') != -1) {
var finalMiscContent = '';

if(misc.indexOf('|') != -1) {
var miscContent = misc.split('|');
for(var i = 0; i < miscContent.length; i++) {
if(miscContent[i].startsWith('AnnoTime=')) {
miscContent[i] += ',' + timeDelta;
}
}
finalMiscContent = miscContent.join("|");
} else {
finalMiscContent = misc + ',' + timeDelta;
}
sent.tokens[outerIndex].tokens[innerIndex].misc = finalMiscContent;
} else {
sent.tokens[outerIndex].tokens[innerIndex].misc += '|AnnoTime=' + timeDelta;
sent.tokens[outerIndex].tokens[innerIndex].misc = sent.tokens[outerIndex].tokens[innerIndex].misc.replace(/\|\|/g, '|');
}
} else {
sent.tokens[outerIndex].tokens[innerIndex].misc = 'AnnoTime=' + timeDelta;
}
} else {
var misc = sent.tokens[outerIndex].misc;
if(misc != undefined) {
if(misc.indexOf('AnnoTime=') != -1) {
var finalMiscContent = '';

if(misc.indexOf('|') != -1) {
var miscContent = misc.split('|');
for(var i = 0; i < miscContent.length; i++) {
if(miscContent[i].startsWith('AnnoTime=')) {
miscContent[i] += ',' + timeDelta;
}
}
finalMiscContent = miscContent.join("|");
} else {
finalMiscContent = misc + ',' + timeDelta;
}
sent.tokens[outerIndex].misc = finalMiscContent;
} else {
sent.tokens[outerIndex].misc += '|AnnoTime=' + timeDelta;
sent.tokens[outerIndex].misc = sent.tokens[outerIndex].misc.replace(/\|\|/g, '|');
}
} else {
sent.tokens[outerIndex].misc = 'AnnoTime=' + timeDelta;
}
}
}
}

function findConlluId(wfNode) { // TODO: refactor the arcitecture.
// takes a cy wf node
Expand Down Expand Up @@ -861,6 +937,13 @@ function switchRtlMode() {
drawTree();
}

function switchLogger() {
if (LOGGER_ENABLED) {
LOGGER_ENABLED = false;
} else {
LOGGER_ENABLED = true;
}
}

function switchAlignment() {
$('#vertical .fa').toggleClass('fa-rotate-90');
Expand Down
1 change: 1 addition & 0 deletions standalone/lib/visualiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var VERT_ALIGNMENT = false;
var LEFT_TO_RIGHT = true;
var LOGGER_ENABLED = false;
var ACTIVE = "#2653c9";
var NORMAL = "#7fa2ff";
var FANCY = "#cc22fc";
Expand Down