PriorKnowledge.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::PriorKnowledge
17* @author Alexey Kozlov ( kozlov at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "PriorKnowledge.h"
24
25#include <IceUtil/UUID.h>
26
27#include <SimoxUtility/algorithm/string/string_tools.h>
28
29#include <ArmarXCore/interface/core/Log.h>
31
39
40
41#define PRIOR_SEGMENT_NAME_CLASSES "classes"
42#define PRIOR_SEGMENT_NAME_RELATIONS "relations"
43#define PRIOR_SEGMENT_NAME_GRAPH "graphs"
44
45namespace memoryx
46{
47 std::string
49 {
50 return "PriorKnowledge";
51 }
52
53 void
55 {
56 usingProxy("CommonStorage");
57
58 const std::string clsCollNamesStr = getProperty<std::string>("ClassCollections").getValue();
59 classCollNames = simox::alg::split(clsCollNamesStr, ",");
60
61 const std::string relCollNamesStr =
62 getProperty<std::string>("RelationCollections").getValue();
63 relationCollNames = simox::alg::split(relCollNamesStr, ",");
64
65 const std::string graphCollNamesStr =
66 getProperty<std::string>("GraphCollections").getValue();
67 graphCollNames = simox::alg::split(graphCollNamesStr, ",");
68 }
69
70 void
72 {
73 ARMARX_INFO << "Starting MemoryX::PriorKnowledge";
74
75 const Ice::CommunicatorPtr ic = getIceManager()->getCommunicator();
76
78
79 CollectionInterfacePrx writeClassColl = dataBasePrx->requestCollection(classCollNames[0]);
80 PersistentObjectClassSegmentPtr classesSegment =
81 new PersistentObjectClassSegment(writeClassColl, ic);
84
85 if (relationCollNames.size() > 0 && !relationCollNames[0].empty())
86 {
87 CollectionInterfacePrx writeRelationColl =
88 dataBasePrx->requestCollection(relationCollNames[0]);
89 PersistentRelationSegmentPtr relationsSegment =
90 new PersistentRelationSegment(writeRelationColl, ic);
93 }
94
95 if (graphCollNames.size() > 0 && !graphCollNames[0].empty())
96 {
97 ARMARX_INFO << "Adding segments: " << graphCollNames;
98 CollectionInterfacePrx graphClassColl =
99 dataBasePrx->requestCollection(graphCollNames[0]);
100 GraphMemorySegmentPtr graphSegment{new GraphMemorySegment{graphClassColl, ic}};
103 }
104 }
105
106 PersistentObjectClassSegmentBasePrx
107 PriorKnowledge::getObjectClassesSegment(const ::Ice::Current& c) const
108 {
109 return PersistentObjectClassSegmentBasePrx::uncheckedCast(
111 }
112
113 PersistentRelationSegmentBasePrx
114 PriorKnowledge::getRelationsSegment(const ::Ice::Current& c) const
115 {
116 return PersistentRelationSegmentBasePrx::uncheckedCast(
118 }
119
120 GraphMemorySegmentBasePrx
121 PriorKnowledge::getGraphSegment(const ::Ice::Current& c) const
122 {
123 return GraphMemorySegmentBasePrx::uncheckedCast(getSegment(PRIOR_SEGMENT_NAME_GRAPH, c));
124 }
125
126 bool
127 PriorKnowledge::hasGraphSegment(const Ice::Current& c) const
128 {
130 }
131
132 CommonStorageInterfacePrx
133 PriorKnowledge::getCommonStorage(const ::Ice::Current&) const
134 {
135 return dataBasePrx;
136 }
137
138 bool
139 PriorKnowledge::isPriorCollection(const ::std::string& collNS, const ::Ice::Current&)
140 {
141 const size_t found = collNS.find_first_of('.');
142 if (found == std::string::npos)
143 {
144 return false;
145 }
146 std::string postfix = collNS.substr(found + 1, std::string::npos);
147 return simox::alg::starts_with(postfix, PRIOR_COLLECTION_PREFIX);
148 }
149
150 void
151 PriorKnowledge::clear(const ::Ice::Current&)
152 {
153 throw armarx::NotImplementedYetException();
154 }
155
156 void
157 PriorKnowledge::setSegmentReadCollections(const PersistentEntitySegmentBasePtr& segmentPrx,
158 const NameList& collNameList)
159 {
160 ARMARX_INFO << "Setting read collections";
161 segmentPrx->clearReadCollections();
162
163 for (memoryx::NameList::const_iterator it = collNameList.begin(); it != collNameList.end();
164 ++it)
165 {
166 ARMARX_INFO << "Adding collection " << *it;
167 CollectionInterfacePrx readColl = dataBasePrx->requestCollection(*it);
168
169 if (!readColl)
170 {
171 ARMARX_ERROR << " Could not find collection with name " << *it << std::endl;
172 }
173 else
174 {
175 segmentPrx->addReadCollection(readColl);
176 }
177 }
178 }
179
180 std::string
181 PriorKnowledge::getMemoryName(const Ice::Current&) const
182 {
183 return getName();
184 }
185
186 AbstractMemorySegmentPrx
187 PriorKnowledge::addGenericSegment(const std::string& segmentName, const Ice::Current&)
188 {
190 dataBasePrx->requestCollection(segmentName), getIceManager()->getCommunicator());
191 return addSegment(segmentName, segment);
192 }
193} // namespace memoryx
194
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#define PRIOR_SEGMENT_NAME_RELATIONS
#define PRIOR_SEGMENT_NAME_GRAPH
#define PRIOR_SEGMENT_NAME_CLASSES
constexpr T c
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
std::string getName() const
Retrieve name of object.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Ice::CommunicatorPtr getCommunicator() const
The Graph Memory Segment contains directed graphs.
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
The persistent object class segment is a specialized segment of the SegmentedMemory.
The PriorKnowledge class provides a database with common sense and/or prior knowldge.
void onInitComponent() override
Pure virtual hook for the subclass.
CommonStorageInterfacePrx dataBasePrx
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
AbstractMemorySegmentPrx addGenericSegment(const std::string &segmentName, const Ice::Current &) override
PersistentRelationSegmentBasePrx getRelationsSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
GraphMemorySegmentBasePrx getGraphSegment(const ::Ice::Current &c=Ice::emptyCurrent) const override
CommonStorageInterfacePrx getCommonStorage(const ::Ice::Current &=Ice::emptyCurrent) const override
void setSegmentReadCollections(const PersistentEntitySegmentBasePtr &segmentPrx, const NameList &collNameList)
bool isPriorCollection(const ::std::string &collNS, const ::Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
Pure virtual hook for the subclass.
static std::string GetDefaultName()
std::string getMemoryName(const Ice::Current &) const override
bool hasGraphSegment(const Ice::Current &c=Ice::emptyCurrent) const override
PersistentObjectClassSegmentBasePrx getObjectClassesSegment(const ::Ice::Current &=Ice::emptyCurrent) const override
AbstractMemorySegmentPrx addSegment(const std::string &segmentName, const AbstractMemorySegmentPtr &segment, const ::Ice::Current &=Ice::emptyCurrent) override
AbstractMemorySegmentPrx getSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
bool hasSegment(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) const override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
VirtualRobot headers.
IceUtil::Handle< PersistentEntitySegment > PersistentEntitySegmentPtr
IceInternal::Handle< PersistentObjectClassSegment > PersistentObjectClassSegmentPtr
IceInternal::Handle< PersistentRelationSegment > PersistentRelationSegmentPtr
IceInternal::Handle< GraphMemorySegment > GraphMemorySegmentPtr