UIMA Ruta中能否通过WORDTABLE实现文本部分匹配?
Absolutely! You can pull off this suffix-based matching and feature assignment using UIMA Ruta's WORDTABLE functionality. Here's a step-by-step breakdown tailored to your specific case:
1. Prepare Your CSV Mapping File
First, confirm your CSV file (let’s name it suffix_mappings.csv) uses the correct semicolon separators as you provided:
book;b. ship;sh.
Each row links a target suffix to its corresponding feature value.
2. Configure WORDTABLE for Suffix Matching
By default, WORDTABLE uses prefix matching, but Ruta lets you switch to suffix mode with simple parameters. Add this declaration to your Ruta script:
// Declare the WORDTABLE with suffix matching enabled WORDTABLE suffixMap = "suffix_mappings.csv"; WORDTABLE(suffixMap, false, ";", 1, 2, SUFFIX); // Enable case-insensitive matching by changing the second parameter to true: // WORDTABLE(suffixMap, true, ";", 1, 2, SUFFIX);
Let’s break down those parameters:
false: Disables case-insensitive matching (flip totrueif you need to match "Book" or "SHIP" variants);: The delimiter used in your CSV file1: Column index (starting at 1) for suffix keys (book,ship)2: Column index for feature values (b.,sh.)SUFFIX: Tells Ruta to match the end of each word against the table’s keys
3. Apply the Matching & Feature Assignment Rule
First, make sure you’ve defined a custom feature in your type system (e.g., STRING suffixFeature; for the WORD type). Then use this rule to assign values:
// Match qualifying words and assign their mapped feature value WORD{-> ASSIGN(suffixFeature, suffixMap.getValue())};
4. Expected Results for Your Input Text
For your input:
yearbook book databook worship friendship yearbook
The rule will assign:
b.toyearbook,book,databook(all end withbook)sh.toworship,friendship(all end withship)
Quick Tips
- Verify your CSV file path: if it’s not in the same directory as your script, use the full path or place it in your project’s resource folder.
- If a word could match multiple suffixes (unlikely here),
WORDTABLEprioritizes the longest matching suffix. - Ensure your type system includes the custom feature you’re assigning (define this in the Ruta descriptor or a separate type system XML file).
内容的提问来源于stack exchange,提问作者Sugunalakshmi Pagemajik

