Skip to content

Commit 81329cc

Browse files
author
Nico Colic
committed
tidied up HTML (fixes TextAE display problem), and a few typos
1 parent bee6d0e commit 81329cc

File tree

4 files changed

+96
-118
lines changed

4 files changed

+96
-118
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Informal evaluation shows that the time for each request grows linearly in size,
3636
## Launching server
3737
The script *launch.sh* takes care of launching both the Stanford server and the accessor.py. If *tmux* is installed, it will try to launch these process in a new tmux session so that the shell can be closed without stopping the processes necessary for the server. Run the script as follows:
3838

39-
`./launch.sh`
39+
`./launch.sh` or `./launch.sh -v`
4040

4141
Alternatively, you can start the processes manually. From the *stanford* directory, the server can be launched as follows:
4242

accessor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def rest():
122122
try:
123123
json_ = text_to_json(request.args['text'])
124124
pretty_json = json.dumps(str(json.loads(json_)),sort_keys=True,indent=4)
125-
return(render_template('index.html',json=json_,pretty_json=pretty_json,input_text=request.args['text']),200)
125+
return(render_template('index.html',json=json_,
126+
pretty_json=pretty_json,
127+
input_text=request.args['text']),200)
126128

127129
except Exception as e:
128130
error_log(e)

launch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ else
4747
# Detach
4848
tmux send -t 'Stanford + spaCy accessor' "python3 accessor.py" C-b d
4949

50-
echo "ready to rumble. Use 'tmux attach -t 'Stanford + spaCy accessor' to see session."
50+
echo "ready to rumble. Use \"tmux attach -t 'Stanford + spaCy accessor'\""{'denotations': [{'id': 'T0', 'obj': 'JJ', 'span': {'begin': 0, 'end': 4}}, {'id': 'T1', 'obj': 'PRP', 'span': {'begin': 5, 'end': 6}}, {'id': 'T2', 'obj': 'VBD', 'span': {'begin': 7, 'end': 15}}, {'id': 'T3', 'obj': 'DT', 'span': {'begin': 16, 'end': 20}}, {'id': 'T4', 'obj': 'JJ', 'span': {'begin': 21, 'end': 29}}, {'id': 'T5', 'obj': 'NN', 'span': {'begin': 30, 'end': 34}}, {'id': 'T6', 'obj': 'TO', 'span': {'begin': 35, 'end': 37}}, {'id': 'T7', 'obj': 'VB', 'span': {'begin': 38, 'end': 42}}, {'id': 'T8', 'obj': 'NN', 'span': {'begin': 43, 'end': 52}}, {'id': 'T9', 'obj': 'IN', 'span': {'begin': 53, 'end': 55}}, {'id': 'T10', 'obj': 'RB', 'span': {'begin': 56, 'end': 63}}, {'id': 'T11', 'obj': '.', 'span': {'begin': 63, 'end': 64}}], 'text': 'Much I marveled this ungainly fowl to hear discourse so plainly.', 'relations': [{'subj': 'T0', 'pred': 'advmod', 'id': 'R0', 'obj': 'T2'}, {'subj': 'T1', 'pred': 'nsubj', 'id': 'R1', 'obj': 'T2'}, {'subj': 'T2', 'pred': 'ROOT', 'id': 'R2', 'obj': 'T2'}, {'subj': 'T3', 'pred': 'det', 'id': 'R3', 'obj': 'T5'}, {'subj': 'T4', 'pred': 'amod', 'id': 'R4', 'obj': 'T5'}, {'subj': 'T5', 'pred': 'dobj', 'id': 'R5', 'obj': 'T2'}, {'subj': 'T6', 'pred': 'aux', 'id': 'R6', 'obj': 'T7'}, {'subj': 'T7', 'pred': 'advcl', 'id': 'R7', 'obj': 'T2'}, {'subj': 'T8', 'pred': 'dobj', 'id': 'R8', 'obj': 'T7'}, {'subj': 'T9', 'pred': 'advmod', 'id': 'R9', 'obj': 'T10'}, {'subj': 'T10', 'pred': 'advmod', 'id': 'R10', 'obj': 'T7'}, {'subj': 'T11', 'pred': 'punct', 'id': 'R11', 'obj': 'T2'}]}" to see session."
5151
fi
5252

templates/index.html

Lines changed: 91 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<title>Stanford + spaCy accessor</title>
55

66
<link rel="stylesheet" href="../static/style.css" />
7+
78
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
89
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" />
910
<link rel="stylesheet" href="http://textae.pubannotation.org/lib/css/textae.min.css" />
@@ -14,21 +15,7 @@
1415
<script src="http://textae.pubannotation.org/vender/jquery.jsPlumb-1.5.2-min.js"></script>
1516
<script src="http://textae.pubannotation.org/lib/textae.min.js"></script>
1617

17-
18-
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
19-
20-
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset-context/cssreset-context-min.css">
21-
22-
23-
24-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
25-
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
26-
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
27-
<script src="http://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
28-
<script src="http://textae.pubannotation.org/vender/jquery.jsPlumb-1.5.2-min.js"></script>
29-
<script src="http://textae.pubannotation.org/lib/textae.min.js"></script>
30-
31-
<script>
18+
<!-- <script>
3219
// A simple function to copy a string to clipboard. See https://github.com/lgarron/clipboard.js for a full solution.
3320
var copyToClipboard = (function() {
3421
var _dataString = null;
@@ -47,117 +34,106 @@
4734
document.execCommand("copy");
4835
};
4936
})();
50-
</script>
37+
</script> -->
5138

5239

5340
</head>
5441

5542
<body>
5643
<div class="container-box">
57-
<div class="blur-container">
58-
<div class="pre-blur-box"></div>
59-
<div id="header" class="blur-box">
60-
<div id="title" class="img-box">
61-
<h1>
62-
<a href="spacy_rest">Stanford + spaCy REST accessor</a>
63-
</h1>
64-
65-
<a id="git-link" onmouseover="document.getElementById('git-img').src='../static/git-hover.png';" onmouseout="document.getElementById('git-img').src='../static/git-colored.png';" href="https://github.com/Aequivinius/dbcls">see on <img id="git-img" src="../static/git-colored.png" alt="GitHub" width="15px"/></a>
66-
</div>
67-
</div>
68-
</div>
69-
{% if error %}
70-
<div id="error" class="blur-container">
71-
<div class="pre-blur-box"></div>
72-
<div class="blur-box error">
73-
{{ error }}
74-
75-
{% if dump %}
76-
<pre><code>{{dump}}</code></pre>
77-
{% endif %}
78-
</div>
79-
</div>
80-
{% endif %}
81-
82-
{% if not page_not_found %}
83-
<div id="main" class="blur-container">
84-
<div class="pre-blur-box"></div>
85-
<div class="blur-box">
86-
<h2>Demo</h2>
87-
<section>
88-
<form id="form-box">
89-
<input type="text" id="text-field" class="white-box" name="text" value="{{input_text}}" placeholder="Input text">
90-
<input id="text-value" class="white-box btn" type="submit" value="submit">
91-
</form>
92-
</section>
93-
<section>
94-
<h3 id="textae">Parsing result in <a href="http://textae.pubannotation.org">TextAE</a> visualization</h3>
95-
<div class=".yui3-cssreset textae-editor">
96-
{{ json }}
97-
</div>
98-
</section>
99-
<section>
100-
<div class="title-bar">
101-
<h3>... in JSON</h3>
102-
<a id="memclick" onclick="copyToClipboard(&quot;{{ pretty_json }}&quot;)">copy to memory</a>
103-
</div>
104-
<textarea id="json-area" class="white-box json-box code">{{ pretty_json }}</textarea>
105-
</section>
106-
</div>
107-
</div>
44+
<div class="blur-container">
45+
<div class="pre-blur-box"></div>
46+
<div id="header" class="blur-box">
47+
<div id="title" class="img-box">
48+
<h1>
49+
<a href="spacy_rest">Stanford + spaCy REST accessor</a>
50+
</h1>
51+
52+
<a id="git-link" onmouseover="document.getElementById('git-img').src='../static/git-hover.png';" onmouseout="document.getElementById('git-img').src='../static/git-colored.png';" href="https://github.com/Aequivinius/dbcls">see on <img id="git-img" src="../static/git-colored.png" alt="GitHub" width="15px"/></a>
53+
</div> <!-- #title -->
54+
</div> <!-- #header -->
55+
</div> <!-- .blur-container -->
56+
57+
{% if error %}
58+
<div id="error" class="blur-container">
59+
<div class="pre-blur-box"></div>
60+
<div class="blur-box error">
61+
{{ error }}
62+
63+
{% if dump %}
64+
<pre><code>{{dump}}</code></pre>
10865
{% endif %}
109-
110-
<div id="explain" class="blur-container">
111-
<div class="pre-blur-box"></div>
112-
<div class="blur-box">
113-
<h3>In a nutshell</h3>
114-
<p>This is the web interface for a pipeline that delivers fast, accurate dependency parses using <a href="http://nlp.stanford.edu/software/tagger.shtml">Stanford POS tagger</a> and <a href="https://spacy.io/">spaCy</a> dependency parser. The result is returned in <a href="http://www.pubannotation.org/docs/annotation-format/">PubAnnotation JSON</a>, which is visualized using <a href="http://textae.pubannotation.org">TextAE</a>.</p>
115-
116-
117-
118-
119-
<h3>Usage</h3>
120-
<p>Either use via the web interface above, or using <a href="https://curl.haxx.se/">cURL</a> as shown below:</p>
121-
<code>
122-
curl -H "content-type:application/json" -d '{"text":"This is a sample sentence."}' http://spacy.dbcls.jp/spacy_rest/spacy_rest/</code><br /><br />
123-
124-
<code>curl -d text="Induction of chromosome banding by trypsin/EDTA for gene mapping by in situ hybridization." http://spacy.dbcls.jp/spacy_rest/spacy_rest/</code>
125-
126-
<p>Any other service making RESTful requests should be possible to use. In particular, this web service was developed in order to be used in conjunction with <a href="http://pubannotation.org/">PubAnnotation</a>, which allows users to obtain annotations for collections of biomedical text automatically, and align them with the original publication.</p>
127-
128-
<h3>Parsing</h3>
129-
<p>A combination of the famous <a href="http://nlp.stanford.edu/software/tagger.shtml">Stanford POS tagger</a> and <a href="https://spacy.io/">spaCy</a> for parsing is used.</p>
130-
131-
<p>spaCy is a python library for NLP. It's main strength is it's speed, owing to the underlying implementation in cython. While it does offer tokenization and POS tagging, we found that the tagger does not perform well, especially in the biomedical domain.</p>
132-
133-
<p>We thus employ Stanford tagger in conjunction with spaCy's parser to provide high accuracy and speed. For more information about this approach, see the <a href="http://cs.aequivinius.ch/downloads/dependencyparsing.pdf">dissertation</a> that informed this project.</p>
134-
66+
</div> <!-- .error -->
67+
</div> <!-- #error -->
68+
{% endif %}
69+
70+
{% if not page_not_found %}
71+
<div id="main" class="blur-container">
72+
<div class="pre-blur-box"></div>
73+
<div class="blur-box">
74+
<h2>Demo</h2>
75+
<section>
76+
<form id="form-box">
77+
<input type="text" id="text-field" class="white-box" name="text" value="{{input_text}}" placeholder="Input text">
78+
<input id="text-value" class="white-box btn" type="submit" value="submit">
79+
</form>
80+
</section>
81+
<section>
82+
<h3 id="textae">Parsing result in <a href="http://textae.pubannotation.org">TextAE</a> visualization</h3>
83+
<div class="textae-editor">{{ json }}</div>
84+
</section>
85+
86+
<section>
87+
<div class="title-bar">
88+
<h3>... in JSON</h3>
89+
<a id="memclick" onclick="copyToClipboard(&quot;{{ pretty_json }}&quot;)">copy to memory</a>
90+
</div>
91+
<textarea id="json-area" class="white-box json-box code">{{ pretty_json }}</textarea>
92+
</section>
93+
</div> <!-- blur-box -->
94+
</div> <!-- #main -->
95+
{% endif %}
96+
97+
<div id="explain" class="blur-container">
98+
<div class="pre-blur-box"></div>
99+
<div class="blur-box">
100+
<h3>In a nutshell</h3>
101+
<p>This is the web interface for a pipeline that delivers fast, accurate dependency parses using <a href="http://nlp.stanford.edu/software/tagger.shtml">Stanford POS tagger</a> and <a href="https://spacy.io/">spaCy</a> dependency parser. The result is returned in <a href="http://www.pubannotation.org/docs/annotation-format/">PubAnnotation JSON</a>, which is visualized using <a href="http://textae.pubannotation.org">TextAE</a>.</p>
102+
103+
<h3>Usage</h3>
104+
<p>Either use via the web interface above, or using <a href="https://curl.haxx.se/">cURL</a> as shown below:</p>
105+
<code>curl -H "content-type:application/json" -d '{"text":"This is a sample sentence."}' http://spacy.dbcls.jp/spacy_rest/spacy_rest/</code><br /><br />
106+
<code>curl -d text="Induction of chromosome banding by trypsin/EDTA for gene mapping by in situ hybridization." http://spacy.dbcls.jp/spacy_rest/spacy_rest/</code>
107+
<p>Any other service making RESTful requests should be possible to use. In particular, this web service was developed in order to be used in conjunction with <a href="http://pubannotation.org/">PubAnnotation</a>, which allows users to obtain annotations for collections of biomedical text automatically, and align them with the original publication.</p>
108+
109+
<h3>Parsing</h3>
110+
<p>A combination of the famous <a href="http://nlp.stanford.edu/software/tagger.shtml">Stanford POS tagger</a> and <a href="https://spacy.io/">spaCy</a> for parsing is used.</p>
111+
112+
<p>spaCy is a python library for NLP. It's main strength is it's speed, owing to the underlying implementation in cython. While it does offer tokenization and POS tagging, we found that the tagger does not perform well, especially in the biomedical domain.</p>
113+
114+
<p>We thus employ Stanford tagger in conjunction with spaCy's parser to provide high accuracy and speed. For more information about this approach, see the <a href="http://cs.aequivinius.ch/downloads/dependencyparsing.pdf">dissertation</a> that informed this project.</p>
115+
135116
<h3>Implementation</h3>
136117
<p>The Stanford POS tagger is written in Java, and can be run as a server using <a href="https://docs.oracle.com/javase/7/docs/api/java/net/ServerSocket.html">java.net.ServerSocket</a>. Using sockets proved to be an easy way to communicate between python and Java reliably.<p>
137-
138-
<p>The main script uses <a href="http://flask.pocoo.org/">Flask</a> to launch a web service listening to <code>rest_spacy</code> and <code>rest_spacy/</code> for incoming requests. Since loading spaCy models takes a considerable amount of time, one object containing these models is maintained that is then used for all requests.</p>
139-
140-
<p>For every request, a new client socket for the Stanford server socket is created, and Stanford's reply is read. The tokenized and tagged text is then passed to the spaCy object. The parses provided by spaCy are then realigned with the original text to facilitate using the results in PubAnnotation, converted into JSON and returned to the client.</p>
141-
</div>
142-
</div>
143-
</div>
144-
145-
<div id="explain" class="blur-container">
146-
<div class="pre-blur-box"></div>
147-
<div class="blur-box">
148-
149-
<p>This web service was developed as a joint project of the <a href="http://www.cl.uzh.ch/de.html">Institute of Computational Linguistics</a> at the University of Zurich, and the <a href="http://dbcls.rois.ac.jp/en/">DBCLS</a> in Japan. It is funded by a grant by <a href="https://www.jsps.go.jp/english/">JSPS</a>.</p>
150-
151-
<div class="img-box">
152-
118+
119+
<p>The main script uses <a href="http://flask.pocoo.org/">Flask</a> to launch a web service listening to <code>rest_spacy</code> and <code>rest_spacy/</code> for incoming requests. Since loading spaCy models takes a considerable amount of time, one object containing these models is maintained that is then used for all requests.</p>
120+
121+
<p>For every request, a new client socket for the Stanford server socket is created, and Stanford's reply is read. The tokenized and tagged text is then passed to the spaCy object. The parses provided by spaCy are then realigned with the original text to facilitate using the results in PubAnnotation, converted into JSON and returned to the client.</p>
122+
</div> <!--blur-box -->
123+
</div> <!-- #explain -->
124+
125+
<div id="credits" class="blur-container">
126+
<div class="pre-blur-box"></div>
127+
<div class="blur-box">
128+
<p>This web service was developed as a joint project of the <a href="http://www.cl.uzh.ch/de.html">Institute of Computational Linguistics</a> at the University of Zurich, and the <a href="http://dbcls.rois.ac.jp/en/">DBCLS</a> in Japan. It is funded by a grant by <a href="https://www.jsps.go.jp/english/">JSPS</a>.</p>
129+
130+
<div class="img-box">
153131
<a id="dbcls-link" href="http://dbcls.rois.ac.jp/en/" ><img class="logo" src="../static/dbcls-colored.png" onmouseover="this.src='../static/dbcls-hover.png';" onmouseout="this.src='../static/dbcls-colored.png';"/></a>
154132
<a id="uzh-link" href="http://www.cl.uzh.ch/de.html"><img class="logo" src="../static/uzh-colored.png" onmouseover="this.src='../static/uzh-hover.png';" onmouseout="this.src='../static/uzh-colored.png';"/></a>
155133
<a id="jsps-link" href="https://www.jsps.go.jp/english/"><img class="logo" src="../static/jsps-colored.png" onmouseover="this.src='../static/jsps-hover.png';" onmouseout="this.src='../static/jsps-colored.png';"/></a>
156-
</div>
157-
</div>
158-
</div>
159-
</div>
160-
</div>
161-
</div>
134+
</div> <!-- .img-box -->
135+
</div> <!-- blur-box -->
136+
</div> <!-- #credits -->
137+
</div> <!--container-box-->
162138
</body>
163139
</html>

0 commit comments

Comments
 (0)