pos.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. class POS {
  2. public:
  3. enum class InternalType {
  4. Noun = 0,
  5. Plural,
  6. NounPhrase,
  7. VerbParticiple,
  8. VerbTransitive,
  9. VerbIntransitive,
  10. Adjective,
  11. Adverb,
  12. Conjunction,
  13. Preposition,
  14. Interjection,
  15. Pronoun,
  16. ArticleDefinite,
  17. ArticleIndefinite,
  18. Nominative,
  19. };
  20. enum class PrimitiveType {
  21. Noun = ((int)InternalType::Noun | (int)InternalType::NounPhrase),
  22. Verb = ((int)InternalType::VerbParticiple | (int)InternalType::VerbTransitive | (int)InternalType::VerbIntransitive),
  23. Adjective = ((int)InternalType::Adjective),
  24. Adverb = ((int)InternalType::Adverb),
  25. Preposition = ((int)InternalType::Preposition),
  26. Interjection = ((int)InternalType::Interjection),
  27. Conjunction = ((int)InternalType::Conjunction),
  28. Pronoun = ((int)InternalType::Pronoun),
  29. Article = ((int)InternalType::ArticleDefinite | (int)InternalType::ArticleIndefinite),
  30. };
  31. bool is(InternalType t) {
  32. return data & (1 << (int)t);
  33. };
  34. bool is(PrimitiveType t) {
  35. return data & (1 << (int)t);
  36. };
  37. bool isPlural() { return data & (int)InternalType::Plural; };
  38. POS(uint32_t types) {
  39. data = types;
  40. };
  41. POS(char* s) {
  42. while(*s && *s != '\n') {
  43. switch(*s) {
  44. case 'N': data &= (int)InternalType::Noun; break;
  45. case 'p': data &= (int)InternalType::Plural | (int)InternalType::Noun; break;
  46. case 'h': data &= (int)InternalType::NounPhrase; break;
  47. case 'V': data &= (int)InternalType::VerbParticiple; break;
  48. case 't': data &= (int)InternalType::VerbTransitive; break;
  49. case 'i': data &= (int)InternalType::VerbIntransitive; break;
  50. case 'A': data &= (int)InternalType::Adjective; break;
  51. case 'v': data &= (int)InternalType::Adverb; break;
  52. case 'C': data &= (int)InternalType::Conjunction; break;
  53. case 'P': data &= (int)InternalType::Preposition; break;
  54. case '!': data &= (int)InternalType::Interjection; break;
  55. case 'r': data &= (int)InternalType::Pronoun; break;
  56. case 'D': data &= (int)InternalType::ArticleDefinite; break;
  57. case 'I': data &= (int)InternalType::ArticleIndefinite; break;
  58. case 'o': data &= (int)InternalType::Nominative; break;
  59. //case '|':
  60. //default:
  61. // nothing
  62. }
  63. s++;
  64. }
  65. };
  66. private:
  67. uint32_t data;
  68. };