Get text between two annotated tags in ruta - uima

How to get data present between two annotated texts?
Sample input:
Seller Name FirstAvenue Mortgage, TN 12230 Contact Name John
Code :
BLOCK(sellerName) Line{CONTAINS(SellerNameKeyword)} {
c:ANY+{-PARTOF(SellerNameKeyword), -PARTOF(SellerName)->
CREATE(SellerName, "label"="Seller Name", "value"=c.ct)}
ContactNameKeyword;
}
This code is not giving any output for SellerName annotation
Expected Output : FirstAvenue Mortgage, TN 12230
What changes if input is spread across two lines ?
Sample input:
Seller Name FirstAvenue Mortgage, Contact Name John
TN 12230 Contact Title Supervisor
Code for above mentioned use case:
TYPESYSTEM utils.PlainTextTypeSystem;
ENGINE utils.PlainTextAnnotator;
DECLARE Keyword (STRING label);
DECLARE Entry(Keyword keyword);
DECLARE Keyword SellerNameKeyword, SellerNameContextBlocker, ContactNameKeyword;
EXEC(PlainTextAnnotator, {Line,Paragraph});
ADDRETAINTYPE(WS);
Line{->TRIM(WS)};
Paragraph{->TRIM(WS)};
REMOVERETAINTYPE(WS);
"Seller Name" -> SellerNameKeyword ( "label" = "Seller Name");
"Contact Title" -> SellerNameContextBlocker("label" = "Seller Name Context Blocker");
"Contact Name" -> ContactNameKeyword("label"= "Contact Name");
DECLARE Entity (STRING label, STRING value);
DECLARE Entity ContactName, SellerName;
BLOCK(line1) Line{CONTAINS(ContactNameKeyword)} {
ContactNameKeyword c:#{-PARTOF(ContactName)-> CREATE(ContactName,"label"="Contact Name", "value"=c.ct)};
}
SellerNameKeyword c:#{-PARTOF(ContactNameKeyword),-PARTOF(SellerNameContextBlocker),-PARTOF(ContactName) ->
CREATE(SellerName,"label"="Seller Name", "value"=c.ct)} SellerNameContextBlocker;
Output : FirstAvenue Mortgage, Contact Name John TN 12230
Expected Output : FirstAvenue Mortgage, TN 12230
Please suggest required changes and what I have missed ?

Since the information you want to annotate is not sequential in text ("Contact Name John" comes in between) you cannot represent the desired output in CAS as the covered text of a single annotation.
However, in your case, you might want to join together the text of interest in a feature of the output annotation. For example:
DECLARE SellerNameKeyword, ContactNameKeyword, ContactTitleKeyword;
DECLARE SellerName (STRING value);
"Seller Name" -> SellerNameKeyword;
"Contact Name" -> ContactNameKeyword;
"Contact Title" -> ContactTitleKeyword;
ADDRETAINTYPE(BREAK);
SellerNameKeyword ANY[0,5]{-PARTOF(ContactNameKeyword), -PARTOF(COMMA) ->
s1:CREATE(SellerName)} COMMA?
ContactNameKeyword ANY[0,5]{-PARTOF(BREAK)} BREAK? ANY[0,10]{-PARTOF(ContactTitleKeyword) ->
s2:CREATE(NameId), s1.value=""+s1.ct+s2.ct} ContactTitleKeyword;
ADDRETAINTYPE(BREAK);
The output of this rules will return an annotation SellerName on "FirstAvenue Mortgage" with feature value containing the desired output "FirstAvenue Mortgage TN 12230".
Mind that this is not a general solution but rather an example how it can be done in the give case.

Related

Fake email generation using factory.LazyAttribute

I am trying to generate fake email ID's for the purpose of research. I employ LazyAttribute towards this end. I want the email ID to correspond to the first and the last names of the person (generated using Faker). The function I wrote is below.
I am unable to get the expected output. If the name of the person is John Snow, I see the following as the output:
John Snow <factory.declarations.LazyAttribute object at ......
Can I expect some help to fix my code? Thanks!
def faker_categorical(num=1, seed=None):
np.random.seed(seed)
fake.seed_instance(seed)
output = []
for x in range(num):
gender = np.random.choice(["M", "F"], p=[0.5, 0.5])
output.append(
{
"First name": fake.first_name(),
"Last name": fake.last_name(),
"E-mail": factory.LazyAttribute(lambda obj: "%s#example.com" % obj.first_name),
})
return output

Get index of a meta-tag in Contact Form 7

I use a meta-tag in Contact Form 7 to send email:
[select category "Billing" "Suggestion" "Problems"]
For email body I insert this shortcode:
Category: [category]
Then I get email which contains "Category: Billing", or "Category: Suggestion", or "Category: Problems".
Is it possible to use some shortcode in Contact Form 7 which returns an index number of a value in meta-tag - 1,2,3? A number instead of a word. For example, "Category: 1", or "Category: 2", "Category: 3".
Use pipes,
[select category "Billing|1" "Suggestion|2" "Problems|3"]

Form binding <select multiple> to List in Play framework

I have a ticketing form that simplified contains a "subject" text field, a "content" textarea and a "to" multiple select.
I expected a multiple select to be able to bind to list(uuid) in Play's form mapping, but that is not the case.
request.body.asFormUrlEncoded("to") returns a Vector of several elements but .to in my mapping is empty. Looking at the source code it seems that Play requires me to put the "to" elements in to[0], to[1] etc. But for a multiple select that would be very inconvenient. Is there a better way?
case class CreateTicketFormModel(subject: String, content: String, to: List[UUID])
def CreateTicketForm = Form(mapping(
"subject" -> nonEmptyText,
"content" -> nonEmptyText,
"to" -> list(uuid)
)(CreateTicketFormModel.apply)(CreateTicketFormModel.unapply))

What does Drools do with ambiguous matches?

I'm playing around with some rules to standardize street addresses that failed look-up from a service provider.
I've defined this rule
rule "Derive Street Aliases"
when
$street : Street();
then
insert( new StreetAlias($street.getPrefixPart() + " " + $street.getStemmedPart(), $street.getName()) );
end
It takes a street name like "South Main Street" and creates the alias "South Main".
This other rule then picks up the alias:
rule "Street Alias Match"
when
$userAddress : UserAddress();
$streetAlias : StreetAlias(alias == $userAddress.getStreetPart());
then
$userAddress.setResolvedAddress($userAddress.getNumberPart() + " " + $streetAlias.getName());
end
This would work fine until a "South Main Avenue" is inserted. Then the alias "South Main" would become ambiguous.
What then is supposed to happen in the 2nd rule? Would it detect a conflict? Would it fire twice so that the last one wins?
I'm interested in the theory of what should happen, as I'm fairly new to Rules Engines.
It is the fundamental principle of the many pattern/many object pattern match problem that the engine should produce all possible matches. In rule based system this means that the engine must explore all possible combinations while evaluate constraints and create activations for each rule, combining facts in various tuples, which will then be used in rule firing.
If you have addresses stored as
class Address {
String streetSpecific;
String streetGeneric;
}
the same "specific" part can be used with several generic parts even in the same city. (Although, duplication of the full street name also occurs.) With an alias
class Alias {
String specific;
}
this rule finds all possible matches
rule "find possibles"
when
Alias( $spec: specific )
Address( streetSpecific == $spec )
then
// another possible match
end
and the rule
rule "find similar"
when
$a1: Address( $spec: streetSpecific )
$a2: Address( this != $a1, streetSpecific == $spec )
then
// display similar pair
end
will find "similar" street names (but note that this rule will fire too often - can you see why?)
Note that even the full name is no guarantee for uniqueness within a single city...

Form mapping that handles optional fields with custom validation

My form looks like:
case class RegistrationForm(department: Option[String], name: String, email: String, employeeId: Option[Int])
Now what I need to do is, if the user entered the department input, then employeeId should be None. And if they left the department empty, then employeeId will be a required field.
My mapping is currently this but it doesn't handle this logic:
val registrationForm = Form(
mapping(
"department" -> optional(String)
"name" -> nonEmptyText,
"email" -> nonEmptyText,
"employeeId" -> optional(number)
)(RegistrationForm.apply)(RegistrationForm.unapply)
)
Also, in my form, how do I create a hidden input field and bind it to my form property, because sometimes my url will be like:
/users/register?employeeId=293838
So I want to create:
<input type="hidden" name="employeeId" value="???" />
So this employeeId hidden input should be bound to the form.
You can use verifying to build constraints between form fields after they've all successfully been bound to the case class.
val registrationForm = Form(
mapping(
"department" -> optional(String)
"name" -> nonEmptyText,
"email" -> nonEmptyText,
"employeeId" -> optional(number)
)(RegistrationForm.apply)(RegistrationForm.unapply)
.verifying("Some error message..", reg =>
(reg.department.isEmpty || reg.employeeId.isEmpty) && (reg.department.nonEmpty || reg.employeeId.nonEmpty)
)
)
The first argument of verifying is an error message to use when the constraint is broken, and the second is a function of the case class you're binding to that returns Boolean. If the function returns false, the Form will contain a global error. I'm not 100% sure that's the logic you're going for in my example, as your wording is a bit strange (sounds like you're describing exclusive OR). You can also chain multiple verifying operations together if needed.
I'm not sure what your question about hidden fields is asking. A hidden field within the html form will be sent to the server with everything else, and bind just as any other field will.