Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output the right relations in PCleanSchemaHelper::make_hirm_schema #119

Merged
merged 6 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cxx/pclean/schema_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ PCleanVariable PCleanSchemaHelper::get_scalarvar_from_path(
assert(false);
}

// Returns original_domains, but with the elements corresponding to
// annotated_ds elements that start with prefix moved to the front.
std::vector<std::string> reorder_domains(
const std::vector<std::string>& original_domains,
const std::vector<std::string>& annotated_ds,
Expand Down
7 changes: 7 additions & 0 deletions cxx/pclean/schema_helper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ class PCleanSchemaHelper {
std::map<std::string, std::vector<std::string>> domains;
std::map<std::string, std::vector<std::string>> annotated_domains;
};

// Returns original_domains, but with the elements corresponding to
// annotated_ds elements that start with prefix moved to the front.
std::vector<std::string> reorder_domains(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a comment somewhere explaining how it works that this function, when applied to noisy relation domains, moves the domains corresponding to base relation domains not only to the front, but also in the same order as the base relation domains? I think I understand but that's an important guarantee and we should document it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

const std::vector<std::string>& original_domains,
const std::vector<std::string>& annotated_ds,
const std::string& prefix);
25 changes: 25 additions & 0 deletions cxx/pclean/schema_helper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,29 @@ BOOST_AUTO_TEST_CASE(test_make_hirm_schmea) {
BOOST_TEST(nr5.domains == expected_domains);
}

BOOST_AUTO_TEST_CASE(test_reorder_domains) {
std::vector<std::string> origs = {"0", "1", "2", "3", "4", "5", "6", "7"};
std::vector<std::string> annotated = {
"000", "001", "010", "011", "100", "101", "110", "111"};

std::vector<std::string> expected = {
"6", "7", "0", "1", "2", "3", "4", "5"};
BOOST_TEST(reorder_domains(origs, annotated, "11") == expected);

expected = {"4", "5", "6", "7", "0", "1", "2", "3"};
BOOST_TEST(reorder_domains(origs, annotated, "1") == expected);

origs = {
"republic_of_ireland", "northern_ireland", "england", "scotland", "wales"};
annotated = {
"ireland:republic_of_ireland",
"ireland:uk:northern_ireland",
"great_britain:uk:england",
"great_britain:uk:scotland",
"great_britain:uk:wales"};
expected = {
"northern_ireland", "republic_of_ireland", "england", "scotland", "wales"};
BOOST_TEST(reorder_domains(origs, annotated, "ireland:uk:") == expected);
}

BOOST_AUTO_TEST_SUITE_END()