summaryrefslogtreecommitdiffstats
path: root/linguistics/src/main/java/com/yahoo/language/process/TokenType.java
blob: 14c7e9bc144e4d70afd3c96b2bdae6abd226256b (plain) (blame)
1
2
3
4
5
6
7
8
9
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.language.process;

/**
 * An enumeration of token types.
 *
 * @author Mathias Mølster Lidal
 */
public enum TokenType {

    UNKNOWN(0),
    SPACE(1),
    PUNCTUATION(2),
    SYMBOL(3),
    ALPHABETIC(4),
    NUMERIC(5),
    MARKER(255);

    private final int value;

    TokenType(int value) {
        this.value = value;
    }

    /** Returns an int code for this type */
    public int getValue() { return value; }

    /**
     * Marker for whether this type of token can be indexed for search.
     * Note that a Token can be excluded from an index, even though the token type marks
     * it as indexable.
     *
     * @see com.yahoo.language.process.Token#isIndexable()
     * @return whether this type of token can be indexed
     */
    public boolean isIndexable() {
        switch (this) {
            case ALPHABETIC: case NUMERIC: return true;
            default: return false;
        }
    }

    /** Translates this from the int code representation returned from {@link #getValue} */
    public static TokenType valueOf(int value) {
        for (TokenType type : values()) {
            if (value == type.value) return type;
        }
        return UNKNOWN;
    }

}