Skip to content

Commit

Permalink
Remove single dependency of another package on edu.stanford.nlp.patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
manning committed Jul 22, 2024
1 parent afb7692 commit 404adab
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.patterns.PatternsAnnotations;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphFactory;
import edu.stanford.nlp.trees.*;
Expand Down Expand Up @@ -138,14 +137,21 @@ public void testMacro() throws IOException {
throw new RuntimeException("failed!");
}

private static class PatternLabelAnnotation implements CoreAnnotation<String> {
@Override
public Class<String> getType() {
return String.class;
}
}

public void testEnv() throws IOException {
SemanticGraph h = SemanticGraph.valueOf("[married/VBN nsubjpass>Hughes/NNP auxpass>was/VBD nmod:to>Gracia/NNP]");
h.getFirstRoot().set(PatternsAnnotations.PatternLabel1.class,"YES");
h.getFirstRoot().set(PatternLabelAnnotation.class,"YES");
//SemanticGraph t = SemanticGraph
// .valueOf("[loved/VBD\nnsubj:Hughes/NNP\ndobj:[wife/NN poss:his/PRP$ appos:Gracia/NNP]\nconj_and:[obsessed/JJ\ncop:was/VBD\nadvmod:absolutely/RB\nprep_with:[Elicia/NN poss:his/PRP$ amod:little/JJ nn:daughter/NN]]]");
String macro = "macro WORD = married";
Env env = new Env();
env.bind("pattern1",PatternsAnnotations.PatternLabel1.class);
env.bind("pattern1",PatternLabelAnnotation.class);
String pattern = "({pattern1:YES}=parent >>nsubjpass {}=node)";
List<SemgrexPattern> pats = SemgrexBatchParser.compileStream(new ByteArrayInputStream((macro + "\n" + pattern).getBytes(StandardCharsets.UTF_8)), env);
SemgrexPattern pat3 = pats.get(0);
Expand Down

0 comments on commit 404adab

Please sign in to comment.