Skip to content

Commit

Permalink
first implementation for the lemma and pos extraction. more controls …
Browse files Browse the repository at this point in the history
…should be applied #32
  • Loading branch information
MedKhem committed Mar 4, 2019
1 parent dc5580c commit ad585e8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
57 changes: 56 additions & 1 deletion src/main/webapp/grobid/grobid-dictionaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ var grobid = (function ($) {
$('#btn_download').bind('click', downloadDictionary);
$("#btn_download").hide();

$('#btn_download_lemmas').bind('click', downloadLemma);
$("#btn_download_lemmas").hide();


$('#btn_downloadBib').bind('click', downloadBibliography());
$("#btn_downloadBib").hide();

Expand Down Expand Up @@ -269,8 +273,17 @@ var grobid = (function ($) {
display += "</pre>";
$('#requestResult').html(display);
window.prettyPrint && prettyPrint();


$('#requestResult').show();
$("#btn_download").show();
var selectedDictionaryForm = $('#selectedFormService option:selected').attr('value');
console.log(selectedDictionaryForm);
if (selectedDictionaryForm == 'form' || selectedDictionaryForm == 'customisedForm'){
$('#btn_download_lemmas').show();
}else{
$('#btn_download_lemmas').hide();
}
}

function SubmitBibSuccesful(responseText, statusText, xhr) {
Expand Down Expand Up @@ -443,7 +456,7 @@ function processDictionaryChange() {
var xr = $('#selectedXrService option:selected').attr('value');
var subEntry = $('#selectedSubEntryService option:selected').attr('value');
var note = $('#selectedNoteService option:selected').attr('value');
console.log(form.concat('/').concat(sense).concat('/').concat(etym).concat('/').concat(re).concat('/').concat(xr).concat('/').concat(subEntry).concat('/').concat(note).concat('.processFullDictionary'));
// console.log(form.concat('/').concat(sense).concat('/').concat(etym).concat('/').concat(re).concat('/').concat(xr).concat('/').concat(subEntry).concat('/').concat(note).concat('.processFullDictionary'));

// createInputFile(selectedMacroLevel);
$('#refinedModels').show();
Expand Down Expand Up @@ -517,6 +530,48 @@ function downloadDictionary() {
return true;
});
}

function downloadLemma() {
var name = "export";
if ((document.getElementById("input").files[0].type == 'application/pdf') ||
(document.getElementById("input").files[0].name.endsWith(".pdf")) ||
(document.getElementById("input").files[0].name.endsWith(".PDF"))) {
name = document.getElementById("input").files[0].name;
}
var fileName = name + ".txt";
var a = document.createElement("a");



var parser, xmlDoc, segmentedBody, entryList;
parser = new DOMParser();
xmlDoc = parser.parseFromString(xmlToDownload,"application/xml");

entryList = xmlDoc.getElementsByTagName("entry");
console.log(entryList.length.toString());
// entryList = segmentedBody.getElementsByTagName("entry");
var lemmas = "";
var form, i;
for (i = 0; i< entryList.length; i++) {
form = entryList[i].getElementsByTagName("form")[0];

lemmas += form.getElementsByTagName("orth")[0].childNodes[0].nodeValue +" "+ entryList[i].getElementsByTagName("gramGrp")[0].getElementsByTagName("pos")[0].childNodes[0].nodeValue +"\n";
}
console.log(lemmas);


var file = new Blob([lemmas], {type: 'text/plain'});
var fileURL = URL.createObjectURL(file);
a.href = fileURL;
a.download = fileName;

document.body.appendChild(a);

$(a).ready(function () {
a.click();
return true;
});
}
function downloadBibliography() {
// var name = "export";
// if ((document.getElementById("input").files[1].type == 'application/pdf') ||
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ <h2><small>
<!--<td>&nbsp;</td><td colspan="2"><input id="checkOptimise" type="checkbox" class="btn" style="margin-bottom: 7px; font-size:0.9em" /> Optimise TEI rendering</td><br>-->
<!--</tr>-->
<tr>
<td>&nbsp;</td><td colspan="2"><input id="submitRequest" type="submit" name="Submit" class="btn"/> <input id="btn_download" class="btn" value="Download TEI Result"/></td>
<td>&nbsp;</td><td colspan="2"><input id="submitRequest" type="submit" name="Submit" class="btn"/> <input id="btn_download" class="btn" value="Download TEI Result"/>
<input style="width: 110px" id="btn_download_lemmas" class="btn" value="Get Lemmas"/></td>
</tr>

</table>
Expand Down

0 comments on commit ad585e8

Please sign in to comment.