Creating and Displaying Trigrams with PowerShell

May 20, 2009

in PowerShell,WolframAlpha,trigrams,yUML

Trigrams are a special case of the N-gram, where N is 3. They are often used in natural language processing for doing statistical analysis of texts. WolframAlpha supports them and has a DNA example.

It looked liked  something fun to implement in PowerShell and diagram with the yUML script I put together.

All you need is PowerShell, an Internet connection and the script below to try it out.

If you’re running Windows 7, you’re good to go. PowerShell is installed out of the box.

WolframAlpha Triads

trigrams "AGCAGCTGACTGATCGTAGCTGACT"

image

PowerShell + yUML

trigrams ‘AGCAGCTGACTGATCGTAGCTGACT’

Function trigrams ($target) {
    Get-yUMLDiagram (Convert-ToyUml ( Create-Tree ( Get-Triads $target ) )) -show
}

image

Download the Script

I am not satisfied with Create-Tree function. It works but is not flexible.

Or, click here to view the file content

{ 1 trackback }

PowerShell Gotcha- almost
05.21.09 at 6:42 pm

{ 2 comments… read them below or add one }

Tobin Harris 06.11.09 at 8:22 pm

Wow, this looks ace! It’s really nice to see with people playing with yUML, kinda makes the project worthwhile!

Just a thought, could you post your scripts as blah.ps1.txt? It’s just that it’d be cool to see the scripts without unzipping.

Doug Finke 06.13.09 at 3:00 pm

Thanks Tobin. yUML is a neat piece of work. Thanks for the suggestion on uploading plain text.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contrat Creative Commons

© 2007-2012, Doug Finke