0

I want to save the incoming visual data of a social robot into a semantic memory as RDF triple in the form "Subject, predicate, object". Im unsure how exactly this kind of datastructure should be programmed in C++. My first attempt was something like this:

class RDFentry {
public:
  int subject;
  std::string predicate;
  int object;
};

std::vector<RDFentry> myrdf = {};
myrdf.push_back({i,"infront",3});

An example entry would be: "1 infront 3" in short for "subect #1 spatial relation is infront of object #3". My problem is, that there is a missing field for the timeframe. The idea is not only store the spatialrelations but also temporal information. Another problem is, that with a fourth timecode field, the number of entries in in the RDF database would explode. In a normal game, 30 frames per second are generated, so after a minute of program running, the semantic memory would be full. How do i solve these problemes, are there any papers which give examples for RDF triple storage in context of social robotics?

Manuel Rodriguez
  • 734
  • 4
  • 18

1 Answers1

0

After adding time field, we've got something like this:

struct RDFentry {
    unsinged int subject;
    std::string predicate;
    unsinged int object;
    unsinged long time;
};

std::vector<RDFentry> myrdf;
myrdf.emplace_back(i, "infront", 3, /*time*/);

To improve memory usage and performance, note that:

  • Use emplace_back instead of push_back.
  • Use the smallest data type for subject and object (here I've used unsigned int).
  • If the predicate field is supposed to hold a few specific values, you can replace that heavy-weight std:string with your own enum.
  • As you may already know, std::vector is a contiguous-memory data structure, every time you insert/remove an value to/from it, it may copy the entire array to somewhere new. So it's recommended to use a linked list.
  • If those RDF entries are too much that your program's memory could store, you should set up a file output stream and save them on the disk.
frogatto
  • 28,539
  • 11
  • 83
  • 129