【发布时间】:2015-01-19 04:27:12
【问题描述】:
我需要建立一个规则,让 Lhs 检查单词的第一个字符是否以 b 开头,然后检查整个单词,而不是在查找中找到的第一个字符
【问题讨论】:
-
欢迎来到堆栈溢出,这个网站面向代码爱好者和程序员,我们很乐意帮助任何被编码困扰的人。但是要在这里寻求帮助,您需要展示您在该问题上取得的一些进展。没有人会从头开始帮助您。
标签: gate
我需要建立一个规则,让 Lhs 检查单词的第一个字符是否以 b 开头,然后检查整个单词,而不是在查找中找到的第一个字符
【问题讨论】:
标签: gate
这是一个与您想要的类似的示例代码(复制自https://gate.ac.uk/wiki/jape-repository/strings.html#section-1.)。您可以阅读更多内容并找到确切的解决方案:
Rule:GetMobile
(
{Phone}
):tag
-->
:tag{
// get the offsets
Long phoneStart = tagAnnots.firstNode().getOffset();
Long phoneEnd = tagAnnots.lastNode().getOffset();
// check the number is longer than or equal to 2 characters (just in case)
if(phoneEnd - phoneStart >= 2) {
try {
String firstTwoChars = doc.getContent()
.getContent(tagAnnots.firstNode().getOffset(),
tagAnnots.firstNode().getOffset() + 2).toString();
// check it matches 07
if("07".equals(firstTwoChars)) {
// create the new annotation
gate.FeatureMap features = Factory.newFeatureMap();
features.put("kind", "mobile");
outputAS.add(tagAS.firstNode(),
tagAS.lastNode(), "Phone", features);
}
}
catch(InvalidOffsetException e) {
// not possible
throw new LuckyException("Invalid offset from annotation");
}
}
}
这里有一些你可以阅读的地方:
https://gate.ac.uk/wiki/jape-repository/
https://gate.ac.uk/sale/talks/gate-course-jun14/module-1-jape/module-1-jape.pdf
【讨论】: