I'm working on a program that deals with 'part-of-speech tagged' strings such as "I_Pronoun am_Verb a_Determiner human_Noun". What I want to do is replace each verb with Verb+number of syllables of the word, which I can accomplish with this:

StringReplace["Our_Pronoun journey_Noun had_Verb advanced_Verb", {" "~~ 
x___ ~~ "_Verb" .. :> " Verb"<>syllables[x]}]

This works great (it doesn't match verbs at the beginning of the sentence, but surprisingly this is also what I want). Now, I want to make it so it matches all verbs except specific ones. So if I have a list like verbBlacklist={"had","were"} and modify the above code such that everything is the same but 'had' and 'were' are no longer matched.

I have no idea how to do this with string patterns. I've seen Except for characters, is there an equivalent for words?


1 Answer 1

syllablesF = # /. DataPaclets`WordDataDump`WordDataHyphenationRules &;
string = "Our_Pronoun were_Verb journey_Noun had_Verb replace_Verb  advanced_Verb";

 " " ~~ x : (Except["_"] ..) ~~ "_Verb" /; StringFreeQ[x, "had" | "were"] :> 
  " (Verb + " <> ToString[syllablesF[x]] <> ")"]

"Our_Pronoun were_Verb journey_Noun had_Verb (Verb + {re, place}) (Verb + {ad, vanced})"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.