summary refs log tree commit diff stats
path: root/generator/part.cpp
blob: c354a07a66c2ad0d6b3387c9abcf37a968c2ae74 (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
#include "part.h"
#include <stdexcept>

namespace verbly {
  namespace generator {

    int part::nextId_ = 0;

    part part::createNounPhrase(std::string role, std::set<std::string> selrestrs, std::set<std::string> synrestrs)
    {
      return part(type::noun_phrase, noun_phrase_type {
        .role = std::move(role),
        .selrestrs = std::move(selrestrs),
        .synrestrs = std::move(synrestrs)
      });
    }

    part part::createVerb()
    {
      return part(type::verb);
    }

    part part::createPreposition(std::set<std::string> choices, bool literal)
    {
      return part(type::preposition, preposition_type {
        .choices = std::move(choices),
        .literal = literal
      });
    }

    part part::createAdjective()
    {
      return part(type::adjective);
    }

    part part::createAdverb()
    {
      return part(type::adverb);
    }

    part part::createLiteral(std::string value)
    {
      return part(type::literal, std::move(value));
    }

    part part::duplicate(const part& other)
    {
      return part(other.type_, other.variant_);
    }

    std::string part::getNounRole() const
    {
      if (type_ == type::noun_phrase)
      {
        return std::get<noun_phrase_type>(variant_).role;
      } else {
        throw std::domain_error("part::getNounRole is only valid for noun phrase parts");
      }
    }

    std::set<std::string> part::getNounSelrestrs() const
    {
      if (type_ == type::noun_phrase)
      {
        return std::get<noun_phrase_type>(variant_).selrestrs;
      } else {
        throw std::domain_error("part::getNounSelrestrs is only valid for noun phrase parts");
      }
    }

    std::set<std::string> part::getNounSynrestrs() const
    {
      if (type_ == type::noun_phrase)
      {
        return std::get<noun_phrase_type>(variant_).synrestrs;
      } else {
        throw std::domain_error("part::getNounSynrestrs is only valid for noun phrase parts");
      }
    }

    std::set<std::string> part::getPrepositionChoices() const
    {
      if (type_ == type::preposition)
      {
        return std::get<preposition_type>(variant_).choices;
      } else {
        throw std::domain_error("part::getPrepositionChoices is only valid for preposition parts");
      }
    }

    bool part::isPrepositionLiteral() const
    {
      if (type_ == type::preposition)
      {
        return std::get<preposition_type>(variant_).literal;
      } else {
        throw std::domain_error("part::isPrepositionLiteral is only valid for preposition parts");
      }
    }

    std::string part::getLiteralValue() const
    {
      if (type_ == type::literal)
      {
        return std::get<literal_type>(variant_);
      } else {
        throw std::domain_error("part::getLiteralValue is only valid for literal parts");
      }
    }

  };
};