简体   繁体   中英

Error Creating TokenRegex Rules

I am creating a TokenRegex Rules list. This is what I have:

$STARTING_SEQUENCE = (/start/|/begin/)

{
  ruleType: "tokens",
  pattern: ([{lemma:$STARTING_SEQUENCE}]), 
  result: "START"
}

When I compile my code, the compiler gives me this error:

Reading TokensRegex rules from tr.txt
Exception in thread "main" java.lang.RuntimeException: Error parsing file: tr.txt
at edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor.createExtractorFromFile(CoreMapExpressionExtractor.java:258)
at MedicalTranscript.x(MedicalTranscript.java:37)
at MedicalTranscript.main(MedicalTranscript.java:76)
Caused by: java.lang.ClassCastException: edu.stanford.nlp.ling.tokensregex.TokenSequencePattern cannot be cast to java.lang.String
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CoreMapVarValue(TokenSequenceParser.java:1673)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.AttrValue(TokenSequenceParser.java:1534)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CoreMapNode(TokenSequenceParser.java:1434)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeBasic(TokenSequenceParser.java:1411)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeGroup(TokenSequenceParser.java:1378)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.NodeDisjConj(TokenSequenceParser.java:1317)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.BracketedNode(TokenSequenceParser.java:1178)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexBasic(TokenSequenceParser.java:884)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegexDisjConj(TokenSequenceParser.java:1071)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.SeqRegex(TokenSequenceParser.java:841)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.BasicValue(TokenSequenceParser.java:383)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.ValueExpression(TokenSequenceParser.java:292)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.Expression(TokenSequenceParser.java:210)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.FieldValue(TokenSequenceParser.java:345)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.CompositeFieldValue(TokenSequenceParser.java:333)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.Rule(TokenSequenceParser.java:122)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.RuleList(TokenSequenceParser.java:107)
at edu.stanford.nlp.ling.tokensregex.parser.TokenSequenceParser.getExpressionExtractor(TokenSequenceParser.java:22)
at edu.stanford.nlp.ling.tokensregex.CoreMapExpressionExtractor.createExtractorFromFile(CoreMapExpressionExtractor.java:254)
... 2 more

What am I doing wrong?

Try

$STARTING_SEQUENCE = "/start|begin/"

Because it is a regular expression for matching the string field lemma, it needs to be a string expressing a normal regular expression over string.

You may also want to do something with the result or use actions to do some annotation:

Example:

{
  ruleType: "tokens",
  pattern: ([{lemma:$STARTING_SEQUENCE}]), 
  action:  ( Annotate($0, ner, "START") )
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM