JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
AttributeJaccard.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 16/05/2019.
3 //
4 
5 #ifndef JODA_ATTRIBUTEJACCARD_H
6 #define JODA_ATTRIBUTEJACCARD_H
7 
8 #include <joda/misc/RJFwd.h>
9 #include <rapidjson/istreamwrapper.h>
10 #include "../../../../src/RJAttributeReader.h"
11 #include "IJSONSimilarityMeasure.h"
12 
13 class AttributeJaccard;
14 
15 template <>
17  bool is_implemented = true;
19  typedef std::set<std::string> Representation;
20 
21  inline const Representation getRepresentation(const RJDocument &lhs) const {
22  Representation paths;
23  std::string prefix;
24  getAttributes(lhs, prefix, paths);
25  return paths;
26  }
27 
28  inline const Representation getRepresentation(const std::string &lhs) {
29  handler.clear();
30  rapidjson::Reader reader;
31  rapidjson::StringStream stream(lhs.c_str());
32  reader.Parse(stream, handler);
33  auto paths = handler.getAttributes();
34  return paths;
35  }
36 
38  rapidjson::IStreamWrapper &lhs) {
39  handler.clear();
40  rapidjson::Reader reader;
41  reader.Parse(lhs, handler);
42  auto paths = handler.getAttributes();
43  return paths;
44  }
45 
46  inline static void getAttributes(const RJValue &doc, std::string &prefix,
47  Representation &set) {
48  if (doc.IsObject()) {
49  for (const auto &m : doc.GetObject()) {
50  set.insert(m.name.GetString());
51  if (m.value.IsObject() || m.value.IsArray()) {
52  getAttributes(m.value, prefix, set);
53  }
54  }
55  } else if (doc.IsArray()) {
56  for (const auto &item : doc.GetArray()) {
57  if (item.IsObject() || item.IsArray()) {
58  getAttributes(item, prefix, set);
59  }
60  }
61  }
62  }
63 };
64 
70  public:
71  double measure(const RJDocument &lhs, const RJDocument &rhs) override;
72  static double measure(
75 };
76 
77 #endif // JODA_ATTRIBUTEJACCARD_H
rapidjson::GenericDocument< RJChar, RJMemoryPoolAlloc, RJBaseAlloc > RJDocument
Definition: RJFwd.h:28
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: AttributeJaccard.h:69
double measure(const RJDocument &lhs, const RJDocument &rhs) override
Definition: AttributeJaccard.cpp:9
Definition: IJSONSimilarityMeasure.h:24
Definition: RJAttributeReader.h:15
const std::set< std::string > & getAttributes() const
Definition: RJAttributeReader.cpp:50
void clear()
Definition: RJAttributeReader.cpp:54
RJAttributeReader handler
Definition: AttributeJaccard.h:18
static void getAttributes(const RJValue &doc, std::string &prefix, Representation &set)
Definition: AttributeJaccard.h:46
const Representation getRepresentation(const RJDocument &lhs) const
Definition: AttributeJaccard.h:21
std::set< std::string > Representation
Definition: AttributeJaccard.h:19
const Representation getRepresentation(rapidjson::IStreamWrapper &lhs)
Definition: AttributeJaccard.h:37
const Representation getRepresentation(const std::string &lhs)
Definition: AttributeJaccard.h:28
Definition: IJSONSimilarityMeasure.h:36
bool is_implemented
Definition: IJSONSimilarityMeasure.h:56