Git Product home page Git Product logo

ling473-proj2's Introduction

Project 2

Task

Given a directory containing a SGML-tagged corpus, write a program to generate a unigram model and print the results in descending order based on frequency.

Results

The top 15 words are

word frequency
the 4398064
a 2032214
to 1893205
of 1888409
and 1759680
in 1486132
that 814646
for 793617
is 712518
on 564762
by 559404
with 512398
he 494957
it 484405
at 463595

Approach

Because the definition of a unigram was slightly different than a traditional unigram's definition, some preprocessing became necessary.

For each line in every file, I split on whitespace, removed all tags from those post-split tokens, parsed out all acceptable words by a RegEx ([A-Za-z']+).

Because some words started or ended with apostrophes and we only want internal apostrophes, trimming prefixed and suffixed apostrophes needed to be done.

At this point, all words were converted to lowercase and empty strings were removed. Finally, all words were aggregated into a map.

This was done for each file and the resultant unigram models were aggregated.

Tools

For this project, I used primarily the Scala standard library with the exception of two libraries:

  • Scalaz, a functional library for Scala, which I used to facilitate merging of per-file unigram maps.
  • Scalatest, a unit testing library for Scala.

Testing

Unit tests were written to cover both file processing (i.e., per-file unigram models) and directory processing (i.e., merged unigram models).

To do

Write more tests to cover more edge cases.

ling473-proj2's People

Contributors

erip avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.