knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
TripleFormat.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #include <unordered_map>
7 #include "knowrob/semweb/TripleFormat.h"
8 
9 static const std::unordered_map<std::string_view, knowrob::semweb::TripleFormat> stringToMap = {
28 };
29 static const std::unordered_map<std::string_view, knowrob::semweb::TripleFormat> stringToMap2 = {
32 };
33 
34 namespace knowrob::semweb {
35  bool isTripleFormatString(std::string_view format) {
36  auto it = stringToMap.find(format);
37  return (it != stringToMap.end());
38  }
39 
40  TripleFormat tripleFormatFromString(std::string_view format) {
41  auto it = stringToMap.find(format);
42  if (it != stringToMap.end()) {
43  return it->second;
44  }
45  it = stringToMap2.find(format);
46  if (it != stringToMap2.end()) {
47  return it->second;
48  }
49  return TripleFormat::RDF_XML;
50  }
51 
52  std::string_view tripleFormatToString(TripleFormat format) {
53  switch (format) {
55  return "RDF/XML";
56  case TripleFormat::RDFA:
57  return "RDFA";
58  case TripleFormat::TRIG:
59  return "TRIG";
61  return "GRDDL";
63  return "TURTLE";
65  return "N-TRIPLES";
66  }
67  return "RDF/XML";
68  }
69 
71  switch (format) {
72  case semweb::RDF_XML:
73  return "rdfxml";
74  case semweb::TURTLE:
75  return "turtle";
76  case semweb::N_TRIPLES:
77  return "ntriples";
78  case semweb::RDFA:
79  return "rdfa";
80  case semweb::TRIG:
81  return "trig";
82  case semweb::GRDDL:
83  return "grddl";
84  }
85  return "rdfxml";
86  }
87 }
bool isTripleFormatString(std::string_view format)
std::string_view tripleFormatToString(TripleFormat format)
TripleFormat tripleFormatFromString(std::string_view format)
std::string_view tripleFormatMimeType(TripleFormat format)