Skip to content

Commit

Permalink
adding get_positives_and_negatives
Browse files Browse the repository at this point in the history
  • Loading branch information
castrod committed Jan 18, 2024
1 parent ce3d1e6 commit 7b5f72b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/nso_rr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,6 @@ struct callback_applier {
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> wff_changes;
for (auto& l: get_leaves(wff, tau_parser::wff_or, tau_parser::wff)) {
std::map<sp_tau_node<BAs...>, sp_tau_node<BAs...>> n_changes;
// FIXME it could have no equalities
auto check_eq = find_top(l, is_non_terminal<tau_parser::bf_eq, BAs...>);
if (check_eq.has_value()) {
auto f = check_eq
Expand Down
3 changes: 3 additions & 0 deletions src/rewriting.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct replace_transformer {
// visitor that selects top nodes that satisfy a predicate and stores them in the
// supplied vector. It only works with post order traversals and never produces
// duplicates.
// TODO (MEDIUM) replace vector by set
template <typename predicate_t, typename node_t>
struct select_top_predicate {
select_top_predicate(predicate_t& query, std::vector<node_t>& selected) :
Expand All @@ -336,6 +337,7 @@ struct select_top_predicate {
// visitor that selects nodes that satisfy a predicate and stores the subnodes
// extracted from them in the supplied vector. It only works with post order
// traversals and never produces duplicates.
// TODO (MEDIUM) replace vector by set
template <typename predicate_t, typename extractor_t, typename node_t>
struct select_subnodes_predicate {
select_subnodes_predicate(predicate_t& query, extractor_t extractor, std::vector<node_t>& selected) :
Expand All @@ -359,6 +361,7 @@ struct select_subnodes_predicate {

// visitor that selects nodes that satisfy a predicate and stores them in the
// supplied vector.
// TODO (MEDIUM) replace vector by set
template <typename predicate_t, typename node_t>
struct select_all_predicate {
select_all_predicate(predicate_t& query, std::vector<node_t>& selected) :
Expand Down
14 changes: 12 additions & 2 deletions src/tau.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,18 @@ std::string clause_to_string(const sp_tau_node<tau_ba<BAs...>, BAs...>& clause,

template<typename... BAs>
void get_positive_and_negative_literals(const tau_spec<BAs...> collapsed,
wff<tau_ba<BAs...>, BAs...>& positive,
std::vector<wff<tau_ba<BAs...>, BAs...>>& negatives) {
std::optional<wff<tau_ba<BAs...>, BAs...>>& positive, std::vector<wff<tau_ba<BAs...>, BAs...>>& negatives) {
auto is_negative = [&collapsed] (const auto& n) {
auto check = collapsed | tau_parser::tau | tau_parser::tau_neg;
return check.has_value();
};
auto is_positive = [&collapsed] (const auto& n) {
auto check = collapsed | tau_parser::tau | tau_parser::tau_neg;
return !check.has_value();
};
negatives = select_top(collapsed, is_negative);
auto positives = collapsed.child | std::views::filter(is_positive) | std::views::take(1);
if (positives.size() > 0) positive = positives[0];
}

template<typename... BAs>
Expand Down

0 comments on commit 7b5f72b

Please sign in to comment.