4
$\begingroup$

This question already has an answer here:

I have a list of french stopwords:

frenchStopWords = {"alors", "au", "aucuns", "aussi", "autre", "avant", "avec", "avoir", \
"bon", "car", "ce", "cela", "ces", "ceux", "chaque", "ci", "comme", \
"comment", "dans", "des", "du", "dedans", "dehors", "depuis", \
"devrait", "doit", "donc", "dos", "début", "elle", "elles", "en", \
"encore", "essai", "est", "et", "eu", "fait", "faites", "fois", \
"font", "hors", "ici", "il", "ils", "je", "juste", "la", "le", "les", \
"leur", "là", "ma", "maintenant", "mais", "mes", "mine", "moins", \
"mon", "mot", "même", "ni", "nommés", "notre", "nous", "ou", "où", \
"par", "parce", "pas", "peut", "peu", "plupart", "pour", "pourquoi", \
"quand", "que", "quel", "quelle", "quelles", "quels", "qui", "sa", \
"sans", "ses", "seulement", "si", "sien", "son", "sont", "sous", \
"soyez", "sujet", "sur", "ta", "tandis", "tellement", "tels", "tes", \
"ton", "tous", "tout", "trop", "très", "tu", "voient", "vont", \
"votre", "vous", "vu", "ça", "étaient", "état", "étions", "été", \
"être"};

And some french text here:

text = {"et", "bien", "bonjour,", "vous", "avez", "déjà", "suivi,", \
"peut-être", "le", "cours", "electronique", "et,", "voilà,", "ça", "c\
\[CloseCurlyQuote]est", "le", "cours", "electronique", "ii,", "c\
\[CloseCurlyQuote]est", "une", "suite", "logique", "du", "premier", \
"cours,", "dans", "le", "premier", "cours", "dans", "l\
\[CloseCurlyQuote]électronique", ",", "étudié,", "tout", "ce", "qui", \
"était", "lié", "aux", "fonctions,", "électroniques", "basées", \
"sur", "les", "amplificateurs,", "opérationnels.", "dans", "ce", \
"cours", "là,,", "va", "aborder", "le", "transistor", "bipolaire,", \
"et", "les", "fonctions", "analogiques", "de", "base.,", "donc", \
"va", "partir", "avec", "toutes,", "les", "fonctions", "de", "base", \
"depuis", "l\[CloseCurlyQuote]analyse,", "du", "transistor", "jusqu\
\[CloseCurlyQuote]à", "ce", "qu\[CloseCurlyQuote],", "arrive", \
"avec", "des", "fonctions", "un", "peu,", "plus", "complexes,", "du", \
"style", "analyser", "un,", "régulateur", "série", "et", "terminer", \
"avec,", "l\[CloseCurlyQuote]analyse", "des", "circuits", "tels", \
"que,", "les", "amplificateurs", "de", "puissance,", "et", "les", \
"amplificateurs", "audio.", "donc", "si", "regarde", "ce", "cours,,", \
"va", "se", "rendre", "compte", "que", "la", "suite,", "d\
\[CloseCurlyQuote]electronique", "c\[CloseCurlyQuote]est", \
"electronique", "ii", ".,", "je", "vais", "aller", "dans", "ce", \
"cours,", "et", "voir", "ce", "qui", "va", "se", "passer.,", "je", \
"vais", "aller", "là-dedans,", "et", "voir", "comment", "c\
\[CloseCurlyQuote]est", "structuré", "ce", "cours.,", "donc,", \
"exactement", "de", "la", "même", "manière", "que", "electronique", \
",", "va", "trouver,", "les", "semaines.,", "il", "y", "l\
\[CloseCurlyQuote]équivalent", "de", "8", "semaines,", "d\
\[CloseCurlyQuote]études,", "dont", "deux", "examens.,", "un", \
"examen"};

Now I want to delete all stopwords. I tried:

DeleteCases[text,#]&/@frenchStopWords

...but this is wrong. I know that I need to use an "OR" operator, but I don't know how to implment it without running a for loop. Thanks.

$\endgroup$

marked as duplicate by Anton Antonov, Mr.Wizard Oct 27 '18 at 21:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8
$\begingroup$

Alternatives are often overlooked DeleteCases:

DeleteCases[text, Alternatives@@frenchStopWords]

While Complement in the comments seems equivalent, it does not accept patterns, and DeleteCases does, which would account for more general cases. This is why it is useful to remember Alternatives usage in DeleteCases.

$\endgroup$
  • $\begingroup$ thank you very much ! I did not know about Alternatives indeed ! $\endgroup$ – james Oct 28 '18 at 7:19

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