summary refs log tree commit diff stats
path: root/generator/generator.h
blob: 82dec6608fd68b88e8b3f5cf03f2f53a992d2594 (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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#ifndef GENERATOR_H_5B61CBC5
#define GENERATOR_H_5B61CBC5

#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <set>
#include <libxml/parser.h>
#include <hkutil/database.h>
#include <filesystem>
#include "notion.h"
#include "word.h"
#include "lemma.h"
#include "form.h"
#include "pronunciation.h"
#include "group.h"
#include "frame.h"

namespace verbly {

  enum class part_of_speech;

  namespace generator {

    class generator {
    public:

      // Constructor

      generator(
        std::string verbNetPath,
        std::string agidPath,
        std::string wordNetPath,
        std::string cmudictPath,
        std::string imageNetPath,
        std::string wordfreqPath,
        std::string outputPath,
        std::string imageNetOutput);

      // Action

      void run();

    private:

      // Subroutines

      void readWordNetSynsets();

      void readAdjectivePositioning();

      void readImageNetUrls();

      void readWordNetSenseKeys();

      void readVerbNet();

      void readAgidInflections();

      void readPrepositions();

      void readCmudictPronunciations();

      void readWordFrequency();

      void writeSchema();

      void writeVersion();

      void dumpObjects();

      void writeMerography();

      void writeMerophony();

      void readWordNetAntonymy();

      void readWordNetVariation();

      void readWordNetClasses();

      void readWordNetCausality();

      void readWordNetEntailment();

      void readWordNetHypernymy();

      void readWordNetInstantiation();

      void readWordNetMemberMeronymy();

      void readWordNetPartMeronymy();

      void readWordNetSubstanceMeronymy();

      void readWordNetPertainymy();

      void readWordNetSpecification();

      void readWordNetSimilarity();

      void analyzeDatabase();

      // Helpers

      std::list<std::string> readFile(std::string path, bool uniq = false);

      inline part_of_speech partOfSpeechByWnid(int wnid);

      notion& createNotion(part_of_speech partOfSpeech);

      notion& lookupOrCreateNotion(int wnid);

      lemma& lookupOrCreateLemma(std::string base_form);

      form& lookupOrCreateForm(std::string text);

      template <typename... Args> word& createWord(Args&&... args);

      void createGroup(xmlNodePtr top, const group* parent = nullptr);

      // Input

      std::string verbNetPath_;
      std::string agidPath_;
      std::string wordNetPath_;
      std::string cmudictPath_;
      std::string imageNetPath_;
      std::string wordfreqPath_;

      // Output

      hatkirby::database db_;
      std::filesystem::path imageNetOutput_;

      // Data

      std::list<notion> notions_;
      std::list<word> words_;
      std::list<lemma> lemmas_;
      std::list<form> forms_;
      std::list<pronunciation> pronunciations_;
      std::list<group> groups_;

      // Indexes

      std::map<int, notion*> notionByWnid_;
      std::map<int, std::set<word*>> wordsByWnid_;
      std::map<std::pair<int, int>, word*> wordByWnidAndWnum_;
      std::map<std::string, std::set<word*>> wordsByBaseForm_;
      std::map<std::string, lemma*> lemmaByBaseForm_;
      std::unordered_map<std::string, form*> formByText_;
      std::map<std::string, pronunciation*> pronunciationByPhonemes_;
      std::unordered_map<std::string, pronunciation*> pronunciationByBlankPhonemes_;
      std::map<std::string, int> anagramSets_;
      std::map<std::string, int> anaphoneSets_;

      // Caches

      std::map<std::string, word*> wnSenseKeys_;

    };

  };
};

#endif /* end of include guard: GENERATOR_H_5B61CBC5 */