# Path: smore/common/util.py
# GBFACTOR = float(1 << 30)
# def cal_ent_loc(query_structure, idx):
# def cal_ent_loc_dict(query_name_dict):
# def list2tuple(l):
# def tuple2list(t):
# def parse_time():
# def set_global_seed(seed):
# def eval_tuple(arg_return):
# def flatten_query(queries):
# def construct_graph(base_path, indexified_files):
# def tuple2filterlist(t):
# def achieve_answer_with_constraints(query, ent_in, ent_out, max_to_keep):
# def fill_query(query_structure, ent_in, ent_out, answer, chill=False):
# def sample_negative_bidirectional(query, ent_in, ent_out, nent):
# def download_url(url, folder, log=True):
# def maybe_download_dataset(data_path):
# def extract_zip(path, folder):
# def thread_wrapped_func(func):
#     def decorated_function(*args, **kwargs):
#         def _queue_result():
# def log_metrics(mode, step, metrics):
#     def embed_query_old(queries, query_structure, idx):
#     def embed_query_new(queries, query_structure, idx, all_ent_embedding, ent_idx):
#     def transform_union_query(queries, query_structure):
#     def transform_union_structure(query_structure):
# 
# Path: smore/common/util.py
# GBFACTOR = float(1 << 30)
# def cal_ent_loc(query_structure, idx):
# def cal_ent_loc_dict(query_name_dict):
# def list2tuple(l):
# def tuple2list(t):
# def parse_time():
# def set_global_seed(seed):
# def eval_tuple(arg_return):
# def flatten_query(queries):
# def construct_graph(base_path, indexified_files):
# def tuple2filterlist(t):
# def achieve_answer_with_constraints(query, ent_in, ent_out, max_to_keep):
# def fill_query(query_structure, ent_in, ent_out, answer, chill=False):
# def sample_negative_bidirectional(query, ent_in, ent_out, nent):
# def download_url(url, folder, log=True):
# def maybe_download_dataset(data_path):
# def extract_zip(path, folder):
# def thread_wrapped_func(func):
#     def decorated_function(*args, **kwargs):
#         def _queue_result():
# def log_metrics(mode, step, metrics):
#     def embed_query_old(queries, query_structure, idx):
#     def embed_query_new(queries, query_structure, idx, all_ent_embedding, ent_idx):
#     def transform_union_query(queries, query_structure):
#     def transform_union_structure(query_structure):


from torch.utils.data import Dataset
from smore.common.util import list2tuple, tuple2list, flatten
from collections import defaultdict
from smore.common.util import fill_query, achieve_answer_with_constraints, list2tuple, tuple2list, flatten, flatten_list, sample_negative_bidirectional
import numpy as np
import torch
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




class TestDataset(Dataset):

# Path: smore/common/util.py
# GBFACTOR = float(1 << 30)
# def cal_ent_loc(query_structure, idx):
# def cal_ent_loc_dict(query_name_dict):
# def list2tuple(l):
# def tuple2list(t):
# def parse_time():
# def set_global_seed(seed):
# def eval_tuple(arg_return):
# def flatten_query(queries):
# def construct_graph(base_path, indexified_files):
# def tuple2filterlist(t):
# def achieve_answer_with_constraints(query, ent_in, ent_out, max_to_keep):
# def fill_query(query_structure, ent_in, ent_out, answer, chill=False):
# def sample_negative_bidirectional(query, ent_in, ent_out, nent):
# def download_url(url, folder, log=True):
# def maybe_download_dataset(data_path):
# def extract_zip(path, folder):
# def thread_wrapped_func(func):
#     def decorated_function(*args, **kwargs):
#         def _queue_result():
# def log_metrics(mode, step, metrics):
#     def embed_query_old(queries, query_structure, idx):
#     def embed_query_new(queries, query_structure, idx, all_ent_embedding, ent_idx):
#     def transform_union_query(queries, query_structure):
#     def transform_union_structure(query_structure):
# 
# Path: smore/common/util.py
# GBFACTOR = float(1 << 30)
# def cal_ent_loc(query_structure, idx):
# def cal_ent_loc_dict(query_name_dict):
# def list2tuple(l):
# def tuple2list(t):
# def parse_time():
# def set_global_seed(seed):
# def eval_tuple(arg_return):
# def flatten_query(queries):
# def construct_graph(base_path, indexified_files):
# def tuple2filterlist(t):
# def achieve_answer_with_constraints(query, ent_in, ent_out, max_to_keep):
# def fill_query(query_structure, ent_in, ent_out, answer, chill=False):
# def sample_negative_bidirectional(query, ent_in, ent_out, nent):
# def download_url(url, folder, log=True):
# def maybe_download_dataset(data_path):
# def extract_zip(path, folder):
# def thread_wrapped_func(func):
#     def decorated_function(*args, **kwargs):
#         def _queue_result():
# def log_metrics(mode, step, metrics):
#     def embed_query_old(queries, query_structure, idx):
#     def embed_query_new(queries, query_structure, idx, all_ent_embedding, ent_idx):
#     def transform_union_query(queries, query_structure):
#     def transform_union_structure(query_structure):


# Path: smore/evaluation/dataloader.py
from torch.utils.data import Dataset
from smore.common.util import list2tuple, tuple2list, flatten
from collections import defaultdict
from smore.common.util import fill_query, achieve_answer_with_constraints, list2tuple, tuple2list, flatten, flatten_list, sample_negative_bidirectional
import numpy as np
import torch

# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




class TestDataset(Dataset):

    def __init__(self, nentity, nrelation):