Skip to content

Commit

Permalink
fix bug with using coref and server
Browse files Browse the repository at this point in the history
  • Loading branch information
J38 authored and Stanford NLP committed May 7, 2017
1 parent 3637d66 commit 92363c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/edu/stanford/nlp/coref/md/CorefMentionFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class CorefMentionFinder {

protected HeadFinder headFinder;
protected Annotator parserProcessor;
protected Annotator taggerProcessor;
protected boolean allowReparsing;

protected static final TregexPattern npOrPrpMentionPattern = TregexPattern.compile("/^(?:NP|PN|PRP)/");
Expand Down Expand Up @@ -512,8 +513,8 @@ public Tree findSyntacticHead(Mention m, Tree root, List<CoreLabel> tokens) {
if (allowReparsing) {
int approximateness = 0;
List<CoreLabel> extentTokens = new ArrayList<>();
extentTokens.add(initCoreLabel("It"));
extentTokens.add(initCoreLabel("was"));
extentTokens.add(initCoreLabel("It", "PRP"));
extentTokens.add(initCoreLabel("was", "VBD"));
final int ADDED_WORDS = 2;
for (int i = m.startIndex; i < endIdx; i++) {
// Add everything except separated dashes! The separated dashes mess with the parser too badly.
Expand All @@ -524,7 +525,7 @@ public Tree findSyntacticHead(Mention m, Tree root, List<CoreLabel> tokens) {
approximateness++;
}
}
extentTokens.add(initCoreLabel("."));
extentTokens.add(initCoreLabel(".", "."));

// constrain the parse to the part we're interested in.
// Starting from ADDED_WORDS comes from skipping "It was".
Expand Down Expand Up @@ -622,10 +623,11 @@ private static Tree funkyFindLeafWithApproximateSpan(Tree root, String token, in
return leaves.get(fallback); // last except for the added period.
}

private static CoreLabel initCoreLabel(String token) {
private static CoreLabel initCoreLabel(String token, String posTag) {
CoreLabel label = new CoreLabel();
label.set(CoreAnnotations.TextAnnotation.class, token);
label.set(CoreAnnotations.ValueAnnotation.class, token);
label.set(CoreAnnotations.PartOfSpeechAnnotation.class, posTag);
return label;
}

Expand Down
2 changes: 2 additions & 0 deletions src/edu/stanford/nlp/pipeline/StanfordCoreNLPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ private StanfordCoreNLP mkStanfordCoreNLP(Properties props) {
impl = pipelineCache.get(props);
if (impl == null) {
AnnotatorPool pool = StanfordCoreNLP.constructAnnotatorPool(props, new AnnotatorImplementations());
// TO DO: this might cause some problems
StanfordCoreNLP.pool = pool;
impl = new StanfordCoreNLP(props, pool);
pipelineCache.put(props, impl);
}
Expand Down

0 comments on commit 92363c1

Please sign in to comment.