Message Boards Message Boards

2
|
3824 Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

Bigram lookup in Association

Posted 10 years ago

I'm creating a list of bigrams from a document like this:

bigrams = WordCounts[Document, 2]

This gives me an association with the number of times a bigram appears. What I need to be able to do is lookup a key, The data looks like this:

<|{"of", "the"} -> 517, {"to", "the"} -> 371, {"in", "the"} ->  361, {"united", "states"} -> 245,|>

I've also got a list of bigram stop words.

stopWords = WordData[All, "Stopwords"];
bigramStopWords = Tuples[stopWords, 2];

What I'm looking to do is remove all instances in the stopwords list from the bigram list. I can't figure out how to do a lookup with the association being made up of a two item list. Any help would be appreciated.

POSTED BY: Buck Huffman

Can you delete stop words beforehand?

text = ExampleData[{"Text", "OriginOfSpecies"}];    
bigrams = WordCounts[DeleteStopwords[text], 2]

enter image description here

BTW, whatever the Key is you can extract with it:

bigrams[{"natural", "selection"}]
(* Out[] = 234 *)
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract