Skip to content

Commit

Permalink
Add a few more pieces to download locally instead of from nlp
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Nov 7, 2024
1 parent f55cdf8 commit 558070b
Show file tree
Hide file tree
Showing 6 changed files with 1,009 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,10 @@ public void run(Optional<Pair<String,String>> basicAuth,
withAuth(server.createContext(uriContext+"/static/fonts/Astloch-Bold.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/Astloch-Bold.ttf", "font/ttfx")), basicAuth);
withAuth(server.createContext(uriContext+"/static/fonts/Liberation_Sans-Regular.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/LiberationSans-Regular.ttf", "font/ttf")), basicAuth);
withAuth(server.createContext(uriContext+"/static/fonts/PT_Sans-Caption-Web-Regular.ttf", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/PTSansCaption-Regular.ttf", "font/ttf")), basicAuth);
withAuth(server.createContext(uriContext+"/configuration.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/configuration.js", "application/javascript")), basicAuth);
withAuth(server.createContext(uriContext+"/dispatcher.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/dispatcher.js", "application/javascript")), basicAuth);
withAuth(server.createContext(uriContext+"/util.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/util.js", "application/javascript")), basicAuth);
withAuth(server.createContext(uriContext+"/url_monitor.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/url_monitor.js", "application/javascript")), basicAuth);
withAuth(server.createContext(uriContext+"/visualizer.js", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/visualizer.js", "application/javascript")), basicAuth);
withAuth(server.createContext(uriContext+"/img/corenlp-title.png", new BytesFileHandler("edu/stanford/nlp/pipeline/demo/corenlp-title.png", "image/png")), basicAuth);
withAuth(server.createContext(uriContext+"/ping", new PingHandler()), Optional.empty());
Expand Down
29 changes: 29 additions & 0 deletions src/edu/stanford/nlp/pipeline/demo/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; -*-
// vim:set ft=javascript ts=2 sw=2 sts=2 cindent:
var Configuration = (function(window, undefined) {
var abbrevsOn = true;
var textBackgrounds = "striped";
var svgWidth = '100%';
var rapidModeOn = false;
var confirmModeOn = true;
var autorefreshOn = false;

var visual = {
margin: { x: 2, y: 1 },
arcTextMargin: 1,
boxSpacing: 1,
curlyHeight: 4,
arcSpacing: 9, //10;
arcStartHeight: 19, //23; //25;
}

return {
abbrevsOn: abbrevsOn,
textBackgrounds: textBackgrounds,
visual: visual,
svgWidth: svgWidth,
rapidModeOn: rapidModeOn,
confirmModeOn: confirmModeOn,
autorefreshOn: autorefreshOn,
};
})(window);
8 changes: 4 additions & 4 deletions src/edu/stanford/nlp/pipeline/demo/corenlp-brat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ head.js(
bratLocation + '/client/lib/jquery.svgdom.min.js',

// brat helper modules
bratLocation + '/client/src/configuration.js',
bratLocation + '/client/src/util.js',
'./configuration.js',
'./util.js',
bratLocation + '/client/src/annotation_log.js',
bratLocation + '/client/lib/webfont.js',

// brat modules
bratLocation + '/client/src/dispatcher.js',
bratLocation + '/client/src/url_monitor.js',
'./dispatcher.js',
'./url_monitor.js',
'./visualizer.js',

// parse viewer
Expand Down
130 changes: 130 additions & 0 deletions src/edu/stanford/nlp/pipeline/demo/dispatcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; -*-
// vim:set ft=javascript ts=2 sw=2 sts=2 cindent:
// TODO: does 'arguments.callee.caller' work?

var Dispatcher = (function($, window, undefined) {
var Dispatcher = function() {
var that = this;

var table = {};

var on = function(message, host, handler) {
if (handler === undefined) {
handler = host;
host = arguments.callee.caller;
}
if (table[message] === undefined) {
table[message] = [];
}
table[message].push([host, handler]);
return this;
};

// Notify listeners that we encountered an error in an asynch call
var inAsynchError = false; // To avoid error avalanches
var handleAsynchError = function(e) {
if (!inAsynchError) {
inAsynchError = true;
// TODO: Hook printout into dispatch elsewhere?
console.warn('Handled async error:', e);
that.post('dispatchAsynchError', [e]);
inAsynchError = false;
} else {
console.warn('Dropped asynch error:', e);
}
};

var post = function(asynch, message, args, returnType) {
if (typeof(asynch) !== 'number') {
// no asynch parameter
returnType = args;
args = message;
message = asynch;
asynch = null;
}
if (args === undefined) {
args = [];
}
var results = [];
// DEBUG: if (typeof(message) != "string" || !(message.match(/mouse/) || message == "hideComment")) console.log(message, args);

if (typeof(message) === 'function') {
// someone was lazy and sent a simple function
var host = arguments.callee.caller;
if (asynch !== null) {
result = setTimeout(function() {
try {
message.apply(host, args);
} catch(e) {
that.handleAsynchError(e);
}
}, asynch);
} else {
result = message.apply(host, args);
}
results.push(result);
} else {
// a proper message, propagate to all interested parties
var todo = table[message];
if (todo !== undefined) {
$.each(todo, function(itemNo, item) {
var result;
if (asynch !== null) {
result = setTimeout(function() {
try {
item[1].apply(item[0], args);
} catch (e) {
that.handleAsynchError(e);
}
}, asynch);
} else {
result = item[1].apply(item[0], args);
}
results.push(result);
});
/* DEBUG
} else {
console.warn('Message ' + message + ' has no subscribers.'); // DEBUG
*/
}
}
if (returnType == 'any') {
var i = results.length;
while (i--) {
if (results[i] !== false) return results[i];
}
return false;
}
if (returnType == 'all') {
var i = results.length;
while (i--) {
if (results[i] === false) return results[i];
}
}
return results;
};

var proxy = function(destination, message) {
this.on(message, function() {
destination.post(message, Array.prototype.slice.call(arguments));
});
};

var dispatcher = {
on: on,
post: post,
proxy: proxy,
};
Dispatcher.dispatchers.push(dispatcher);
return dispatcher;
};

Dispatcher.dispatchers = [];
Dispatcher.post = function(asynch, message, args, returnType) {
$.each(Dispatcher.dispatchers, function(dispatcherNo, dispatcher) {
dispatcher.post(asynch, message, args, returnType);
});
};

return Dispatcher;
})(jQuery, window);
Loading

0 comments on commit 558070b

Please sign in to comment.