Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 17 additions & 3 deletions khiops/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
from khiops.core.internals.runner import get_runner


def build_multi_table_dictionary_domain(
def _build_multi_table_dictionary_domain(
dictionary_domain, root_dictionary_name, secondary_table_variable_name
):
"""Builds a multi-table dictionary domain from a dictionary with a key

Parameters
----------
dictionary_domain : `.DictionaryDomain`
Expand All @@ -36,6 +35,11 @@ def build_multi_table_dictionary_domain(
secondary_table_variable_name : str
Name, in the root dictionary, for the "table" variable of the secondary table.

Returns
-------
`.DictionaryDomain`
The new dictionary domain

Raises
------
`TypeError`
Expand All @@ -45,6 +49,16 @@ def build_multi_table_dictionary_domain(
- the dictionary domain doesn't contain at least a dictionary
- the dictionary domain's root dictionary doesn't have a key set
"""

# This is a special-purpose function whose goal is to assist in preparing the
# coclustering deployment.
# This function builds a new root dictionary and adds it to an existing dictionary
# domain.
# The new root dictionary only contains one field, which references a preexisting
# dictionary from the input dictionary domain as a new (secondary) Table variable.
# The preexisting dictionary must have a key set on it, as this is the join key
# with the new root table.

# Check that `dictionary_domain` is a `DictionaryDomain`
if not isinstance(dictionary_domain, DictionaryDomain):
raise TypeError(
Expand Down Expand Up @@ -279,7 +293,7 @@ def deploy_coclustering(
# Create a root dictionary containing the keys
root_dictionary_name = "CC_" + dictionary_name
table_variable_name = "Table_" + dictionary_name
domain = build_multi_table_dictionary_domain(
domain = _build_multi_table_dictionary_domain(
tmp_domain, root_dictionary_name, table_variable_name
)

Expand Down
4 changes: 2 additions & 2 deletions khiops/sklearn/estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import khiops.core as kh
import khiops.core.internals.filesystems as fs
from khiops.core.dictionary import DictionaryDomain
from khiops.core.helpers import build_multi_table_dictionary_domain
from khiops.core.helpers import _build_multi_table_dictionary_domain
from khiops.core.internals.common import is_dict_like, is_list_like, type_error_message
from khiops.sklearn.dataset import (
Dataset,
Expand Down Expand Up @@ -862,7 +862,7 @@ def _create_coclustering_model_domain(
assert isinstance(output_dir, str)

# Build multi-table dictionary domain out of the input domain
mt_domain = build_multi_table_dictionary_domain(
mt_domain = _build_multi_table_dictionary_domain(
domain,
self.model_main_dictionary_name_,
self.model_secondary_table_variable_name,
Expand Down
28 changes: 0 additions & 28 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from khiops.core.internals.runner import KhiopsLocalRunner, KhiopsRunner
from khiops.core.internals.scenario import ConfigurableKhiopsScenario
from khiops.core.internals.version import KhiopsVersion
from tests.test_helper import KhiopsTestHelper

# Disable warning about access to protected member: These are tests
# pylint: disable=protected-access
Expand Down Expand Up @@ -2434,33 +2433,6 @@ def test_invalid_versions(self):
with self.assertRaises(ValueError):
KhiopsVersion(version)

@staticmethod
def _build_multi_table_dictionary_args():
resources_directory = KhiopsTestHelper.get_resources_dir()
dictionaries_dir = os.path.join(resources_directory, "dictionary", "ref_kdic")
splice_domain = kh.read_dictionary_file(
os.path.join(dictionaries_dir, "SpliceJunction.kdic")
)
monotable_domain = kh.DictionaryDomain()
monotable_domain.add_dictionary(
splice_domain.get_dictionary("SpliceJunctionDNA")
)
output_directory = os.path.join(
resources_directory, "dictionary", "output_kdic"
)
root_dict_name = "SpliceJunction"
secondary_table_variable_name = "DNA"
multi_table_dict_out_path = os.path.join(
output_directory, "SpliceJunctionTest.kdic"
)

return {
"dictionary_file_path_or_domain": monotable_domain,
"root_dictionary_name": root_dict_name,
"secondary_table_variable_name": secondary_table_variable_name,
"output_dictionary_file_path": multi_table_dict_out_path,
}

def test_scenario_generation(self):
"""Test the scenario generation from template and arguments"""
templates = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pandas as pd

from khiops.core.dictionary import DictionaryDomain
from khiops.core.helpers import build_multi_table_dictionary_domain, visualize_report
from khiops.core.helpers import _build_multi_table_dictionary_domain, visualize_report
from khiops.sklearn import train_test_split_dataset


Expand Down Expand Up @@ -78,7 +78,7 @@ def test_build_multi_table_dictionary_domain(self):
ref_multi_table_domain = DictionaryDomain(ref_multi_table_domain_specification)

# Build multi-table dictionary domain from the montable dictionary domain
multi_table_domain = build_multi_table_dictionary_domain(
multi_table_domain = _build_multi_table_dictionary_domain(
monotable_domain, "A_Prefix_SpliceJunctionDNA", "A_Name_SpliceJunctionDNA"
)

Expand Down