dlvhex
2.5.0
|
00001 /* dlvhex -- Answer-Set Programming with external interfaces. 00002 * Copyright (C) 2005-2007 Roman Schindlauer 00003 * Copyright (C) 2006-2015 Thomas Krennwallner 00004 * Copyright (C) 2009-2016 Peter Schüller 00005 * Copyright (C) 2011-2016 Christoph Redl 00006 * Copyright (C) 2015-2016 Tobias Kaminski 00007 * Copyright (C) 2015-2016 Antonius Weinzierl 00008 * 00009 * This file is part of dlvhex. 00010 * 00011 * dlvhex is free software; you can redistribute it and/or modify it 00012 * under the terms of the GNU Lesser General Public License as 00013 * published by the Free Software Foundation; either version 2.1 of 00014 * the License, or (at your option) any later version. 00015 * 00016 * dlvhex is distributed in the hope that it will be useful, but 00017 * WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with dlvhex; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00024 * 02110-1301 USA. 00025 */ 00026 00037 #ifdef HAVE_CONFIG_H 00038 #include "config.h" 00039 #endif // HAVE_CONFIG_H 00040 00041 #ifdef HAVE_MLP 00042 00043 #include "dlvhex2/RuleMLOutputBuilder.h" 00044 #include "dlvhex2/ResultContainer.h" 00045 00046 #include <iostream> 00047 00048 DLVHEX_NAMESPACE_BEGIN 00049 00050 RuleMLOutputBuilder::RuleMLOutputBuilder() 00051 { } 00052 00053 RuleMLOutputBuilder::~RuleMLOutputBuilder() 00054 { } 00055 00056 void 00057 RuleMLOutputBuilder::buildPre(std::ostream& stream) 00058 { 00060 stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 00061 00062 stream << "<RuleML xmlns=\"http://www.ruleml.org/0.91/xsd\"" << std::endl 00063 << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl 00064 << " xsi:schemaLocation=\"http://www.ruleml.org/0.91/xsd http://www.ruleml.org/0.91/xsd/datalog.xsd\">" << std::endl; 00065 00066 stream << "<Assert mapClosure=\"universal\">" << std::endl; 00067 00068 stream << "<Or>" << std::endl; 00069 } 00070 00071 00072 void 00073 RuleMLOutputBuilder::buildPost(std::ostream& stream) 00074 { 00075 stream << "</Or>" << std::endl; 00076 stream << "</Assert>" << std::endl; 00077 stream << "</RuleML>" << std::endl; 00078 } 00079 00080 00081 void 00082 RuleMLOutputBuilder::buildResult(std::ostream& stream, const ResultContainer& facts) 00083 { 00084 buildPre(stream); 00085 00086 for (ResultContainer::result_t::const_iterator as = facts.getAnswerSets().begin(); 00087 as != facts.getAnswerSets().end(); 00088 ++as) { 00089 stream << "<And>" << std::endl; 00090 00091 for (AnswerSet::const_iterator f = (*as)->begin(); 00092 f != (*as)->end(); 00093 ++f) { 00094 if (f->isStronglyNegated()) { 00095 stream << "<Neg>"; 00096 } 00097 00098 stream << "<Atom>"; 00099 00100 stream << "<Rel>"; 00101 stream << "<![CDATA[" << f->getArgument(0) << "]]>"; 00102 stream << "</Rel>"; 00103 00104 for (unsigned i = 1; i <= f->getArity(); i++) { 00105 stream << "<Ind>"; 00106 stream << "<![CDATA[" << f->getArgument(i) << "]]>"; 00107 stream << "</Ind>"; 00108 } 00109 00110 stream << "</Atom>"; 00111 00112 if (f->isStronglyNegated()) { 00113 stream << "</Neg>"; 00114 } 00115 00116 stream << std::endl; 00117 } 00118 00119 stream << "</And>" << std::endl; 00120 } 00121 00122 buildPost(stream); 00123 } 00124 00125 00126 DLVHEX_NAMESPACE_END 00127 #endif 00128 00129 00130 00131 // vim:expandtab:ts=4:sw=4: 00132 // mode: C++ 00133 // End: