Skip to content

Commit

Permalink
init atomese reduct
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidnekachew committed Jul 19, 2018
1 parent c038445 commit e3bedc9
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
2 changes: 2 additions & 0 deletions moses/atomese/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ADD_SUBDIRECTORY(representation)
ADD_SUBDIRECTORY(reduct)

ADD_LIBRARY(atomese SHARED
representation/load_table
reduct/reduct
)

TARGET_LINK_LIBRARIES (atomese
Expand Down
9 changes: 9 additions & 0 deletions moses/atomese/reduct/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#install header files
INSTALL(FILES

reduct.h

DESTINATION

"include/${PROJECT_NAME}/atomese/reduct"
)
38 changes: 38 additions & 0 deletions moses/atomese/reduct/reduct.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** reduct.cc ---
*
* Copyright (C) 2018 OpenCog Foundation
*
* Author: Yidnekachew Wondimu <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License v3 as
* published by the Free Software Foundation and including the exceptions
* at http://opencog.org/wiki/Licenses
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to:
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <moses/comboreduct/reduct/reduct.h>
#include <moses/comboreduct/converter/combo_atomese.h>
#include "reduct.h"

namespace opencog {
namespace atomese {

Handle full_reduce(combo::combo_tree& tr)
{
// combo::combo_tree& tr = combo::atomese_combo(to_reduce);
reduct::full_reduce(tr);
return combo::atomese_combo(tr);
}

}
}
41 changes: 41 additions & 0 deletions moses/atomese/reduct/reduct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** reduct.h ---
*
* Copyright (C) 2018 OpenCog Foundation
*
* Author: Yidnekachew Wondimu <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License v3 as
* published by the Free Software Foundation and including the exceptions
* at http://opencog.org/wiki/Licenses
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to:
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef _OPENCOG_ATOMESE_REDUCT_H
#define _OPENCOG_ATOMESE_REDUCT_H

namespace opencog {
namespace atomese {

/**
* Apply full_reduction on an atomese program.
*
* @param tr a combo_tree to be reduced.
* @todo it should accept a Handle as an argument after the combo->atomese converter is done.
* @return
*/
Handle full_reduce(combo::combo_tree& tr);

}
}

#endif //_OPENCOG_ATOMESE_REDUCT_H
1 change: 1 addition & 0 deletions tests/atomese/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ADD_SUBDIRECTORY (representation)
ADD_SUBDIRECTORY (reduct)
8 changes: 8 additions & 0 deletions tests/atomese/reduct/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
IF (HAVE_GUILE)
ADD_CXXTEST(reductUTest)
TARGET_LINK_LIBRARIES(reductUTest
atomese
${ATOMSPACE_LIBRARIES}
${GUILE_LIBRARIES}
)
ENDIF (HAVE_GUILE)
55 changes: 55 additions & 0 deletions tests/atomese/reduct/reductUTest.cxxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <opencog/util/Logger.h>
#include <moses/comboreduct/combo/combo.h>
#include <moses/comboreduct/converter/combo_atomese.h>
#include <opencog/atoms/base/Link.h>
#include <opencog/atoms/base/Node.h>
#include "moses/atomese/reduct/reduct.h"

using namespace opencog;
using namespace std;

#define cl createLink
#define cn createNode

class reductUTest : public CxxTest::TestSuite
{
public:
reductUTest();

~reductUTest();

void test_full_reduce();
};

reductUTest::reductUTest()
{
logger().set_level(Logger::DEBUG);
logger().set_print_to_stdout_flag(true);
}

reductUTest::~reductUTest()
{
// Erase the log file if no assertions failed.
if (!CxxTest::TestTracker::tracker().suiteFailed())
std::remove(logger().get_filename().c_str());
}

// test atomese full_reduction.
void reductUTest::test_full_reduce()
{
Handle X = cn(PREDICATE_NODE, "1"),
Y = cn(PREDICATE_NODE, "2");

// TODO: this should be passed to atomese::full_reduce instead of a combo_tree.
// Handle to_reduce = cl(OR_LINK,
// cl(AND_LINK, X, X),
// Y);

combo::combo_tree tr = combo::str2combo_tree("or(and($1 $1) $2)", {});

Handle result = atomese::full_reduce(tr);

Handle expected = cl(OR_LINK, X, Y);

TS_ASSERT(content_eq(expected, result));
}

2 comments on commit e3bedc9

@Yidnekachew
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per #21.

@Yidnekachew
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nil said:

I don't think you need to bother with that for now, simply convert the reduced combo program to atomese, using the code in https://github.com/opencog/as-moses/blob/master/moses/comboreduct/converter/combo_atomese.h

That is, as you implement the atomese_based_scorer convert the combo tree to atomese, that combo tree will likely already be reduced (depending on the parameters) and that's all your need. Reread carefully Section Replace Combo by Atomese Interpreter in Fitness Evaluation of issue #3 that should hopefully be clear (let me know otherwise).

Please sign in to comment.