I need to build a rule where Lhs check if the first character of word beggin in b then check the whole word without the first character that found in lookup
Asked
Active
Viewed 412 times
1
-
Welcome to stack overflow, this website is for code enthusiasts and programmers and we are happy to help anyone who is stuck with coding. But for asking help here you need to show some progress you have done on the problem. No one will help you from scratch. – RicoRicochet Jan 19 '15 at 04:33
1 Answers
1
This is a sample code for something similar to what you want(Copied from https://gate.ac.uk/wiki/jape-repository/strings.html#section-1.). You can read a little more and get to the exact solution:
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");
}
}
}
Here are some places where you can read up:
https://gate.ac.uk/wiki/jape-repository/
https://gate.ac.uk/sale/talks/gate-course-jun14/module-1-jape/module-1-jape.pdf

pnv
- 1,437
- 3
- 23
- 52