Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 #include <plugins/owlexporter/PluginOWLExporter.h>
00041
00042
00043 namespace beliefstate {
00044 namespace plugins {
00045 PLUGIN_CLASS::PLUGIN_CLASS() {
00046 this->setPluginVersion("0.93");
00047 }
00048
00049 PLUGIN_CLASS::~PLUGIN_CLASS() {
00050 }
00051
00052 Result PLUGIN_CLASS::init(int argc, char** argv) {
00053 Result resInit = defaultResult();
00054
00055 this->setSubscribedToEvent("set-experiment-meta-data", true);
00056 this->setSubscribedToEvent("export-planlog", true);
00057 this->setSubscribedToEvent("experiment-start", true);
00058 this->setSubscribedToEvent("experiment-shutdown", true);
00059 this->setSubscribedToEvent("register-owl-namespace", true);
00060
00061 return resInit;
00062 }
00063
00064 Result PLUGIN_CLASS::deinit() {
00065 return defaultResult();
00066 }
00067
00068 Result PLUGIN_CLASS::cycle() {
00069 Result resCycle = defaultResult();
00070 this->deployCycleData(resCycle);
00071
00072 return resCycle;
00073 }
00074
00075 void PLUGIN_CLASS::consumeEvent(Event evEvent) {
00076 if(evEvent.strEventName == "export-planlog") {
00077 if(evEvent.cdDesignator) {
00078 std::string strFormat = evEvent.cdDesignator->stringValue("format");
00079 transform(strFormat.begin(), strFormat.end(), strFormat.begin(), ::tolower);
00080
00081 if(strFormat == "owl") {
00082 if(m_mapMetaData.find("time-end") == m_mapMetaData.end()) {
00083 m_mapMetaData["time-end"] = this->getTimeStampStr();
00084 }
00085
00086 ServiceEvent seGetPlanTree = defaultServiceEvent("symbolic-plan-tree");
00087 seGetPlanTree.cdDesignator = new CDesignator(evEvent.cdDesignator);
00088 this->deployServiceEvent(seGetPlanTree);
00089 }
00090 }
00091 } else if(evEvent.strEventName == "experiment-start") {
00092 Event evSendOwlExporterVersion = defaultEvent("set-experiment-meta-data");
00093 evSendOwlExporterVersion.cdDesignator = new CDesignator();
00094 evSendOwlExporterVersion.cdDesignator->setType(ACTION);
00095
00096 evSendOwlExporterVersion.cdDesignator->setValue("field", "owl-exporter-version");
00097 evSendOwlExporterVersion.cdDesignator->setValue("value", this->pluginVersion());
00098
00099 m_mapRegisteredOWLNamespaces.clear();
00100
00101 this->deployEvent(evSendOwlExporterVersion);
00102
00103 m_mapMetaData["time-start"] = this->getTimeStampStr();
00104 } else if(evEvent.strEventName == "experiment-shutdown") {
00105 m_mapMetaData["time-end"] = this->getTimeStampStr();
00106 } else if(evEvent.strEventName == "set-experiment-meta-data") {
00107 if(evEvent.cdDesignator) {
00108 std::string strField = evEvent.cdDesignator->stringValue("field");
00109 std::string strValue = evEvent.cdDesignator->stringValue("value");
00110
00111 if(strField != "") {
00112 this->info("Set meta data field '" + strField + "' to '" + strValue + "'");
00113 m_mapMetaData[strField] = strValue;
00114 }
00115 }
00116 } else if(evEvent.strEventName == "register-owl-namespace") {
00117 if(evEvent.cdDesignator) {
00118 std::string strShortcut = evEvent.cdDesignator->stringValue("shortcut");
00119 std::string strIRI = evEvent.cdDesignator->stringValue("iri");
00120
00121 if(strIRI != "" && strShortcut != "") {
00122 m_mapRegisteredOWLNamespaces[strShortcut] = strIRI;
00123 this->info("Registered OWL namespace: '" + strShortcut + "' = '" + strIRI + "'");
00124 } else {
00125 this->warn("Did not register OWL namespace. Insufficient information: '" + strShortcut + "' = '" + strIRI + "'");
00126 }
00127 }
00128 }
00129 }
00130
00131 Event PLUGIN_CLASS::consumeServiceEvent(ServiceEvent seServiceEvent) {
00132 Event evResult = defaultEvent();
00133
00134 if(seServiceEvent.siServiceIdentifier == SI_RESPONSE) {
00135 if(seServiceEvent.strServiceName == "symbolic-plan-tree") {
00136 if(seServiceEvent.cdDesignator) {
00137 if(seServiceEvent.lstResultEvents.size() > 0) {
00138 Event evCar = seServiceEvent.lstResultEvents.front();
00139
00140 std::string strFormat = seServiceEvent.cdDesignator->stringValue("format");
00141 transform(strFormat.begin(), strFormat.end(), strFormat.begin(), ::tolower);
00142
00143 if(strFormat == "owl") {
00144 this->info("OWLExporter Plugin received plan log data. Exporting symbolic log.");
00145
00146 CExporterOwl* expOwl = new CExporterOwl();
00147 expOwl->setMetaData(m_mapMetaData);
00148
00149 CDesignator* cdConfig = this->getIndividualConfig();
00150 std::string strSemanticsDescriptorFile = cdConfig->stringValue("semantics-descriptor-file");
00151
00152 if(strSemanticsDescriptorFile != "") {
00153 this->info("Loading semantics descriptor file '" + strSemanticsDescriptorFile + "'");
00154
00155 if(expOwl->loadSemanticsDescriptorFile(strSemanticsDescriptorFile) == false) {
00156 this->warn("Failed to load semantics descriptor file '" + strSemanticsDescriptorFile + "'.");
00157 }
00158 } else {
00159 this->warn("No semantics descriptor file was specified.");
00160 }
00161
00162 expOwl->configuration()->setValue(string("display-successes"), (int)seServiceEvent.cdDesignator->floatValue("show-successes"));
00163 expOwl->configuration()->setValue(string("display-failures"), (int)seServiceEvent.cdDesignator->floatValue("show-fails"));
00164 expOwl->configuration()->setValue(string("max-detail-level"), (int)seServiceEvent.cdDesignator->floatValue("max-detail-level"));
00165
00166 expOwl->setRootNodes(evCar.lstRootNodes);
00167
00168 bool bFailed = false;
00169 for(Node* ndNode : evCar.lstNodes) {
00170 if(ndNode) {
00171 expOwl->addNode(ndNode);
00172 } else {
00173 this->fail("One of the nodes received in the plan log data contains invalid data. Cancelling export. Try again at will.");
00174 bFailed = true;
00175 break;
00176 }
00177 }
00178
00179 if(!bFailed) {
00180 this->info("Parameterizing exporter");
00181
00182 expOwl->setDesignatorIDs(evCar.lstDesignatorIDs);
00183 expOwl->setDesignatorEquations(evCar.lstEquations);
00184 expOwl->setDesignatorEquationTimes(evCar.lstEquationTimes);
00185
00186 ConfigSettings cfgsetCurrent = configSettings();
00187 expOwl->setOutputFilename(cfgsetCurrent.strExperimentDirectory + seServiceEvent.cdDesignator->stringValue("filename"));
00188 expOwl->setRegisteredOWLNamespaces(m_mapRegisteredOWLNamespaces);
00189
00190 this->info("Exporting OWL file to '" + expOwl->outputFilename() + "'", true);
00191
00192 if(expOwl->runExporter(NULL)) {
00193 this->info("Successfully exported OWL file '" + expOwl->outputFilename() + "'", true);
00194 } else {
00195 this->warn("Failed to export to OWL file '" + expOwl->outputFilename() + "'", true);
00196 }
00197 } else {
00198 this->warn("Failed to export to OWL file '" + expOwl->outputFilename() + "'", true);
00199 }
00200
00201 delete expOwl;
00202 }
00203 }
00204 }
00205 }
00206 }
00207
00208 return evResult;
00209 }
00210 }
00211
00212 extern "C" plugins::PLUGIN_CLASS* createInstance() {
00213 return new plugins::PLUGIN_CLASS();
00214 }
00215
00216 extern "C" void destroyInstance(plugins::PLUGIN_CLASS* icDestroy) {
00217 delete icDestroy;
00218 }
00219 }