自然语言结构化处理工具-Apache UIMA Ruta使用(二)Ruta 规则简介

本文介绍了ApacheUIMARuta的规则语言,包括规则元素的组成,Annotation的作用,以及如何利用内置和自定义的Annotation进行模式匹配和动作执行。通过实例展示了如何在病程记录中抽取发病时间信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言

上一篇文章中我们已经搭建好了Ruta的Workbench,并且在只是新建了一个空的规则脚本的情况下,就能运行一个规则脚本,说明这个组件已经帮我们处理的很多内容,在这篇文章中,我们将继续了解Ruta的规则

二、What is

The UIMA Ruta language is an imperative rule language extended with scripting elements. A UIMA Ruta rule defines a pattern of annotations with additional conditions. If this pattern applies,Core Concepts 2 Apache UIMA Ruta Overview UIMA Ruta Version 2.4.0 then the actions of the rule are performed on the matched annotations. A rule is composed of a sequence of rule elements and a rule element essentially consist of four parts: A matching
condition, an optional quantifier, a list of conditions and a list of actions. The matching condition is typically a type of an annotation by which the rule element matches on the covered text of one of those annotations. The quantifier specifies, whether it is necessary that the rule element successfully matches and how often the rule element may match. The list of conditions specifies additional constraints that the matched text or annotations need to fulfill. The list of actions defines the consequences of the rule and often creates new annotations

以上摘自:Apache UIMA Ruta��� Guide and Reference

Ruta 是一种命令式的规则语言,Ruta中的规则定义一个带有附加条件的由Annotation组成的模式 ,如果这个模式匹配上了,就会执行相应的动作。这里的Annotation,在上一篇文章的结尾,有给大家展示,这里再拿过来给大家看一下:

这里的的BREAK、CAP、COLON、SW等,都是Annotation,annotation的一般翻译为注解,注释,我一般喜欢叫标签,每一个Annotation都有一个begin end属性,指明了它在原文档中的位置范围,更像是在文章里面贴的一个个标签,告诉你这个位置是什么,另外一个位置是什么。

Ruta已经内置了很多标签,默认情况,在运行的时候,会把这些内置的标签都给添加到文本上,所以我们建的空的规则文件,却能在运行之后,看到上图这些内容。这些内置标签,都通过descriptor文件夹下的BasicTypeSystem引入了进来。

右键上面红框中文件的其中一个,open With 会看到

选择Component Descriptor Editor,没有的话 点Other... 在UIMA Ruta下能找到。打开像这样:

在最下面能切换:

点Type System,能看到这个类型定义文件中,定义的标签

这里面定义的Annotation都是可以在脚本里面直接用的。

这里再解释下最开始的基于Annotation的模式,结合病程记录文章抽取来说下:

为了抽取患者是什么时候出现的症状,也就是患者的发病时间,我自定义了一个标签类型DateUnit(后面会将如何添加自定义类型),它有两个feature,一个是Number,一个是Unit

使用以下脚本:

"天"{->MARK(DateUnit)};

"周"{->MARK(DateUnit)};

(NUM DateUnit){->MARK(Duration),Duration.Number=NUM,Duration.Unit=DateUnit};

第一行 把所有的天标记为DateUnit

第二行 把所有的周标记为DateUnit

第三行,当NUM类型和DateUnit在一起的时候,把其整个整体标记为Duration类型,并且把NUM赋值给DateUnit的第一个feature Number,把DateUnit赋值给DateUnit的第二个标签 Unit。

NUM DATEUnit ,当满足这个模式的时候,执行->之后定义的动作。具体的使用可以参考官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值