Skip to main content
added 2 characters in body
Source Link
kglr
  • 403.4k
  • 18
  • 501
  • 959

I'm working on a program that deals with 'part-of-speech tagged' strings such as "I_Pronoun am_Verb a_Determiner human_Noun""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?

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?

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?

Source Link
Nico A
  • 3.7k
  • 1
  • 17
  • 29

Excluding some words in string patterns

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?