Mailchimp INTERESTED merge tag advanced conditions - if-statement

I have read ALL on mailchimp website from all api docs to blog comments :D
and even talked (chat) with there support.
Support helped me in some why but nothing i didnt knew :D
Merge tags have IF and ELSEIF statements and work on OR logic there is NO AND !!!
A bit blaaahhhhh if you ask me... ;)
(Mailchimp add AND) XD
So i have a question if anyone tried this.
I have one List with 2 Groups
(Group title: Categories
with Group names: language course, IT course, first aid course, cooking course;
Group title: Cities
with Group names: New York, Washington, Springfield, Texas)
And i want to send campaign to users who have this criteria:
Categories:IT course
OR AND
Cities: New York
i have tried:
|INTERESTED:Categories:IT course|
|INTERESTED:Cities:New York|
(STEP 1) This text will print only to New York & IT Course Subscribers;
|END:INTERESTED:|
This text will print only to IT Course Subscribers;
BUT if they already are receiving from step ONE (STEP 1)
This will duplicate the msg
|END:INTERESTED:|
So i tried this:
|INTERESTED:Categories:IT course|
|INTERESTED:Cities:New York|
(STEP 1) This text will print only to New York & IT Course Subscribers;
|END:INTERESTED:|
*|ELSE:|*
BUT this is okey :D but what if they dont have IT course selected
where will the "Cities:New York" message print ??? SOOO.... next step xD
|END:INTERESTED:|
It should be something like this. Right?
|INTERESTED:Categories:IT course|
|INTERESTED:Cities:New York|
(STEP 1) This text will print only to New York & IT Course Subscribers;
|END:INTERESTED:|
*|ELSE:|*
|INTERESTED:Categories:IT course|
(STEP 2) This text will print only to IT course Subscribers;
|END:INTERESTED:|
*|ELSE:|*
|INTERESTED:Cities:New York|
(STEP 3) This text will print only to New York Subscribers;
and this gets duplicated but it shouldnt even get executed
|END:INTERESTED:|
*|END:INTERESTED:|*
AND COMPLEX step
What if i have one Categories and two Cities
|INTERESTED:Categories:IT course|
|INTERESTED:Cities:New York, Washington|
(STEP 1) This text will print only to New York, Washington & IT Course Subscribers;
|END:INTERESTED:|
*|END:INTERESTED:|*
how to do this one ???
:D
I think this is possible but i cant find any mistakes in nesting.
I hope you have better idea and NESTING plan ;)
And did anyone tried |IF:| on |INTERESTED:...|
a have seen in doc. that there is |ELSE| clause but not |IF| nor |ELSEIF| so i asked the support and they told me to try it (my conclusion THEY DONT KNOW) where i was very surprised, so i tried it and of course the syntax is wrong.
What did i tried?
few variations:
this is the right syntax (normal)
|INTERESTED:...|
*|END:INTERESTED:|*
|INTERESTED:...|
...
|ELSE:|
...
|END:INTERESTED:|
.
.
.
i have tried:
|IF:INTERESTED:...|
...
|ELSEIF:|
...
|END:INTERESTED:|
and
|IF:INTERESTED:...|
...
|ELSEIF:|
...
|ENDIF:|
because i didnt know what to close INTERESTED merge tag or IF merge tag
i got some gibberish but i think somethig is wrong.

Clarification: Are you trying: 1) to create a segment to send a campaign to; or 2) Cause particular information to appear in a campaign depending on which groups the subscriber is in?
Here is what you can use to control what text appears within a campaign
*|INTERESTED:Categories:IT course|*
*|INTERESTED::Cities:New York|*This text will appear only if category is "IT Course" and cities is "New York"
*|ELSE:|*This text will appear only if category is "IT Course" and cities is not "New York"
*|END:INTERESTED|*
*|ELSE:|*This text will appear only if category is not "IT Course"
*|END:INTERESTED|*
You can nest both Group inclusion (INTERESTED ... END:INTERESTED) and regular field IF:field= and END:IF sections

I have found the solution if anyone is interested here it is :D
|INTERESTED:Categories: IT course>|
|INTERESTED:Cities: New York|
Categories: IT course & Cities: New York were selected
|ELSE:|
|INTERESTED:Categories: IT course|
this is because if you dont find users
with Categories: IT course & Cities: New York
|END:INTERESTED|
|END:INTERESTED|
*|ELSE:|*
|INTERESTED:Cities: New York|
This will print if Categories: IT course were FALSE
|END:INTERESTED|
*|END:INTERESTED|*
But now i have different question, it involves all of this.
How can now SKIP sending email to person who doesnt have anything select ???
:D
My friend suggested to try with segments and API but i would also like to hear from other people.

Related

Splitting chat conversations into sentences and mapping responses

I have the following data:
Rep: hi ! Customer: i was wondering if you have a delivery option? If so what are the options available ? Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options. Customer: ok! thank you Rep: Is there anything else that I can help you with? (Chat ended)
I am trying to split this into Q&A format like this:
Rep: hi !
Customer: i was wondering if you have a delivery option? If so what are the options available ?
Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options.
Customer: ok! thank you
Rep: Is there anything else that I can help you with?
(Chat ended)
This is one set of conversation with an unique ID. After the split I would like to have each the questions and answers as different columns appropriately matching each response.
I tried the following:
for i in d.split(':'):
if i:
print(i.strip().split('.'))
The output is as follows:
['Rep']
['hi ! Customer']
['i was wondering if you have a delivery option? If so what are the options available ? Rep']
["i'd be happy to answer that for you! There is a 2 and 5 day delivery options", ' Customer']
['ok! thank you Rep']
['Is there anything else that I can help you with? (Chat ended)']
You can use a much simpler regex!!!
import re
p = re.compile('(\w*\s*:)')
input_string = "Rep: hi ! Customer: i was wondering if you have a delivery option? If so what are the options available ? Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options. Customer: ok! thank you Rep: Is there anything else that I can help you with? (Chat ended)"
new_string = p.sub(r'\n\g<1>',input_string)
for line in new_string.split('\n')[1:]:
print line
Splitting with ':' is dangerous because the conversation itself may contain ':'.
You should have the names of the rep and the customer first so that you can search for their names followed by : in a regex pattern, with which you can use re.findall to parse the sample chat into:
[('Rep', 'hi !'), ('Customer', 'i was wondering if you have a delivery option? If so what are the options available ?'), ('Rep', "i'd be happy to answer that for you! There is a 2 and 5 day delivery options."), ('Customer', 'ok! thank you')]
Then use a loop to map the items into a dict data structure that you prefer:
import re
from pprint import pprint
def parse_chat(chat, rep, customer):
conversation = {}
rep_message = ''
for person, message in re.findall(r'({0}|{1}): (.*?)\s*(?=(?:{0}|{1}):)'.format(rep, customer), chat):
if person == rep:
rep_message = message
else:
conversation[rep_message] = message
return conversation
chat = '''Rep: hi ! Customer: i was wondering if you have a delivery option? If so what are the options available ? Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options. Customer: ok! thank you Rep: Is there anything else that I can help you with? (Chat ended)'''
pprint(parse_chat(chat, 'Rep', 'Customer'))
This outputs:
{'hi !': 'i was wondering if you have a delivery option? If so what are the options available ?',
"i'd be happy to answer that for you! There is a 2 and 5 day delivery options.": 'ok! thank you'}
Solution
Based on the assumption that there are only single, non-space-delimited words behind colons, the best approach would be to use regex to match the Customer and Rep strings before the colons, and then insert newlines so that the appropriate format is obtained.
The following is one working example:
import re
# The data has been stored into a string by this point
data = "Rep: hi ! Customer: i was wondering if you have a delivery option? If so what are the options available ? Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options. Customer: ok! thank you Rep: Is there anything else that I can help you with? (Chat ended)"
# First insert the newlines before the first word before a colon
newlines = re.sub(r'(\S+)\s*:', r'\n\g<1>:', data)
# Remove the first newline and fix the (Chat ended) on the end
solution = re.sub(r'\(Chat ended\)', '\n(Chat ended)', newlines[1:])
print(solution)
> "Rep: hi !
Customer: i was wondering if you have a delivery option? If so what are the options available ?
Rep: i'd be happy to answer that for you! There is a 2 and 5 day delivery options.
Customer: ok! thank you
Rep: Is there anything else that I can help you with?
(Chat ended)"
Explanation
The newlines = re.sub... line first searches the data string for any non-space-delimited word followed by a colon, and then replaces it with a \n character followed by whatever the sequence of non-space characters was matched, \S+ (which could be Customer, Rep, Bill, etc.), and then inserts the : at the end.
Finally, assuming that all conversations end with (Chat ended), the line of code afterwards matches for only that text and moves it onto a new line in the same manner as the newlines = re.sub... line does.
The output is a string, but if you need it to be anything else, you can split it based on '\n' and do what you have to do after that.
So you basically want to identify where you want to insert newlines - as such you could try a couple different patterns, if it's always "customer" and "rep":
(?<!^)(Customer:|Rep:|\(Chat ended) demo
We just check that we are not at start of the string and then match the constant tokens by OR'ing them together. Or more generically,
(?<=\s)([A-Z]\w+:|\(Chat ended) demo
We look back to see a space (we're not at start of string) and then match CapitalizedWord+COLON or ending sequence, then insert newlines before each match.
substitution for both:
\n$0

Usage of REGEXP with a token from dictionary for creating an annotation in UIMA

I need to mark an annotation with the use of regular expression and a token from a dictionary. Here is my rule
ANY{REGEXP("new"), Book.names.ct == "personal book" -> MARK (NewPersonalBook)};
that has to work with the following input:
new personal book application
open a new personal book
The programm shows no errors in the code but it doesn't mark the annotation "NewPersonalBook" for the input.
How is it possible to fix the problem?
I'm not sure if I understood your case but I tried to replicate what you're trying to do
I created a wordlist personal book, nicebook
Then I have my text example
new personal book application. open a new personal book. my new nicebook is nice.
The script
WORDLIST BooksList = 'books.txt';
DECLARE Book, NewBook;
Document{-> MARKFAST(Book, BooksList)};
W{REGEXP("new")} Book.ct == "personal book" {-> MARK(NewBook, 1, 2)}; //if you want to test a specific text
W{REGEXP("new")} Book {-> MARK(NewBook, 1, 2)}; //this will annotate NewBook for a books with the word new before it
If you dont want the "new" word with the annotation you need to remove the integer parameters (as they indicate the span that you want covered, in this case the first matched text "new" and the second which will be the book text)
Disclaimer: I'm new to UIMA RUTA, hope this helps

Remove Image Tag of a string in R

Here is a piece of strings after I xpathSapply() a xml file into R.
test <-
"Nothing screams the holidays quite like a honey baked ham from the infamous < a href=\"http://www.honeybaked.com/\">Honey Baked Ham Co< /a>. This molasses-y monstrous brown sugar encrusted pork dream come true was a staple at my family Christmas dinner table. Did you know that this artery clogging bit of Americana makes plenty of trimmings to pair with that big ole ham? HBH Co. is now serving up some killer casseroles to pair with that sugar-soaked pig-pile you’ve had good and bad dreams about.\n\nNow I know what you’re thinking, what does honeyed ham or a bunch of beautiful casseroles have to do with wine? Quiet thy fluttering heart… I give you the FIVE wine pairings for the perfect Honey Baked Ham Co. Holiday feast!\n\n \n\n<strong>1)</strong>"
My boss asked me to count number of words in this string, but I need to remove the image first.
I try to remove the image in this string, this:
< a href=\"http://www.honeybaked.com/\">Honey Baked Ham Co < /a>
I am new to regular expression and try unlist(strsplit(test, split = " ")) first and then grep the index of "< a" and "a>", and then remove everything between these two index.
But is there any efficient way to do this?
First, remove everything between and within "<" and "/a>" with sub:
cleared <- sub("<.*/a>", "", test)
Then, simply count the words:
wordsCount <- length(unlist(strsplit(cleared," ")))

Find all paragraphs of text that are related to a topic

Given a set of words ["college", "sports", "coding"], and a set of paragraphs of text (i.e. facebook posts), how can I see for each word the paragraphs that are related to that topic?
So for college, how can I find all the paragraphs of text that may be about the topic college?
I'm new to natural language processing, and not very advanced at regex. Clues about how to get started, what the right terms to google, etc are appreciated.
One basic ideea would be to iterate over your posts and see if any post matches any of the topic.
Let's say we have the following posts:
Post 1:
Dadadad adada college fgdssfgoksh jkhsfdkjshdkj sports hfjkshgkjshgjhsdgjkhskjgfs.
Post 2:
Sports dadadad adada fgdssfgoksh jkhsfdkjshdkj hfjkshgkjshgjhsdgjkhskjgfs.
Post 3:
Coding adskjdsflkshdflksjlg lsdjk hsjdkh kdsafkj asfjkhsa coding fhksajhdf kjhskfhsfd ssdggsd.
and the following topics:
["college", "sports", "coding"]
The regex could be: (topicName)+
E.g.: (college)+ or (sports)+ or (coding)+
Small pseudocode:
for every topicName
for every post
var customRegex = new RegExp('(' + topicName + ')+');
if customRegex.test(post) then
//post matches topicName
else
//post doesn't match topicName
endif
endfor
endfor
Hope it could give you a starting point.
Exact string matching won't take you far, especially with small fragments of text. I suggest you to use semantic similarity for this. A simple web search will give several implementations.

Parsing Exchange Recipients from a string with Regex

I'm about to break this down into two operations since I can't seem to figure out the regular expression to do it in one. However, I thought I would ask the brain trust here to see if anyone can do it (which I'm sure someone can).
Essentially I have a string containing a recipients field from an email in Exchange. I want to parse it out into individual recipients. I don't need to validate emails or anything. Essentially the data is comma separated except if the comma is in between a set of quotes. That's the part that's messing me up.
Right now I'm using: (?"[^"\r\n]*")
Which gives me the quoted names, and ([a-zA-Z0-9_-.]+)#(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})
which gives me the email addresses
Here's what I have..
Data:
"George Washington" <gwashington#government.net>, "Abraham Lincoln" <alincoln#government.net>, "Carter, Jimmy" <jimmy.carter#presidents.com>, "Nixon, Richard M." <tricky.dick#presidents.com>
What I'd like to get back is this:
"George Washington" <gwashington#government.net>
"Abraham Lincoln" <alincoln#government.net>
"Carter, Jimmy" <jimmy.carter#presidents.com>
"Nixon, Richard M." <tricky.dick#presidents.com>
I dont know enough about the exchange to get the pattern that will match for any exchange recipients entries.
But based on information past for you as an example. I give you this:
["][^"]+["][^",]+(?=[,]?)
This match all for entries that you post.
And know a simple example in C# how to use:
var input = "\"George Washington\" <gwashington#government.net>, \"Abraham Lincoln\" <alincoln#government.net>, \"Carter, Jimmy\" <jimmy.carter#presidents.com>, \"Nixon, Richard M.\" <tricky.dick#presidents.com>";
var pattern = "[\"][^\"]+[\"][^\",]+(?=[,]?)";
var items = Regex.Matches(input, pattern)
.Cast<Match>()
.Select(s => s.Value)
.ToList();
If there is a input text that this pattern dont work please post the input here.
Regex.Match(input, #"\"[^\"]*\"\s\<[^>]*>");