Blame view

morfeusz/Dictionary.cpp 2.55 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* 
 * File:   Dictionary.cpp
 * Author: lennyn
 * 
 * Created on August 8, 2014, 3:15 PM
 */

#include "Dictionary.hpp"
#include "charset/CharsetConverter.hpp"
#include "deserialization/MorphDeserializer.hpp"

using namespace std;

namespace morfeusz {

    static Deserializer<InterpsGroupsReader>& initializeDeserializer(MorfeuszProcessorType processorType) {
        static Deserializer<InterpsGroupsReader> *analyzerDeserializer
                = new MorphDeserializer();
        static Deserializer<InterpsGroupsReader> *generatorDeserializer
                = new MorphDeserializer();
        return *(processorType == ANALYZER ? analyzerDeserializer : generatorDeserializer);
    }
Michał Lenart authored
23
Michał Lenart authored
24
25
    static set<string> getAvailableOptions(const map<SegrulesOptions, SegrulesFSA*> segrulesFSAsMap, const string& option) {
        set<string> res;
Michał Lenart authored
26
27
        for (
                map<SegrulesOptions, SegrulesFSA*>::const_iterator it = segrulesFSAsMap.begin();
Michał Lenart authored
28
29
30
31
32
33
                it != segrulesFSAsMap.end();
                ++it) {
            res.insert(it->first.find(option)->second);
        }
        return res;
    }
Michał Lenart authored
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

    Dictionary* Dictionary::getEmpty() {
        static Dictionary* dict = new Dictionary();
        return dict;
    }

    Dictionary::Dictionary()
    : fsa(NULL),
    idResolver(),
    separatorsList(),
    segrulesFSAsMap(),
    defaultSegrulesOptions(),
    defaultSegrulesFSA(NULL),
    availableAgglOptions(),
    availablePraetOptions() {
    }
Michał Lenart authored
50
51

    Dictionary::Dictionary(const unsigned char* fsaFileStartPtr, MorfeuszProcessorType processorType)
Michał Lenart authored
52
53
    : fsa(FSAType::getFSA(fsaFileStartPtr, initializeDeserializer(processorType))),
    idResolver(fsaFileStartPtr, &UTF8CharsetConverter::getInstance()),
Michał Lenart authored
54
55
56
    separatorsList(getSeparatorsList(fsaFileStartPtr)),
    segrulesFSAsMap(createSegrulesFSAsMap(fsaFileStartPtr)),
    defaultSegrulesOptions(getDefaultSegrulesOptions(fsaFileStartPtr)),
Michał Lenart authored
57
    defaultSegrulesFSA(getDefaultSegrulesFSA(this->segrulesFSAsMap, fsaFileStartPtr)),
Michał Lenart authored
58
    availableAgglOptions(getAvailableOptions(segrulesFSAsMap, "aggl")),
Michał Lenart authored
59
    availablePraetOptions(getAvailableOptions(segrulesFSAsMap, "praet")) {
Michał Lenart authored
60
    }
Michał Lenart authored
61
62
63
64
65
66
67
68

    bool Dictionary::isCompatibleWith(const Dictionary& other) const {
        return this->idResolver.isCompatibleWith(other.idResolver)
                && this->availableAgglOptions == other.availableAgglOptions
                && this->availablePraetOptions == other.availablePraetOptions
                && this->defaultSegrulesOptions == other.defaultSegrulesOptions
                && this->separatorsList == other.separatorsList;
    }
Michał Lenart authored
69
}