README.md 2.96 KB
Newer Older
1
# JityTagGeneratorBundle
Hermann Mayer's avatar
Hermann Mayer committed
2

3 4
[![Build Status](http://jenkins.jity.de/job/jity-tag-generator/badge/icon)](http://jenkins.jity.de/job/jity-tag-generator/)

5
## About
Hermann Mayer's avatar
Hermann Mayer committed
6

7 8 9
This bundle is part of the Jity project. With the help of this
generator you be able to transform any text to a usefull collection of tags.

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
## Installation

Add JityTagGenerator to your composer.json:

    {
        "require": {
            "jity/tag-generator": "dev-master"
        }
    }

Download bundle:

    php composer.phar update

Add the JityTagGenerator to your AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            ...
            new Jity\TagGeneratorBundle\JityTagGeneratorBundle(),
            ...
        );
        ...
    }

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
## Usage

This is a simple example how to use the TagGenerator.

    use Jity\Tag\TagGenerator,
        Jity\Tag\Filter\Score,
        Jity\Tag\Filter\ScoreGroup,
        Jity\Tag\Filter\Length,
        Jity\Tag\Filter\Occurrence,
        Jity\Tag\Filter\Dictionary,
        Jity\Tag\Filter\Capitalized,
        Jity\Tag\Filter\Uppercase,
        Jity\Tag\Filter\Camelcase,
        Jity\Tag\Filter\Regex;
    
    /* ------------------------------------------------------ */
    /* - Configuration */
    /* ------------------------------------------------------ */
    
    // Instantiate a new Generator
    $generator = new TagGenerator();
    
    // Configure all Filters
    $generator
    
        /* Remove words shorter than 3 chars */
        ->addFilter(
            new Length(1, true, array(
                'min' => 2
            ))
        )
    
        /* Remove most useless words from collection (stop-words) */
        ->addFilter(
            new Dictionary(1, true, array(
                'match'         => true,
                'casesensitive' => false,
                'dictionaries'  => array(
                    'german'    => array(
                        'adjektive',
                        'verben',
                        'klein',
                        'fixwords'
                    )
                )
            ))
        )  
    
        /* Score occurrence of remaining words */
        ->addFilter(
            new Occurrence(5)
        ) 
    
        /* Score uppercased words */
        ->addFilter(new Uppercase(15))
    
        /* Score camelcased words */
        ->addFilter(new Camelcase(15))
    
        /* Score capitalized words */
96
        ->addFilter(new Capitalized(5));
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    
    // Receive the collection of tags
    $tags = $generator->getTags('Lorem ipsum etc');


## Development

### Write own filters

All you need to do this is to implement Jity\Tag\Filter\FilterInterface or
extend Jity\Tag\Filter\AbstractFilter. A good and simple example is the
Jity\Tag\Filter\Uppercase filter. Just have a look at this.

### Recompile a dictionary

Go to resources/dictionaries/LANG/source and run:

114
    for i in stopwords fixwords adjektive verben compound klein verben worte; do cat source/${i}*.txt | ../compiler.sh "$i"; done
Hermann Mayer's avatar
Hermann Mayer committed
115