knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::transaction::Insert Class Reference

#include <Transaction.h>

Inheritance diagram for knowrob::transaction::Insert:
Collaboration diagram for knowrob::transaction::Insert:

Public Member Functions

 Insert (const std::shared_ptr< QueryableStorage > &queryable, const std::shared_ptr< Vocabulary > &vocabulary)
 
 Insert (const std::shared_ptr< QueryableStorage > &queryable, const std::shared_ptr< Vocabulary > &vocabulary)
 
- Public Member Functions inherited from knowrob::transaction::Transaction
 Transaction (const std::shared_ptr< QueryableStorage > &queryable, const std::shared_ptr< Vocabulary > &vocabulary, bool isRemoval)
 
virtual ~Transaction ()=default
 
void addBackend (const std::shared_ptr< NamedBackend > &backend)
 
bool commit (const Triple &triple)
 
bool commit (const Triple &triple, const IRIAtomPtr &reifiedName)
 
bool commit (const TripleContainerPtr &triples)
 
bool commit (const TripleContainerPtr &triples, const ReifiedNames &reifiedNames)
 
 Transaction (const std::shared_ptr< QueryableStorage > &queryable, const std::shared_ptr< Vocabulary > &vocabulary, bool isRemoval)
 
virtual ~Transaction ()=default
 
void addBackend (const std::shared_ptr< NamedBackend > &backend)
 
bool commit (const Triple &triple)
 
bool commit (const Triple &triple, const IRIAtomPtr &reifiedName)
 
bool commit (const TripleContainerPtr &triples)
 
bool commit (const TripleContainerPtr &triples, const ReifiedNames &reifiedNames)
 

Protected Member Functions

bool doCommit (const Triple &triple, const StoragePtr &backend) override
 
bool doCommit (const TripleContainerPtr &triples, const StoragePtr &backend) override
 
void updateVocabulary (const Triple &triple) override
 
bool doCommit (const Triple &triple, const StoragePtr &backend) override
 
bool doCommit (const TripleContainerPtr &triples, const StoragePtr &backend) override
 
void updateVocabulary (const Triple &triple) override
 
- Protected Member Functions inherited from knowrob::transaction::Transaction
bool commitProtected (const TripleContainerPtr &triple, const StoragePtr &backend)
 
IRIAtomPtr queryReifiedName (const Triple &triple)
 
bool commitProtected (const TripleContainerPtr &triple, const StoragePtr &backend)
 
IRIAtomPtr queryReifiedName (const Triple &triple)
 

Additional Inherited Members

- Static Protected Member Functions inherited from knowrob::transaction::Transaction
static std::shared_ptr< ThreadPool::RunnercreateTripleWorker (const TripleContainerPtr &triples, const std::function< void(const TriplePtr &)> &fn)
 
static std::shared_ptr< ThreadPool::RunnercreateTripleWorker (const TripleContainerPtr &triples, const std::function< void(const TriplePtr &)> &fn)
 
- Protected Attributes inherited from knowrob::transaction::Transaction
std::shared_ptr< Vocabularyvocabulary_
 
std::shared_ptr< QueryableStoragequeryable_
 
std::vector< std::shared_ptr< NamedBackend > > backends_
 
bool isRemoval_
 

Detailed Description

A data insertion transaction.

Definition at line 94 of file Transaction.h.

Constructor & Destructor Documentation

◆ Insert() [1/2]

knowrob::transaction::Insert::Insert ( const std::shared_ptr< QueryableStorage > &  queryable,
const std::shared_ptr< Vocabulary > &  vocabulary 
)
inline

Definition at line 96 of file Transaction.h.

97  : Transaction(queryable, vocabulary, false) {}
Transaction(const std::shared_ptr< QueryableStorage > &queryable, const std::shared_ptr< Vocabulary > &vocabulary, bool isRemoval)
Definition: Transaction.h:25

◆ Insert() [2/2]

knowrob::transaction::Insert::Insert ( const std::shared_ptr< QueryableStorage > &  queryable,
const std::shared_ptr< Vocabulary > &  vocabulary 
)
inline

Definition at line 96 of file Transaction.h.

97  : Transaction(queryable, vocabulary, false) {}

Member Function Documentation

◆ doCommit() [1/4]

bool Insert::doCommit ( const Triple triple,
const StoragePtr backend 
)
overrideprotectedvirtual

Implements knowrob::transaction::Transaction.

Definition at line 185 of file Transaction.cpp.

185  {
186  return backend->insertOne(triple);
187 }

◆ doCommit() [2/4]

bool knowrob::transaction::Insert::doCommit ( const Triple triple,
const StoragePtr backend 
)
overrideprotectedvirtual

◆ doCommit() [3/4]

bool Insert::doCommit ( const TripleContainerPtr triples,
const StoragePtr backend 
)
overrideprotectedvirtual

Implements knowrob::transaction::Transaction.

Definition at line 193 of file Transaction.cpp.

193  {
194  return backend->insertAll(triples);
195 }

◆ doCommit() [4/4]

bool knowrob::transaction::Insert::doCommit ( const TripleContainerPtr triples,
const StoragePtr backend 
)
overrideprotectedvirtual

◆ updateVocabulary() [1/2]

void Insert::updateVocabulary ( const Triple triple)
overrideprotectedvirtual

Implements knowrob::transaction::Transaction.

Definition at line 201 of file Transaction.cpp.

201  {
202  // keep track of imports, subclasses, and subproperties
203  if (isSubClassOfIRI(triple.predicate())) {
204  auto sub = vocabulary_->defineClass(triple.subject());
205  auto sup = vocabulary_->defineClass(triple.valueAsString());
206  sub->addDirectParent(sup, triple.graph());
207  vocabulary_->increaseFrequency(rdfs::subClassOf->stringForm());
208  } else if (isSubPropertyOfIRI(triple.predicate())) {
209  auto sub = vocabulary_->defineProperty(triple.subject());
210  auto sup = vocabulary_->defineProperty(triple.valueAsString());
211  sub->addDirectParent(sup, triple.graph());
212  vocabulary_->increaseFrequency(rdfs::subPropertyOf->stringForm());
213  } else if (isTypeIRI(triple.predicate())) {
214  vocabulary_->addResourceType(triple.subject(), triple.valueAsString());
215  // increase frequency in vocabulary
216  static std::set<std::string_view> skippedTypes = {
217  owl::Class->stringForm(),
218  owl::Restriction->stringForm(),
219  owl::NamedIndividual->stringForm(),
220  owl::AnnotationProperty->stringForm(),
221  owl::ObjectProperty->stringForm(),
222  owl::DatatypeProperty->stringForm(),
223  rdfs::Class->stringForm(),
224  rdf::Property->stringForm()
225  };
226  if (vocabulary_->isDefinedClass(triple.valueAsString()) &&
227  !skippedTypes.count(triple.valueAsString())) {
228  vocabulary_->increaseFrequency(triple.valueAsString());
229  }
230  vocabulary_->increaseFrequency(rdf::type->stringForm());
231  } else if (isInverseOfIRI(triple.predicate())) {
232  auto p = vocabulary_->defineProperty(triple.subject());
233  auto q = vocabulary_->defineProperty(triple.valueAsString());
234  p->setInverse(q);
235  q->setInverse(p);
236  vocabulary_->increaseFrequency(owl::inverseOf->stringForm());
237  } else if (owl::imports->stringForm() == triple.predicate()) {
238  auto resolvedImport = URI::resolve(triple.valueAsString());
239  auto importedGraph = DataSource::getNameFromURI(resolvedImport);
240  if (triple.graph()) {
241  vocabulary_->importHierarchy()->addDirectImport(triple.graph().value(), importedGraph);
242  } else {
243  KB_WARN("import statement without graph");
244  }
245  } else if (vocabulary_->isObjectProperty(triple.predicate()) ||
246  vocabulary_->isDatatypeProperty(triple.predicate())) {
247  // increase frequency of property in vocabulary
248  vocabulary_->increaseFrequency(triple.predicate());
249  }
250 }
#define KB_WARN
Definition: Logger.h:27
static std::string getNameFromURI(const std::string &uriString)
Definition: DataSource.cpp:36
virtual std::string_view valueAsString() const =0
virtual std::optional< std::string_view > graph() const =0
virtual std::string_view subject() const =0
virtual std::string_view predicate() const =0
static std::string resolve(const std::string_view &uriString)
Definition: URI.cpp:79
std::shared_ptr< Vocabulary > vocabulary_
Definition: Transaction.h:71
const IRIAtomPtr inverseOf
Definition: owl.h:17
const IRIAtomPtr ObjectProperty
Definition: owl.h:21
const IRIAtomPtr NamedIndividual
Definition: owl.h:27
const IRIAtomPtr Restriction
Definition: owl.h:20
const IRIAtomPtr imports
Definition: owl.h:15
const IRIAtomPtr AnnotationProperty
Definition: owl.h:23
const IRIAtomPtr Class
Definition: owl.h:18
const IRIAtomPtr DatatypeProperty
Definition: owl.h:22
const IRIAtomPtr Property
Definition: rdf.h:16
const IRIAtomPtr type
Definition: rdf.h:15
const IRIAtomPtr Class
Definition: rdfs.h:22
const IRIAtomPtr subPropertyOf
Definition: rdfs.h:16
const IRIAtomPtr subClassOf
Definition: rdfs.h:15
bool isSubClassOfIRI(std::string_view iri)
Definition: rdfs.cpp:9
bool isTypeIRI(std::string_view iri)
Definition: rdf.cpp:9
bool isSubPropertyOfIRI(std::string_view iri)
Definition: rdfs.cpp:12
bool isInverseOfIRI(std::string_view iri)
Definition: owl.cpp:12

◆ updateVocabulary() [2/2]

void knowrob::transaction::Insert::updateVocabulary ( const Triple triple)
overrideprotectedvirtual

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