MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Computing n-grams

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89051] Re: Computing n-grams
  • From: Seth Chandler <sethchandler at mac.com>
  • Date: Sat, 24 May 2008 03:56:59 -0400 (EDT)
  • References: <g11r2s$aaa$1@smc.vnet.net>

On May 21, 12:53 pm, "Coleman, Mark" <Mark.Cole... at LibertyMutual.com>
wrote:
> Greetings,
>
> Imagine one has a list such as {a,b,c,d,e,f,g}. I'm trying to find an
> efficient way in Mathematica to compute then-gramsof the list. That is, for
> n=2, then-gramsare all the lists of length 2 consisting of consecutive
> elements, e.g.,
>
> {a,b},{b,c},{c,d},{d,e},...
>
> While for n=3,
>
> {a,b,c},{b,c,d},{c,d,e},..., and so on.
>
> As I understand it, the built-in Mathematica commands such as Subsets or
> Permutations compute all possible list of size n, without regard to the
> order of the list elements.
>
> Thanks,
>
> Mark

There are two Demonstrations that deal with n-grams that may be of
interest to you and that have code for finding n-grams. They are
http://demonstrations.wolfram.com/CollocationBySymmetricConditionalProbability/
and  http://demonstrations.wolfram.com/Tries/


  • Prev by Date: Re: Is it possible to solve this differential equation?
  • Next by Date: Re: How to plot a graph, using a distance matrix
  • Previous by thread: Re: Computing n-grams
  • Next by thread: strange behaviour of Integration