input.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from pipeline.backend.config import IODataType
  17. class Input(object):
  18. def __init__(self, name, data_type="single"):
  19. if data_type == "single":
  20. self.data = InputData(name).data
  21. self.data_output = InputData(name).get_all_input()
  22. elif data_type == "multi":
  23. self.data = TrainingInputData(name)
  24. self.data_output = InputData(name).get_all_input()
  25. else:
  26. raise ValueError("input data type should be one of ['single', 'multi']")
  27. class InputData(object):
  28. def __init__(self, prefix):
  29. self.prefix = prefix
  30. @property
  31. def data(self):
  32. return ".".join([self.prefix, IODataType.SINGLE])
  33. @staticmethod
  34. def get_all_input():
  35. return ["data"]
  36. class TrainingInputData(object):
  37. def __init__(self, prefix):
  38. self.prefix = prefix
  39. @property
  40. def train_data(self):
  41. return ".".join([self.prefix, IODataType.TRAIN])
  42. @property
  43. def test_data(self):
  44. return ".".join([self.prefix, IODataType.TEST])
  45. @property
  46. def validate_data(self):
  47. return ".".join([self.prefix, IODataType.VALIDATE])
  48. @staticmethod
  49. def get_all_input():
  50. return [IODataType.TRAIN,
  51. IODataType.VALIDATE,
  52. IODataType.TEST]