Skip to content
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__
.pyc
.env
Pipfile*
.DS_Store
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Other contributors
Francis Tyers (@ftyers)
Sushain Cherivirala (@sushain97)
Kevin Brubeck Unhammer (@unhammer)
Kevin Murphy (@keggsmurph21)
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
certifi==2018.1.18
chardet==3.0.4
click==6.7
Flask==0.12.2
GitHub-Flask==3.2.0
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
requests==2.18.4
urllib3==1.22
Werkzeug==0.14.1
20 changes: 20 additions & 0 deletions server/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

class Env():
def __init__(self, filepath):
self.variables = {}
self.read(filepath)

def read(self, filepath):
with open(filepath) as f:
for line in f.readlines():
key,value = line.split('=')
self.variables[key] = value.strip('\n')

def get(self, key):
if key in self.variables:
return self.variables[key]
return None

def __repr__(self):
return str(self.variables)
30 changes: 29 additions & 1 deletion server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
from flask import send_file
from flask import send_from_directory
from flask import url_for
from flask_github import GitHub

import os
import uuid
from db import CorpusDB
from env import Env


PATH_TO_CORPORA = 'corpora'
Expand All @@ -25,7 +28,11 @@
*******************************************************************************
'''

environment = Env('.env')
app = Flask(__name__, static_folder='../standalone', static_url_path='/annotatrix')
app.config['GITHUB_CLIENT_ID'] = '2aed75d6a4e13b9dd029'
app.config['GITHUB_CLIENT_SECRET'] = environment.get('GITHUB_CLIENT_SECRET')
github = GitHub(app)

if not os.path.exists(PATH_TO_CORPORA):
os.mkdir(PATH_TO_CORPORA)
Expand Down Expand Up @@ -69,7 +76,7 @@ def download_corpus():
if os.path.exists(PATH_TO_CORPORA + '/' + db_path):
db = CorpusDB(PATH_TO_CORPORA + '/' + db_path)
corpus, corpus_name = db.get_file()
with open(PATH_TO_CORPORA + '/' + treebank_id, 'w') as f:
with open(PATH_TO_CORPORA + '/' + treebank_id, 'w') as f:
f.write(corpus)
return send_file(PATH_TO_CORPORA + '/' + treebank_id, as_attachment=True, attachment_filename=corpus_name)
return jsonify({'corpus': 'something went wrong'})
Expand Down Expand Up @@ -103,7 +110,28 @@ def annotatrix():
def index():
return send_from_directory('../standalone', 'welcome_page.html')

@app.route('/login', methods=['GET', 'POST'])
def login():
return github.authorize()

@app.route('/github-callback', methods=['GET', 'POST'])
@github.authorized_handler
def authorized(oauth_token):
print('token', oauth_token)

next_url = request.args.get('next') or url_for('index')
if oauth_token is None:
return redirect(next_url)

'''
user = User.query.filter_by(github_access_token=oauth_token).first()
if user is None:
user = User(oauth_token)
db_session.add(user)

user.github_access_token = oauth_token
db_session.commit()'''
return redirect(next_url)
# @app.route('/<treebank_id>', methods=['GET', 'POST'])
# def index_corpus(treebank_id):
# return redirect(url_for('corpus_page', treebank_id=treebank_id))
Expand Down
39 changes: 25 additions & 14 deletions standalone/lib/annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ function getContents() {
// // TODO: implement
// } else {
var splitted = localStorage.getItem('treebank'); // TODO: implement a more memory-friendly func?
splitted = JSON.parse(splitted); // string to array
splitted = JSON.parse(splitted) || {}; // string to array
splitted[CURRENTSENTENCE] = $("#indata").val();
localStorage.setItem('treebank', JSON.stringify(splitted)); // update the treebank
return splitted.join('\n\n');
// return splitted.join('\n\n'); NOTE: doesn't make sense to call .join() on an Object ...
// }
}

Expand Down Expand Up @@ -140,6 +140,7 @@ function bindCyHandlers() {
/* Binds event handlers to cy elements.
NOTE: If you change the style of a node (e.g. its selector) then
you also need to update it here. */
cy.on('click', 'node, edge', clickInCy);
cy.on('click', 'node.wf', drawArcs);
cy.on('cxttapend', 'edge.dependency', selectArc);
cy.on('click', 'node.pos', changeNode);
Expand All @@ -149,6 +150,16 @@ function bindCyHandlers() {
cy.on('zoom', cy.center); // center the view port when the page zoom is changed
}

function clickInCy() {
console.log(this);

let oldValue = $('#edit').attr( 'value' );
let newValue = $('#edit').val();

if ( ISEDITING && (oldValue!==newValue) )
writePOS( newValue );
}


function loadFromUrl(argument) {
/* Check if the URL contains arguments. If it does, takes first
Expand Down Expand Up @@ -290,9 +301,9 @@ function splitIntoSentences(corpus) {

// splitting
if (format == "plain text") {
var splitted = corpus.match(/[^ ].+?[.!?](?=( |$))/g);
var splitted = corpus.match(/[^ ].+?[.!?](?=( |$))/g) || [];
} else {
var splitted = corpus.split("\n\n");
var splitted = corpus.split("\n\n") || [];
}

// removing empty lines
Expand All @@ -316,7 +327,7 @@ function showDataIndiv() {
}
if(AVAILABLESENTENCES != 0) {
document.getElementById('currentsen').value = (CURRENTSENTENCE+1);
} else {
} else {
document.getElementById('currentsen').value = 0;
}
document.getElementById('totalsen').innerHTML = AVAILABLESENTENCES;
Expand Down Expand Up @@ -432,7 +443,7 @@ function exportCorpora() {
if (SERVER_RUNNING) {
console.log('exportCorpora');
downloadCorpus();
} else {
} else {
var finalcontent = getContents();

var link = document.createElement('a');
Expand Down Expand Up @@ -468,16 +479,16 @@ function drawTree() {
1. removes the previous tree, if there's one
2. takes the data from the textarea
3. */

ISEDITING = false;

// TODO: update the sentence
try {cy.destroy()} catch (err) {}; // remove the previous tree, if there is one

var content = $("#indata").val(); // TODO: rename
var format = detectFormat(content);

// -- to be moved out--
// -- to be moved out--
// content = content.replace(/ +\n/, '\n'); // remove extra spaces at the end of lines. #89
// $("#indata").val(content); // TODO: what is this line for?

Expand Down Expand Up @@ -505,13 +516,13 @@ function drawTree() {
var newContent = cleanConllu(content); // TODO: move this one inside of this func

// If there are >1 CoNLL-U format sentences is in the input, treat them as such
// conlluMultiInput(newContent); // TODO: move this one also inside of this func, and make a separate func for calling them all at the same time
// conlluMultiInput(newContent); // TODO: move this one also inside of this func, and make a separate func for calling them all at the same time

if(newContent != content) {
content = newContent;
$("#indata").val(content);
}
// -- to be moved out --
// -- to be moved out --

conlluDraw(content);
showProgress();
Expand Down Expand Up @@ -557,7 +568,7 @@ function detectFormat(content) {
// console.log('[0] detectFormat() WARNING EMPTY CONTENT');
return "Unknown";
}

var firstWord = content.replace(/\n/g, " ").split(" ")[0];

//console.log('[0] detectFormat() ' + content.length + " | " + FORMAT);
Expand Down Expand Up @@ -677,12 +688,12 @@ function getLocalStorageMaxSize(error) {
minimalFound = 0,
error = error || 25e4;

// fill a string with 1024 symbols / bytes
// fill a string with 1024 symbols / bytes
while (i--) string1024 += 1e16;

i = max / 1024;

// fill a string with 'max' amount of symbols / bytes
// fill a string with 'max' amount of symbols / bytes
while (i--) string += string1024;

i = max;
Expand Down
Loading