目的:
指定标题级别。
第一个标题被指定为1级。我提取它的字体系列和大小并找到匹配的标题。一旦水平被分配,我取消标记标题,保留标题&另一个注释(HeadingHierarchy)中的功能。级别完成后,只要在Headinglevel注释中留下任何标题,我就会反复调用同一个块。
问题:
该脚本适用于查找所有1级标题。但是当通过Call语句执行块时,它只找到每个级别的第一个匹配(级别2以后)。因此,以下输入的总级数变为10,而必须为4。
输入:(适用。TXT)
Apache UIMA Ruta Overview =>Arial,18
What is Apache UIMA Ruta? =>Arial,16
Getting started =>Arial,16
UIMA Analysis Engines =>Arial,16
Ruta Engine =>Times New Roman,14
Configuration Parameters =>Arial,10
Annotation Writer =>Times New Roman,14
Configuration Parameters =>Arial,10
Apache UIMA Ruta Language =>Arial,18
Syntax =>Arial,16
Rule elements and their matching order =>Arial,16
脚本:
PACKAGE uima.ruta.example;
DECLARE Headinglevel(STRING family, INT size, INT level);
DECLARE HeadingHierarchy(STRING family, INT size, INT level);
DECLARE FontFamily, FontSize;
STRING family;
INT size;
RETAINTYPE(BREAK);
BREAK? #{-PARTOF(Headinglevel)} @SPECIAL+ W+ COMMA NUM{->MARK(Headinglevel,2,6), MARK(HeadingHierarchy,2,6), MARK(FontFamily,4), MARK(FontSize,6)};
RETAINTYPE;
h:Headinglevel{->h.family = family, HeadingHierarchy.family = family}
<-{FontFamily{PARSE(family)};};
h:Headinglevel{->h.size = size, HeadingHierarchy.size = size}
<-{FontSize{PARSE(size)};};
INT i=1;
BLOCK(ForEachHeadLevel)Document{}
{
# h:Headinglevel{-> family = h.family, size = h.size};
h:Headinglevel{AND(h.family == family, h.size == size)-> h.level=i, HeadingHierarchy.level = i, UNMARK(h)};
}
Headinglevel{->i=i+1, CALL(Test2.ForEachHeadLevel)};
Document{->LOG(" LEVELS : " + (i))};
预期输出:
HeadingHierarchy Feature
Apache UIMA... =>Arial,18 level: 1
What is Apa... =>Arial,16 level: 2
Getting sta... =>Arial,16 level: 2
UIMA Analys... =>Arial,16 level: 2
Ruta Engine... =>Times New Roman,14 level: 3
Configurati... =>Arial,10 level: 4
Annotation ... =>Times New Roman,14 level: 3
Configurati... =>Arial,10 level: 4
Apache UIMA... =>Arial,18 level: 1
Syntax =>Ar... =>Arial,16 level: 2
Rule elemen... =>Arial,16 level: 2
答案 0 :(得分:1)
问题是CALL限制了规则元素匹配的范围上的窗口。这意味着BLOCK仅在现有的Headinglevel注释中执行。但是,您需要拥有完整的文档,以便块中的第二个规则完成其工作。
这很可能不是最好的解决方案,但是第一个出现在我脑海中的解决方案。
无论使用DOCUMENTBLOCK对CALL操作的限制如何,您都可以将BLOCK中的窗口重置为完整文档:
BLOCK (ForEachHeadLevel)Document{}
{
DOCUMENTBLOCK Document{}
{
# h:Headinglevel{-> family = h.family, size = h.size};
h:Headinglevel{AND(h.family == family, h.size == size)-> h.level=i, HeadingHierarchy.level = i, UNMARK(h)};
}
}
DOCUMENTBLOCK
是一个块扩展名。您需要在org.apache.uima.ruta.block.DocumentBlockExtension
配置参数中包含additionalExtensions
。
这是使用FOREACH块的另一种解决方案:
INT i=0;
FOREACH(hl) Headinglevel{}{
hl{IS(Headinglevel)-> i=i+1, family = hl.family, size = hl.size};
h:Headinglevel{h.family == family, h.size == size -> h.level=i, HeadingHierarchy.level = i, UNMARK(h)};
}
免责声明:我是UIMA Ruta的开发者