<commit_before># Mr. Mongo

[![Build Status](https://travis-ci.org/yuya-takeyama/mr_mongo.png?branch=master)](https://travis-ci.org/yuya-takeyama/mr_mongo)
[![Coverage Status](https://coveralls.io/repos/yuya-takeyama/mr_mongo/badge.png?branch=master)](https://coveralls.io/r/yuya-takeyama/mr_mongo)

MapReduce framework for MongoDB using Ruby DSL

## Installation

Add this line to your application's Gemfile:

    gem 'mr_mongo'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install mr_mongo

## Usage

### mr_mongo command

```
$ bundle exec mr_mongo
Commands:
  mr_mongo exec            # executes MapReduce
  mr_mongo exec_on_memory  # executes MapReduce on memory
  mr_mongo help [COMMAND]  # Describe available commands or one specific command
```

*NOTICE*

The result of exec_on_memory may be massive, so it's preferable to use for small collections as testing.

### Defining MapReduce job using DSL

Following is word-count example using Mr. Mongo DSL

```ruby
set :collection, 'texts'
set :out, {replace: 'word_counts'}

__END__

@@ map
function () {
  this.text.split(/\s+/).forEach(function (word) {
    emit(word, {count: 1});
  });
}

@@ reduce
function (key, values) {
  var count = 0;

  values.forEach(function (value) {
    count += value.count;
  });

  return {count: count};
}
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request<commit_msg>Add document about Dynamic Parameters and Default Parameter<commit_after># Mr. Mongo

[![Build Status](https://travis-ci.org/yuya-takeyama/mr_mongo.png?branch=master)](https://travis-ci.org/yuya-takeyama/mr_mongo)
[![Coverage Status](https://coveralls.io/repos/yuya-takeyama/mr_mongo/badge.png?branch=master)](https://coveralls.io/r/yuya-takeyama/mr_mongo)

MapReduce framework for MongoDB using Ruby DSL

## Installation

Add this line to your application's Gemfile:

    gem 'mr_mongo'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install mr_mongo

## Usage

### mr_mongo command

```
$ bundle exec mr_mongo
Commands:
  mr_mongo exec            # executes MapReduce
  mr_mongo exec_on_memory  # executes MapReduce on memory
  mr_mongo help [COMMAND]  # Describe available commands or one specific command
```

*NOTICE*

The result of exec_on_memory may be massive, so it's preferable to use for small collections as testing.

### Defining MapReduce job using DSL

Following is word-count example using Mr. Mongo DSL

```ruby
set :collection, 'texts'
set :out, {replace: 'word_counts'}

__END__

@@ map
function () {
  this.text.split(/\s+/).forEach(function (word) {
    emit(word, {count: 1});
  });
}

@@ reduce
function (key, values) {
  var count = 0;

  values.forEach(function (value) {
    count += value.count;
  });

  return {count: count};
}
```

### Dynamic Parameters

sub-commands `exec` and `exec_on_memory` accepts *Dynamic Parameters* by `--params` option.

`--params` can be specified as JSON hash.

```
$ bundle exec mr_mongo exec some_map_reduce.rb --params '{"date":"2013-02-01"}'
```

In DSL, Dynamic Parameters can be get with `#params` method.

```ruby
set :collection, 'accesses'
set :query, {date: params['date']} if params['date']

__END__

...
```

### Default Parameter

Default Parameter can be set with `#default_param` method

```ruby
default_param 'date', '2013-02-01'

# => params will be {"date" => "2013-02-01"} by default.
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
{'fraction_non_alphanumeric': 0.13153058545550014, 'fraction_numerical': 0.009976371751115778, 'mean_word_length': 4.066489361702128, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1902080', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1273, 'n_words': 396}