# Avoid DeleteStopwords to unproperly break hyphenated words?

**URL:** <https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450>\
**Category:** Questions\
**Tags:** computational-linguistics\
**Created:** [December 17, 2018, 6:54pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450 "2018-12-17T18:54:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kn](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kn/32/18980_2.png) [@kn](https://community.wolfram.com/u/kn)\
**Post date:** [December 17, 2018, 6:54pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/1 "2018-12-17T18:54:20Z")

</div>

Hi, friends

Please, consider the example

```
TextWords["through the mechanism of follow-up of living patients 
the natural history of various diseases of military-medical 
importance"]
DeleteStopwords[%]

```

First operation performs as needed:

{“through”, “the”, “mechanism”, “of”, “follow-up”, “of”, “living”,  
“patients”, “the”, “natural”, “history”, “of”, “various”, “diseases”,  
“of”, “military-medical”, “importance”}

But the last cuts the ending of “ **follow-up** ”:

{“mechanism”, “follow-”, “living”, “patients”, “natural”, “history”,  
“various”, “diseases”, “military-medical”, “importance”}

Can such the trouble be fixed by standard means of _Mathematica_ text normalization?

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [December 17, 2018, 7:46pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/2 "2018-12-17T19:46:31Z")

</div>

That looks like a bug. I would report it to [Wolfram Support](http://www.wolfram.com/support/contact/email/?topic=Feedback). One workaround would be to remove trailing hyphens.

```
sentence = "through the mechanism of follow-up of living patients 
the natural history of various diseases of military-medical 
importance";
sentence // TextWords // DeleteStopwords // StringReplace["-" ~~ EndOfString -> ""]

(* {"mechanism", "follow", "living", "patients", "natural", "history", "various", "diseases", "military-medical", "importance"} *)

```

---

<div class="post-metadata">

**Author:** ![kn](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kn/32/18980_2.png) [@kn](https://community.wolfram.com/u/kn)\
**Post date:** [December 17, 2018, 8:58pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/3 "2018-12-17T20:58:56Z")

</div>

Thanks, Rohit

But I suppose that stop words should not crack the words. If **follow-up** is not a stop word, **DeleteStopwords** has to remain it untouched.

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [December 17, 2018, 9:46pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/4 "2018-12-17T21:46:42Z")

</div>

Hi Konstantin,

I completely agree, which is why I suggested reporting it to Wolfram Support as a bug.

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [December 17, 2018, 10:21pm UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/5 "2018-12-17T22:21:02Z")

</div>

There might be a workaround.

First of all we can determine the list of stop words in the Wolfram Language:

```
stopWords = ToLowerCase@Complement[DictionaryLookup["*"], DeleteStopwords[DictionaryLookup["*"]]]; 

```

My first attempt was to use Complement, but it reorders the list of words alphabetically, This, however, does appear to work:

```
myDeleteStopwords[list_] := Select[list, ! MemberQ[stopWords, ToLowerCase[#]] &]

```

This might be less efficient than the built in function. Let’s try this on AliceInWonderland:

```
text = TextWords@ExampleData[{"Text", "AliceInWonderland"}];

myDeleteStopwords[text]; // AbsoluteTiming

DeleteStopwords[text]; // AbsoluteTiming

```

on my machine myDeleteStopwords takes 0.081037 seconds to run and DeleteStopwords takes 0.087887, so that are practically equally fast.

You might also want to look at the stop words that are built into the Wolfram Language. myDeleteStopwords might give you more flexibility if you want to choose different lists.

Cheers,

Marco

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [December 18, 2018, 12:50am UTC](https://community.wolfram.com/t/avoid-deletestopwords-to-unproperly-break-hyphenated-words/13450/6 "2018-12-18T00:50:44Z")

</div>

To get the list of built-in stop words.

```
WordList["Stopwords"]

```

or

```
WordData[All, "Stopwords"]

```
