ANNIE中JAPE规则调试:仅含数字的机构名称不标注问题求助
Let's break down why your current JAPE setup isn't working and get it sorted out. The core issue here is how you're trying to identify numeric-only establishment names—your rule relies on a Lookup.kind == number condition that probably doesn't correctly capture those cases, plus the way you're suppressing the annotation isn't aligned with ANNIE's processing flow.
What's Wrong with the Original Code?
Your first rule assumes the Lookup annotation has a kind property set to number for numeric-only establishments, but ANNIE's default Lookup annotations don't typically use the kind attribute this way. That property is usually reserved for categorizing establishment types (like "company" or "university"), not indicating whether the name is purely numeric. So your rule isn't actually matching the cases you want to exclude.
Corrected JAPE File
Here's a revised version that properly identifies and skips numeric-only establishment names, with explanations:
Phase: Establishment Input: Lookup Token Options: control = appelt // First, prioritize skipping numeric-only establishments Rule: SkipNumericEstablishments Priority: 100 ( // Match a Lookup tagged as an establishment {Lookup.majorType == "establishment"} // Ensure all Tokens within this Lookup are pure digits ({Token.string.matches("^\\d+$")})+ ):numeric_estab --> // Do not generate any Establishment annotation for this match { } // Then handle valid, non-numeric establishments Rule: Establishment Priority: 50 ( {Lookup.majorType == "establishment"} ):valid_estab --> :valid_estab.Establishment = {rule = "EstablishmentRule"}
Key Changes Explained
- Targeting Numeric Tokens: Instead of relying on
Lookup.kind, we check that everyTokenwithin theLookupspan is a pure numeric string using the regex^\\d+$. The+ensures there's at least one (and potentially multiple) numeric tokens making up the establishment name. - Priority Order: With
control = appelt, rules run in order of highest priority first. TheSkipNumericEstablishmentsrule (priority 100) catches the numeric cases first and does nothing (so noEstablishmentannotation is created), while the lower-priorityEstablishmentrule (50) only processes the remaining non-numeric establishments. - Clear Rule Separation: Splitting the logic into two distinct rules makes it easier to debug and ensures we don't accidentally overlap matches.
Why control = appelt Wasn't the Problem
Your hunch about control settings was off—appelt is actually the right choice here because it enforces priority-based execution, which is exactly what we need to ensure the skip rule runs before the annotation rule. The issue was entirely in how you were identifying the numeric-only names.
内容的提问来源于stack exchange,提问作者Chris Dromey

