Skip to content

Commit

Permalink
Fix serialization bug in Document; other minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Angeli authored and Stanford NLP committed Feb 9, 2018
1 parent 288ccac commit 7aa2e7f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 24 deletions.
22 changes: 11 additions & 11 deletions src/edu/stanford/nlp/pipeline/demo/corenlp-brat.html
Expand Up @@ -49,17 +49,17 @@
<label for="annotators" class="label">&mdash; Annotations &mdash;</label>
<select id="annotators" data-placeholder="CoreNLP annotators"
multiple class="chosen-select" title="Select CoreNLP annotators">
<option value="pos" selected > parts-of-speech </option>
<option value="lemma" > lemmas </option>
<option value="ner" selected > named entities </option>
<option value="regexner" > named entities (regexner)</option>
<option value="parse" > constituency parse </option>
<option value="depparse" selected > dependency parse </option>
<option value="openie" selected > openie </option>
<option value="coref" > coreference </option>
<option value="entitylink" > wikipedia entities </option>
<option value="kbp" > relations </option>
<option value="sentiment" > sentiment </option>
<option value="pos" selected > parts-of-speech </option>
<option value="lemma" > lemmas </option>
<option value="ner" selected > named entities </option>
<option value="regexner" > named entities (regexner) </option>
<option value="parse" > constituency parse </option>
<option value="depparse" selected > dependency parse </option>
<option value="openie" selected > openie </option>
<option value="coref" > coreference </option>
<!--<option value="entitylink" > wikipedia entities </option>--> <!-- TODO this regularly crashes corenlp.run -->
<option value="kbp" > relations </option>
<option value="sentiment" > sentiment </option>
</select>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/pipeline/demo/corenlp-brat.js
Expand Up @@ -989,7 +989,7 @@ $(document).ready(function() {
url: serverAddress + '?properties=' + encodeURIComponent(
'{"annotators": "' + annotators() + '", "date": "' + date() + '"}') +
'&pipelineLanguage=' + encodeURIComponent($('#language').val()),
data: encodeURIComponent(currentQuery), //jQuery does'nt automatically URI encode strings
data: encodeURIComponent(currentQuery), //jQuery doesn't automatically URI encode strings
dataType: 'json',
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
success: function(data) {
Expand Down
10 changes: 7 additions & 3 deletions src/edu/stanford/nlp/simple/Document.java
Expand Up @@ -486,10 +486,13 @@ public Document cased() {
*/
public CoreNLPProtos.Document serialize() {
synchronized (impl) {
// Serialize sentences
// Ensure we have sentences
List<Sentence> sentences = sentences();
// Ensure we're saving the newest sentences
// IMPORTANT NOTE: the clear below must come after we call #sentences()
this.impl.clearSentence();
for (Sentence sent : sentences()) {
this.impl.addSentence(sent.serialize());
for (Sentence s : sentences) {
this.impl.addSentence(s.serialize());
}
// Serialize document
return impl.build();
Expand Down Expand Up @@ -671,6 +674,7 @@ protected List<Sentence> sentences(Properties props, Annotator tokenizer) {
// (sentences)
List<CoreMap> sentences = ann.get(CoreAnnotations.SentencesAnnotation.class);
this.sentences = new ArrayList<>(sentences.size());
this.impl.clearSentence();
for (CoreMap sentence : sentences) {
//Sentence sent = new Sentence(this, sentence);
Sentence sent = new Sentence(this, this.serializer.toProtoBuilder(sentence), sentence.get(CoreAnnotations.TextAnnotation.class), defaultProps);
Expand Down
2 changes: 1 addition & 1 deletion src/edu/stanford/nlp/time/rules/defs.sutime.txt
Expand Up @@ -135,7 +135,7 @@
label: "AF",
value: InexactTime( TimeRange ( NOON, IsoTime( 18, NONE, NONE) ) )
}
EVENING = {
EVENING = {
type: TIME_OF_DAY,
label: "EV",
value: InexactTime( TimeRange ( IsoTime( 18, NONE, NONE), IsoTime ( 20, NONE, NONE) ) )
Expand Down
1 change: 1 addition & 0 deletions src/edu/stanford/nlp/time/rules/english.sutime.txt
Expand Up @@ -250,6 +250,7 @@
{ (/suppertimes?/) => SUPPERTIME }
{ (/daylights?|days?|daytimes?/) => DAYTIME }
{ (/nighttimes?|nights?|overnights?/) => NIGHT }
{ (/workday|work day|business hours/) => WORKDAY }

# Seasons
{ (/summers?/) => SUMMER }
Expand Down
53 changes: 45 additions & 8 deletions src/edu/stanford/nlp/util/Pointer.java
@@ -1,5 +1,6 @@
package edu.stanford.nlp.util;

import java.io.Serializable;
import java.util.Optional;

/**
Expand All @@ -8,22 +9,58 @@
*
* @author Gabor Angeli
*/
public class Pointer<T> {
public class Pointer<T> implements Serializable {
/** The serial version uid to ensure stable serialization. */
private static final long serialVersionUID = 1L;

private Optional<T> impl;
/**
* The value the pointer is set to, if it is set.
*/
private T impl;

/**
* Create a pointer pointing nowhere.
*/
public Pointer() {
this.impl = Optional.empty();
this.impl = null;
}

@SuppressWarnings("UnusedDeclaration")
/**
* Create a pointer pointing at the given object.
*
* @param impl The object the pointer is pointing at.
*/
public Pointer(T impl) {
this.impl = Optional.of(impl);
this.impl = impl;
}

public Optional<T> dereference() { return impl; }

public void set(T impl) { this.impl = Optional.of(impl); }
/**
* Dereference the pointer.
* If the pointer is pointing somewhere, the {@linkplain Optional optional} will be set.
* Otherwise, the optional will be {@linkplain Optional#empty() empty}.
*/
public Optional<T> dereference() {
return Optional.ofNullable(impl);
}


/**
* Set the pointer.
*
* @param impl The value to set the pointer to. If this is null, the pointer is unset.
*/
public void set(T impl) {
this.impl = impl;
}


public void set(Optional<T> impl) { this.impl = impl.isPresent() ? impl : this.impl; }
/**
* Set the pointer to a possible value.
*
* @param impl The value to set the pointer to. If this is {@linkplain Optional#empty empty}, the pointer is unset.
*/
public void set(Optional<T> impl) {
this.impl = impl.orElse(null);
}
}
3 changes: 3 additions & 0 deletions test/src/edu/stanford/nlp/time/SUTimeTest.java
Expand Up @@ -90,6 +90,7 @@ public void testThis() {
Pair.makePair(SUTime.AFTERNOON, "2016-06-19T12:00:00.000/PT6H"), // TODO: Check this...
Pair.makePair(SUTime.EVENING, "2016-06-19T18:00:00.000/PT2H"), // TODO: Check this...
Pair.makePair(SUTime.NIGHT, "2016-06-19T14:00:00.000/2016-06-20T00:00:00.000"),
Pair.makePair(SUTime.PMS, "2016-06-19T12:00:00.000/2016-06-20T00:00:00.000"),

Pair.makePair(SUTime.DAY, "2016-06-19/2016-06-19"),
Pair.makePair(SUTime.WEEK, "2016-06-13/2016-06-19"), // TODO: is this right (Sunday is a weird day...)
Expand All @@ -102,6 +103,8 @@ public void testThis() {
Pair.makePair(SUTime.SPRING, "2016-03-01/2016-06"),
Pair.makePair(SUTime.SUMMER, "2016-06-01/2016-09"),
Pair.makePair(SUTime.FALL, "2016-09-01/2016-12"),

Pair.makePair(SUTime.WORKDAY, "2016-06-19T09:00:00.000/PT8H"),
});

for (int i = 0; i < testPairs.length; i++) {
Expand Down

0 comments on commit 7aa2e7f

Please sign in to comment.