forked from TUfischl/newdetkdecomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNamedEntity.h
executable file
·54 lines (40 loc) · 1.35 KB
/
NamedEntity.h
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
#pragma once
#if !defined(CLS_NAMEDENTITY)
#define CLS_NAMEDENTITY
#include <memory>
#include <string>
#include <unordered_set>
#include <algorithm>
#include "Globals.h"
#pragma once
class NamedEntity
{
private:
uint Id;
string Name;
mutable int Label;
public:
NamedEntity(uint id = 0, const string &name = "") : Id{ id }, Name{ name } { Label = 0; }
virtual uint getId() const { return Id; }
virtual string getName() const { return Name; }
virtual int getLabel() const { return Label; }
virtual void setLabel(int label = 0) const { Label = label; }
virtual void setAllLabels(int label = 0) const = 0;
virtual void incLabel() const { setLabel(Label +1); }
virtual void decLabel() const { setLabel(Label -1); }
};
using NamedEntitySharedPtr = std::shared_ptr<NamedEntity>;
struct NamedEntityHash {
size_t operator() (const NamedEntitySharedPtr &entity) const {
return std::hash<uint>()(entity->getId());
}
};
// Checks whether Set1 is a subset of Set2
template <typename T>
bool isSubset(const std::unordered_set<T, NamedEntityHash>& a, const std::unordered_set<T, NamedEntityHash>& b)
{
// return true if all members of a are also in b
auto const is_in_b = [&b](auto const& x) { return b.find(x) != b.end(); };
return a.size() <= b.size() && std::all_of(a.begin(), a.end(), is_in_b);
}
#endif