Skip to content

mod_mecab is an apache HTTP server extension. The function is to dump result of parsing by MeCab.

Notifications You must be signed in to change notification settings

kahagon/mod_mecab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mod_mecab

Dependencies

mod_mecab uses some libraries. you must also install these libraries to build mod_mecab.

apache development utils
json-c
libapreq2
libmecab1
if you use Ubuntu, you can install these libraries with below.

    apt-get install apache2-prefork-dev libjson0-dev libapreq2-dev libmecab-dev
                
on Fedora,

    yum install httpd-devel json-c-devel libapreq2-devel mecab-devel
                
Intall

before installing, you must check Makefile variables and directive below.

${top_srcdir} (variable)
${top_builddir} (variable)
include (directive)
values of these variables, is specified path to directory of apache build utilities.
on Ubuntu, the path is /usr/share/apache2. on Fedora, /usr/lib/httpd.
you must check these variables and rewrite value if you need.

installing command is below. Run terminal and type these command.

    git clone https://github.com/oasynnoum/mod_mecab.git
    cd mod_mecab
    make
    make install
                
Settings

add LoadModule directive to your apache conf file.
    LoadModule mecab_module     /usr/lib/apache2/modules/mod_mecab.so
                
create a file which named mecab.conf in your conf.d directory.
    <IfModule mod_mecab.c>
        <Location /mecab>
            SetHandler mecab
        </Location>

        # the name of query param name
        TargetQueryName q

        # the name of environment variable which is MeCab parsing result.
        # if you use PHP, you can get result by next code.
        # mod_mecab_object = json_encode(getenv('MECAB_JSON'));.
        MecabJsonEnvName MECAB_JSON
    </IfModule mod_mecab.c>
                

Usage

you can get MeCab result JSON from environment variables. show example code below.

PHP

    <?php
    header('Content-Type: text/plain; charset=UTF-8', true);
    var_dump(json_decode(getenv('MECAB_JSON')));
                
Perl

    #!/usr/bin/perl
    use strict;
    use warnings;
    use utf8;
    use JSON;
    use Data::Dumper;

    print "Content-Type: text/plain; charset=UTF-8\r\n\r\n";
    print Dumper(decode_json($ENV{'MECAB_JSON'}));

                
HTML/JavaScript

<!DOCTYPE html>
<html>
    <head>
        <title>mod_mecab testing</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript">
            jQuery(function() {
                jQuery("#parse").click(function (ev) {
                    jQuery.ajax({
                        url : "/mecab",
                        data : {
                            q : jQuery("#input").val()
                        },
                        dataType : "json",
                        success : function(data, textStatus, jqXHR) {
                            console.log(data);
                        }
                    });
                    return false;
                });
            });
        </script>
    </head>
    <body>
        <h1>mod_mecab testing</h1>
        <p>the result will appear in your JavaScript console.</p>
        <h2>input</h2>
        <form>
            <textarea cols="40" rows="10" id="input"></textarea>
            <button id="parse">parse</button>
        </form>
    </body>
</html>

About

mod_mecab is an apache HTTP server extension. The function is to dump result of parsing by MeCab.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published