Skip to content
Snippets Groups Projects
Commit 65031756 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Delete and Select actions (WIP, not implemented).

parent 2bf7fcb4
Branches
No related merge requests found
......@@ -28,6 +28,8 @@ endif(WIN32)
SET(libwccl_STAT_SRC
exception.cpp
ops/action.cpp
ops/actions/delete.cpp
ops/actions/select.cpp
ops/formatters.cpp
ops/functions/bool/iteration.cpp
ops/functions/bool/iterations/atleast.cpp
......
#include <libwccl/ops/actions/delete.h>
#include <libwccl/ops/functions/constant.h>
#include <sstream>
namespace Wccl {
Bool Delete::execute(const ActionExecContext& context) const
{
Bool changed(false);
//@todo: implement
return changed;
}
std::string Delete::to_string(const Corpus2::Tagset& tagset) const
{
std::ostringstream os;
os << name() << "(" << pos_->to_string(tagset) << ", "
<< condition_->to_string(tagset) << ")";
return os.str();
}
std::ostream& Delete::write_to(std::ostream& os) const
{
os << name() << "(" << *pos_ << ", " << *condition_ << ")";
return os;
}
} /* end ns Wccl */
#ifndef LIBWCCL_OPS_ACTIONS_DELETE_H
#define LIBWCCL_OPS_ACTIONS_DELETE_H
#include <libwccl/ops/action.h>
#include <libwccl/values/position.h>
#include <libwccl/values/bool.h>
#include <libwccl/ops/function.h>
namespace Wccl {
/**
* Action to delete lexemes that meet a condition
* (unless no lexemes would be left, in which case
* token is left alone with no changes)
*/
class Delete : public Action
{
public:
typedef boost::shared_ptr<Function<Position> > PosFunctionPtr;
typedef boost::shared_ptr<Function<Bool> > BoolFunctionPtr;
Delete(const BoolFunctionPtr& condition, const PosFunctionPtr& pos = detail::CurrentPos())
: pos_(pos),
condition_(condition)
{
BOOST_ASSERT(pos_);
BOOST_ASSERT(condition_);
}
/**
* @returns Name of the function.
*/
std::string name() const {
return "delete";
}
/**
* @returns String representation of the Action
*/
std::string to_string(const Corpus2::Tagset& tagset) const;
protected:
/**
* Writes string representation of the Action to
* an output stream.
* @returns Stream written to.
* @note May be incomplete and/or containt internal info.
*/
std::ostream& write_to(std::ostream& ostream) const;
/**
* Executes the Action on given context: it deletes
* all lexemes of the token at given position that meet
* the condition, unless all of them meet the condition.
* In such case no action is commited to avoid a token
* that would otherwise have no lexemes remaining.
* Also, no action is done if position points outside sentence.
* @returns True if there were any changes made; False otherwise
*/
Bool execute(const ActionExecContext &context) const;
private:
const PosFunctionPtr pos_;
const BoolFunctionPtr condition_;
};
} /* end ns Wccl */
#endif // LIBWCCL_OPS_ACTIONS_DELETE_H
#include <libwccl/ops/actions/select.h>
#include <libwccl/ops/functions/constant.h>
#include <sstream>
namespace Wccl {
Bool Select::execute(const ActionExecContext& context) const
{
Bool changed(false);
//@todo: implement
return changed;
}
std::string Select::to_string(const Corpus2::Tagset& tagset) const
{
std::ostringstream os;
os << name() << "(" << pos_->to_string(tagset) << ", "
<< condition_->to_string(tagset) << ")";
return os.str();
}
std::ostream& Select::write_to(std::ostream& os) const
{
os << name() << "(" << *pos_ << ", " << *condition_ << ")";
return os;
}
} /* end ns Wccl */
#ifndef LIBWCCL_OPS_ACTIONS_SELECT_H
#define LIBWCCL_OPS_ACTIONS_SELECT_H
#include <libwccl/ops/action.h>
#include <libwccl/values/position.h>
#include <libwccl/values/bool.h>
#include <libwccl/ops/function.h>
namespace Wccl {
/**
* Action to keep only lexemes that meet a condition
* (unless no lexemes would be left, in which case
* token is left alone with no changes)
*/
class Select : public Action
{
public:
typedef boost::shared_ptr<Function<Position> > PosFunctionPtr;
typedef boost::shared_ptr<Function<Bool> > BoolFunctionPtr;
Select(const BoolFunctionPtr& condition, const PosFunctionPtr& pos = detail::CurrentPos())
: pos_(pos),
condition_(condition)
{
BOOST_ASSERT(pos_);
BOOST_ASSERT(condition_);
}
/**
* @returns Name of the function.
*/
std::string name() const {
return "select";
}
/**
* @returns String representation of the Action
*/
std::string to_string(const Corpus2::Tagset& tagset) const;
protected:
/**
* Writes string representation of the Action to
* an output stream.
* @returns Stream written to.
* @note May be incomplete and/or containt internal info.
*/
std::ostream& write_to(std::ostream& ostream) const;
/**
* Executes the Action on given context: it deletes
* all lexemes of the token at given position that do not meet
* the condition, unless none of them meets the condition.
* In such case no action is commited to avoid a token
* that would otherwise have no lexemes remaining.
* Also, no action is done if position points outside sentence.
* @returns True if there were any changes made; False otherwise
*/
Bool execute(const ActionExecContext &context) const;
private:
const PosFunctionPtr pos_;
const BoolFunctionPtr condition_;
};
} /* end ns Wccl */
#endif // LIBWCCL_OPS_ACTIONS_SELECT_H
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment