<commit_before>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 <NAME>
 * Copyright (C) 2006, 2007, 2008, 2009, 2010 <NAME>
 * Copyright (C) 2009, 2010 <NAME>
 * 
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file   TestEvalEndToEnd.cpp
 * @author <NAME> <<EMAIL>>
 * 
 * @brief  Test evaluation starting from HEX program to final models.
 *
 * Functional external atoms are provided in fixture.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

#include "dlvhex2/EvalGraphBuilder.h"
#include "dlvhex2/EvalHeuristicOldDlvhex.h"
#include "dlvhex2/ProgramCtx.h"
#include "dlvhex2/Printer.h"
#include "dlvhex2/Registry.h"
#include "dlvhex2/PluginInterface.h"
#include "dlvhex2/DependencyGraph.h"
#include "dlvhex2/ComponentGraph.h"
#include "dlvhex2/ModelGenerator.h"
#include "dlvhex2/OnlineModelBuilder.h"
#include "dlvhex2/ASPSolver.h"
#include "dlvhex2/ASPSolverManager.h"

// this must be included before dummytypes!
#define BOOST_TEST_MODULE __FILE__
#include <boost/test/unit_test.hpp>

#include "fixturesExt1.h"
#include "graphviz.h"

#include <iostream>
#include <fstream>
#include <cstdlib>

#define LOG_REGISTRY_PROGRAM(ctx) \
  LOG(INFO,*ctx.registry()); \
	RawPrinter printer(std::cerr, ctx.registry()); \
	std::cerr << "edb = " << *ctx.edb << std::endl; \
	LOG(INFO,"idb"); \
	printer.printmany(ctx.idb,"\n"); \
	std::cerr << std::endl; \
	LOG(INFO,"idb end");

LOG_INIT(Logger::ERROR | Logger::WARNING)

DLVHEX_NAMESPACE_USE

typedef FinalEvalGraph::EvalUnit EvalUnit;
typedef OnlineModelBuilder<FinalEvalGraph> FinalOnlineModelBuilder;
typedef FinalOnlineModelBuilder::Model Model;
typedef FinalOnlineModelBuilder::OptionalModel OptionalModel;

BOOST_FIXTURE_TEST_CASE(testEvalHeuristicExt1,ProgramExt1ProgramCtxDependencyGraphComponentGraphFixture) 
{
  LOG_REGISTRY_PROGRAM(ctx);

  // eval graph
  FinalEvalGraph eg;

  {
    // create builder that supervises the construction of eg
    ASPSolverManager::SoftwareConfigurationPtr extEvalConfig(
        new ASPSolver::DLVSoftware::Configuration);
    EvalGraphBuilder egbuilder(ctx, compgraph, eg, extEvalConfig);

    {
      // create heuristic, which sends commands to egbuilder
      EvalHeuristicOldDlvhex heuristicOldDlvhex;
      heuristicOldDlvhex.build(egbuilder);
      LOG(INFO,"building eval graph finished");

      // log the (changed) component graph
      {
        const char* fnamev = "testEvalEndToEndExt1Verbose.dot";
        LOG(INFO,"dumping verbose graph to " << fnamev);
        std::ofstream filev(fnamev);
        compgraph.writeGraphViz(filev, true);
        makeGraphVizPdf(fnamev);

        const char* fnamet = "testEvalEndToEndExt1Terse.dot";
        LOG(INFO,"dumping terse graph to " << fnamet);
        std::ofstream filet(fnamet);
        compgraph.writeGraphViz(filet, false);
        makeGraphVizPdf(fnamet);
      }
    }
  }

  //
  // evaluate
  //
  FinalOnlineModelBuilder omb(eg);

  EvalUnit ufinal;

  // setup final unit
  {
    BOOST_TEST_MESSAGE("adding ufinal");
    LOG(INFO,"ufinal = " << ufinal);
    ufinal = eg.addUnit(FinalEvalGraph::EvalUnitPropertyBundle());

    FinalEvalGraph::EvalUnitIterator it, itend;
    boost::tie(it, itend) = eg.getEvalUnits();
    for(; it != itend && *it != ufinal; ++it)
    {<commit_msg>fixing testcase that is only activated with DLV<commit_after>/* dlvhex -- Answer-Set Programming with external interfaces.
 * Copyright (C) 2005, 2006, 2007 <NAME>
 * Copyright (C) 2006, 2007, 2008, 2009, 2010 <NAME>
 * Copyright (C) 2009, 2010 <NAME>
 * 
 * This file is part of dlvhex.
 *
 * dlvhex is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * dlvhex 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with dlvhex; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

/**
 * @file   TestEvalEndToEnd.cpp
 * @author <NAME> <<EMAIL>>
 * 
 * @brief  Test evaluation starting from HEX program to final models.
 *
 * Functional external atoms are provided in fixture.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

#include "dlvhex2/EvalGraphBuilder.h"
#include "dlvhex2/EvalHeuristicOldDlvhex.h"
#include "dlvhex2/ProgramCtx.h"
#include "dlvhex2/Printer.h"
#include "dlvhex2/Registry.h"
#include "dlvhex2/PluginInterface.h"
#include "dlvhex2/DependencyGraph.h"
#include "dlvhex2/ComponentGraph.h"
#include "dlvhex2/ModelGenerator.h"
#include "dlvhex2/OnlineModelBuilder.h"
#include "dlvhex2/ASPSolver.h"
#include "dlvhex2/ASPSolverManager.h"

// this must be included before dummytypes!
#define BOOST_TEST_MODULE __FILE__
#include <boost/test/unit_test.hpp>

#include "fixturesExt1.h"
#include "graphviz.h"

#include <iostream>
#include <fstream>
#include <cstdlib>

#define LOG_REGISTRY_PROGRAM(ctx) \
  LOG(INFO,*ctx.registry()); \
	RawPrinter printer(std::cerr, ctx.registry()); \
	std::cerr << "edb = " << *ctx.edb << std::endl; \
	LOG(INFO,"idb"); \
	printer.printmany(ctx.idb,"\n"); \
	std::cerr << std::endl; \
	LOG(INFO,"idb end");

LOG_INIT(Logger::ERROR | Logger::WARNING)

DLVHEX_NAMESPACE_USE

typedef FinalEvalGraph::EvalUnit EvalUnit;
typedef OnlineModelBuilder<FinalEvalGraph> FinalOnlineModelBuilder;
typedef FinalOnlineModelBuilder::Model Model;
typedef FinalOnlineModelBuilder::OptionalModel OptionalModel;

BOOST_FIXTURE_TEST_CASE(testEvalHeuristicExt1,ProgramExt1ProgramCtxDependencyGraphComponentGraphFixture) 
{
  LOG_REGISTRY_PROGRAM(ctx);

  // eval graph
  FinalEvalGraph eg;

  {
    // create builder that supervises the construction of eg
    ASPSolverManager::SoftwareConfigurationPtr extEvalConfig(
        new ASPSolver::DLVSoftware::Configuration);
    EvalGraphBuilder egbuilder(ctx, compgraph, eg, extEvalConfig);

    {
      // create heuristic, which sends commands to egbuilder
      EvalHeuristicOldDlvhex heuristicOldDlvhex;
      heuristicOldDlvhex.build(egbuilder);
      LOG(INFO,"building eval graph finished");

      // log the (changed) component graph
      {
        const char* fnamev = "testEvalEndToEndExt1Verbose.dot";
        LOG(INFO,"dumping verbose graph to " << fnamev);
        std::ofstream filev(fnamev);
        compgraph.writeGraphViz(filev, true);
        makeGraphVizPdf(fnamev);

        const char* fnamet = "testEvalEndToEndExt1Terse.dot";
        LOG(INFO,"dumping terse graph to " << fnamet);
        std::ofstream filet(fnamet);
        compgraph.writeGraphViz(filet, false);
        makeGraphVizPdf(fnamet);
      }
    }
  }

  //
  // evaluate
  //
  dlvhex::ModelBuilderConfig<FinalEvalGraph> cfg(eg);
  FinalOnlineModelBuilder omb(cfg);

  EvalUnit ufinal;

  // setup final unit
  {
    BOOST_TEST_MESSAGE("adding ufinal");
    LOG(INFO,"ufinal = " << ufinal);
    ufinal = eg.addUnit(FinalEvalGraph::EvalUnitPropertyBundle());

    FinalEvalGraph::EvalUnitIterator it, itend;
    boost::tie(it, itend) = eg.getEvalUnits();
    for(; it != itend && *it != ufinal; ++it)
    {
{'fraction_non_alphanumeric': 0.1112473935974488, 'fraction_numerical': 0.017171593278547774, 'mean_word_length': 4.213554987212277, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2989749', 'n_tokens_mistral': 2797, 'n_tokens_neox': 2602, 'n_words': 699}