社交机器人的RDF语义网络

时间:2022-10-31 21:28:46

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:

我想将社交机器人的传入视觉数据以“主题,谓词,对象”的形式保存为RDF三元组的语义记忆。我不确定这种数据结构究竟应该用C ++编程。我的第一次尝试是这样的:

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?

一个示例条目是:“1 infront 3”简称为“subect#1空间关系是对象#3的前面”。我的问题是,时间框架中缺少一个字段。这个想法不仅存储空间关系,还存储时间信息。另一个问题是,对于第四个时间码字段,RDF数据库中的条目数将会爆炸。在正常游戏中,每秒生成30帧,因此在程序运行一分钟后,语义内存将会满。我如何解决这些问题,是否有任何论文在社交机器人的背景下提供RDF三重存储的示例?

1 个解决方案

#1


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.
  • 使用emplace_back而不是push_back。

  • Use the smallest data type for subject and object (here I've used unsigned int).
  • 使用主题和对象的最小数据类型(这里我使用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.
  • 如果谓词字段应该包含一些特定值,则可以用您自己的枚举替换该重量级std:string。

  • 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.
  • 您可能已经知道,std :: vector是一个连续内存数据结构,每次向/从中插入/删除值时,它都可能将整个数组复制到新的位置。所以建议使用链表。

  • 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.
  • 如果这些RDF条目太多,程序的内存可以存储,则应设置文件输出流并将其保存在磁盘上。

#1


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.
  • 使用emplace_back而不是push_back。

  • Use the smallest data type for subject and object (here I've used unsigned int).
  • 使用主题和对象的最小数据类型(这里我使用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.
  • 如果谓词字段应该包含一些特定值,则可以用您自己的枚举替换该重量级std:string。

  • 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.
  • 您可能已经知道,std :: vector是一个连续内存数据结构,每次向/从中插入/删除值时,它都可能将整个数组复制到新的位置。所以建议使用链表。

  • 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.
  • 如果这些RDF条目太多,程序的内存可以存储,则应设置文件输出流并将其保存在磁盘上。