我收到此错误 错误:edu.stanford.nlp.ling.tokensregex.parser.TokenMgrError:遇到:" \'",在:""
我正在使用最新的2016-10-31版本的stanford core nlp, 这是我的代码
static MaxentTagger tagger = new MaxentTagger("C:/Users/Sam/Desktop/stanford-corenlp-full-2016-10-31/stanford-corenlp-full-2016-10-31/edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger"); tokens = new ArrayList<CoreLabel>(); properties = new Properties(); properties.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); pipeline = new StanfordCoreNLP(properties); this.sentenceFeatures = Main.pipeline.process(textFeatures) .get(CoreAnnotations.SentencesAnnotation.class); for(CoreMap sentence: this.sentenceFeatures) { // **using TokensRegex** for (CoreLabel token: sentence.get(TokensAnnotation.class)){ Main.tokens.add(token); } this.p1 = TokenSequencePattern.compile(this.textFeatures); this.matcher = p1.getMatcher(Main.tokens); for (CoreLabel token: sentence.get(TokensAnnotation.class)) { String words = token.get(TextAnnotation.class); this.wordsList.add(words); String tagged = Main.tagger.tagString(words); this.wordsList.add(tagged); this.no_of_words++; this.no_of_chars += words.length(); } }
虽然
textFeatures = "At the western corner of the northern peninsula of Michigan you'll find Porcupine Mountains Wilderness State Park that is a true gem for a great family vacation , and the largest State Park in Michigan too.It has many things to offer to families looking for adventure in the great outdoors.And it's accessible during all the seasons of the year.The Park got its name from the Ojibwa Indians, who named the 'small mountains' thus, because, with their tall trees, they looked like crouching porcupines.Visit in the spring as the leaves begin to bud.Call on it in the summer lambing season.Greet it in the Autumn as the leaves begin to fall.Love it in the winter skying season.Its terrain is wild and rugged where it sits at the shoreline of Lake Superior, and inland where it embraces sixty-thousand acres of towering pines and sturdy birches and natural hemlock forests.The rivers teem with various species of trout as they cut through the forests."
和我得到的例外是:
Exception in thread "main" java.lang.RuntimeException: When parsing Here are some of Michigan's premier attractions (although of course it's by no means complete) - or intended to be, for that matter.Porcupine Mountains At the western corner of the northern peninsula of Michigan you'll find Porcupine Mountains Wilderness State Park that is a true gem for a great family vacation , and the largest State Park in Michigan too.It has many things to offer to families looking for adventure in the great outdoors.And it's accessible during all the seasons of the year.The Park got its name from the Ojibwa Indians, who named the 'small mountains' thus, because, with their tall trees, they looked like crouching porcupines.Visit in the spring as the leaves begin to bud.Call on it in the summer lambing season.Greet it in the Autumn as the leaves begin to fall.Love it in the winter skying season.Its terrain is wild and rugged where it sits at the shoreline of Lake Superior, and inland where it embraces sixty-thousand acres of towering pines and sturdy birches and natural hemlock forests.The rivers teem with various species of trout as they cut through the forests. edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParseException: Parsing failed. Error: edu.stanford.nlp.ling.tokensregex.parser.TokenMgrError: Lexical error at line 1, column 26. Encountered: "\'" (39), after : "" at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:192) at edu.stanford.nlp.ling.tokensregex.TokenSequencePattern.compile(TokenSequencePattern.java:171)
答案 0 :(得分:2)
TokenSequencePattern应该是您要编译的规则,而不是您要在其中找到模式的文本。
以下是对TokensRegex的一般参考: