1
$\begingroup$

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?

$\endgroup$
2
$\begingroup$
ClearAll[syllablesF]
syllablesF = # /. DataPaclets`WordDataDump`WordDataHyphenationRules &;
string = "Our_Pronoun were_Verb journey_Noun had_Verb replace_Verb  advanced_Verb";

StringReplace[string, 
 " " ~~ 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})"

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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