knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::mongo::MongoTaxonomy Class Reference

#include <MongoTaxonomy.h>

Public Types

using StringPair = std::pair< std::string_view, std::string_view >
 
using StringPair = std::pair< std::string_view, std::string_view >
 

Public Member Functions

 MongoTaxonomy (const std::shared_ptr< mongo::Collection > &tripleCollection, const std::shared_ptr< mongo::Collection > &oneCollection, const VocabularyPtr &vocabulary)
 
void updateInsert (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions)
 
void updateRemove (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions)
 
 MongoTaxonomy (const std::shared_ptr< mongo::Collection > &tripleCollection, const std::shared_ptr< mongo::Collection > &oneCollection, const VocabularyPtr &vocabulary)
 
void updateInsert (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions)
 
void updateRemove (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions)
 

Protected Member Functions

void update (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions, bool isInsert)
 
void update (const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions, bool isInsert)
 

Protected Attributes

std::shared_ptr< mongo::CollectiontripleCollection_
 
std::shared_ptr< mongo::CollectiononeCollection_
 
VocabularyPtr vocabulary_
 

Detailed Description

A class to update the taxonomy in a MongoDB.

Definition at line 19 of file MongoTaxonomy.h.

Member Typedef Documentation

◆ StringPair [1/2]

using knowrob::mongo::MongoTaxonomy::StringPair = std::pair<std::string_view, std::string_view>

Definition at line 21 of file MongoTaxonomy.h.

◆ StringPair [2/2]

using knowrob::mongo::MongoTaxonomy::StringPair = std::pair<std::string_view, std::string_view>

Definition at line 21 of file MongoTaxonomy.h.

Constructor & Destructor Documentation

◆ MongoTaxonomy() [1/2]

MongoTaxonomy::MongoTaxonomy ( const std::shared_ptr< mongo::Collection > &  tripleCollection,
const std::shared_ptr< mongo::Collection > &  oneCollection,
const VocabularyPtr vocabulary 
)

Definition at line 16 of file MongoTaxonomy.cpp.

20  : tripleCollection_(tripleCollection), oneCollection_(oneCollection), vocabulary_(vocabulary) {
21 }
std::shared_ptr< mongo::Collection > oneCollection_
Definition: MongoTaxonomy.h:37
std::shared_ptr< mongo::Collection > tripleCollection_
Definition: MongoTaxonomy.h:36

◆ MongoTaxonomy() [2/2]

knowrob::mongo::MongoTaxonomy::MongoTaxonomy ( const std::shared_ptr< mongo::Collection > &  tripleCollection,
const std::shared_ptr< mongo::Collection > &  oneCollection,
const VocabularyPtr vocabulary 
)

Member Function Documentation

◆ update() [1/2]

void MongoTaxonomy::update ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions,
bool  isInsert 
)
protected

Definition at line 193 of file MongoTaxonomy.cpp.

196  {
197  // below performs the server-side data transformation for updating hierarchy relations
198  // such as rdf::type.
199 
200  if (subClassAssertions.empty() && subPropertyAssertions.empty()) return;
201 
202  // create a bulk operation for updating subClassOf and subPropertyOf relations
203  // using the taxonomic assertions in the Vocabulary class
204  auto bulk = tripleCollection_->createBulkOperation();
205 
206  // add bulk operations to update subClassOf and subPropertyOf relations
207  if (!subClassAssertions.empty()) {
208  bulkUpdateTaxonomy<Class>(bulk, vocabulary_, rdfs::subClassOf->stringForm(), subClassAssertions);
209  }
210  if (!subPropertyAssertions.empty()) {
211  bulkUpdateTaxonomy<Property>(bulk, vocabulary_, rdfs::subPropertyOf->stringForm(), subPropertyAssertions);
212  }
213 
214  // also update the p* field of all documents that contain an invalidated property in this field
215  if (!subPropertyAssertions.empty()) {
216  std::set<std::string_view> invalidPropertyAssertions;
217  for (auto &assertion: subPropertyAssertions) {
218  invalidPropertyAssertions.insert(assertion.first);
219  }
220  if (isInsert) {
221  bulkUpdateTriples_insert(bulk, vocabulary_, invalidPropertyAssertions);
222  } else {
223  bulkUpdateTriples_remove(bulk, vocabulary_, tripleCollection_->name(), invalidPropertyAssertions);
224  }
225  }
226 
227  if (!bulk->empty()) {
228  bulk->execute();
229  }
230 }
const IRIAtomPtr subPropertyOf
Definition: rdfs.h:16
const IRIAtomPtr subClassOf
Definition: rdfs.h:15

◆ update() [2/2]

void knowrob::mongo::MongoTaxonomy::update ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions,
bool  isInsert 
)
protected

◆ updateInsert() [1/2]

void MongoTaxonomy::updateInsert ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions 
)

Definition at line 181 of file MongoTaxonomy.cpp.

183  {
184  update(subClassAssertions, subPropertyAssertions, true);
185 }
void update(const std::vector< StringPair > &subClassAssertions, const std::vector< StringPair > &subPropertyAssertions, bool isInsert)

◆ updateInsert() [2/2]

void knowrob::mongo::MongoTaxonomy::updateInsert ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions 
)

◆ updateRemove() [1/2]

void MongoTaxonomy::updateRemove ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions 
)

Definition at line 187 of file MongoTaxonomy.cpp.

189  {
190  update(subClassAssertions, subPropertyAssertions, false);
191 }

◆ updateRemove() [2/2]

void knowrob::mongo::MongoTaxonomy::updateRemove ( const std::vector< StringPair > &  subClassAssertions,
const std::vector< StringPair > &  subPropertyAssertions 
)

Member Data Documentation

◆ oneCollection_

std::shared_ptr< mongo::Collection > knowrob::mongo::MongoTaxonomy::oneCollection_
protected

Definition at line 37 of file MongoTaxonomy.h.

◆ tripleCollection_

std::shared_ptr< mongo::Collection > knowrob::mongo::MongoTaxonomy::tripleCollection_
protected

Definition at line 36 of file MongoTaxonomy.h.

◆ vocabulary_

VocabularyPtr knowrob::mongo::MongoTaxonomy::vocabulary_
protected

Definition at line 38 of file MongoTaxonomy.h.


The documentation for this class was generated from the following files: