bench_executor.yarrrml

YARRRML is a human readable text-based representation for declarative Linked Data generation rules.

Website: https://rml.io/yarrrml/
Repository: https://github.com/RMLio/yarrrml-parser

 1#!/usr/bin/env python3
 2
 3"""
 4YARRRML is a human readable text-based representation for declarative
 5Linked Data generation rules.
 6
 7**Website**: https://rml.io/yarrrml/<br>
 8**Repository**: https://github.com/RMLio/yarrrml-parser
 9"""
10
11import os
12from bench_executor.container import Container
13from bench_executor.logger import Logger
14
15VERSION = '1.3.6'
16
17
18class YARRRML(Container):
19    """YARRRML container to transform YARRRML mappings into RML mappings."""
20
21    def __init__(self, data_path: str, config_path: str, directory: str,
22                 verbose: bool):
23        """Creates an instance of the YARRRML class.
24
25        Parameters
26        ----------
27        data_path : str
28            Path to the data directory of the case.
29        config_path : str
30            Path to the config directory of the case.
31        directory : str
32            Path to the directory to store logs.
33        verbose : bool
34            Enable verbose logs.
35        """
36        self._data_path = os.path.abspath(data_path)
37        self._config_path = os.path.abspath(config_path)
38        self._logger = Logger(__name__, directory, verbose)
39
40        os.makedirs(os.path.join(self._data_path, 'yarrrml'), exist_ok=True)
41        super().__init__(f'blindreviewing/yarrrml:v{VERSION}', 'YARRRML',
42                         self._logger,
43                         volumes=[f'{self._data_path}/yarrrml:/data',
44                                  f'{self._data_path}/shared:/data/shared'])
45
46    @property
47    def root_mount_directory(self) -> str:
48        """Subdirectory in the root directory of the case for YARRRML.
49
50        Returns
51        -------
52        subdirectory : str
53            Subdirectory of the root directory for YARRRML.
54        """
55        return __name__.lower()
56
57    def transform_mapping(self, yarrrml_file: str, mapping_file: str,
58                          r2rml: bool = False, pretty: bool = True) -> bool:
59        """Transform a YARRRML mapping into a RML mapping.
60
61        Parameters
62        ----------
63        yarrrml_file : str
64            Name of the YARRRML mapping file.
65        mapping_file : str
66            Name of the RML mapping file.
67        r2rml : bool
68            Whether the RML mapping file must be R2RML compatible.
69        pretty : bool
70            Whether the generated mapping file must be pretty or not.
71
72        Returns
73        -------
74        success : bool
75            Whether the YARRRML was initialized successfull or not.
76        """
77        arguments = ['-i', os.path.join('/data/shared/', yarrrml_file),
78                     '-o', os.path.join('/data/shared/', mapping_file)]
79
80        if r2rml:
81            arguments.append('-c')
82            arguments.append('-f R2RML')
83
84        if pretty:
85            arguments.append('-p')
86
87        self._logger.debug(f'Executing YARRRML with arguments '
88                           f'"{" ".join(arguments)}"\n')
89
90        cmd = f'{" ".join(arguments)}'
91        success = self.run_and_wait_for_exit(cmd)
92        return success
class YARRRML(bench_executor.container.Container):
19class YARRRML(Container):
20    """YARRRML container to transform YARRRML mappings into RML mappings."""
21
22    def __init__(self, data_path: str, config_path: str, directory: str,
23                 verbose: bool):
24        """Creates an instance of the YARRRML class.
25
26        Parameters
27        ----------
28        data_path : str
29            Path to the data directory of the case.
30        config_path : str
31            Path to the config directory of the case.
32        directory : str
33            Path to the directory to store logs.
34        verbose : bool
35            Enable verbose logs.
36        """
37        self._data_path = os.path.abspath(data_path)
38        self._config_path = os.path.abspath(config_path)
39        self._logger = Logger(__name__, directory, verbose)
40
41        os.makedirs(os.path.join(self._data_path, 'yarrrml'), exist_ok=True)
42        super().__init__(f'blindreviewing/yarrrml:v{VERSION}', 'YARRRML',
43                         self._logger,
44                         volumes=[f'{self._data_path}/yarrrml:/data',
45                                  f'{self._data_path}/shared:/data/shared'])
46
47    @property
48    def root_mount_directory(self) -> str:
49        """Subdirectory in the root directory of the case for YARRRML.
50
51        Returns
52        -------
53        subdirectory : str
54            Subdirectory of the root directory for YARRRML.
55        """
56        return __name__.lower()
57
58    def transform_mapping(self, yarrrml_file: str, mapping_file: str,
59                          r2rml: bool = False, pretty: bool = True) -> bool:
60        """Transform a YARRRML mapping into a RML mapping.
61
62        Parameters
63        ----------
64        yarrrml_file : str
65            Name of the YARRRML mapping file.
66        mapping_file : str
67            Name of the RML mapping file.
68        r2rml : bool
69            Whether the RML mapping file must be R2RML compatible.
70        pretty : bool
71            Whether the generated mapping file must be pretty or not.
72
73        Returns
74        -------
75        success : bool
76            Whether the YARRRML was initialized successfull or not.
77        """
78        arguments = ['-i', os.path.join('/data/shared/', yarrrml_file),
79                     '-o', os.path.join('/data/shared/', mapping_file)]
80
81        if r2rml:
82            arguments.append('-c')
83            arguments.append('-f R2RML')
84
85        if pretty:
86            arguments.append('-p')
87
88        self._logger.debug(f'Executing YARRRML with arguments '
89                           f'"{" ".join(arguments)}"\n')
90
91        cmd = f'{" ".join(arguments)}'
92        success = self.run_and_wait_for_exit(cmd)
93        return success

YARRRML container to transform YARRRML mappings into RML mappings.

YARRRML(data_path: str, config_path: str, directory: str, verbose: bool)
22    def __init__(self, data_path: str, config_path: str, directory: str,
23                 verbose: bool):
24        """Creates an instance of the YARRRML class.
25
26        Parameters
27        ----------
28        data_path : str
29            Path to the data directory of the case.
30        config_path : str
31            Path to the config directory of the case.
32        directory : str
33            Path to the directory to store logs.
34        verbose : bool
35            Enable verbose logs.
36        """
37        self._data_path = os.path.abspath(data_path)
38        self._config_path = os.path.abspath(config_path)
39        self._logger = Logger(__name__, directory, verbose)
40
41        os.makedirs(os.path.join(self._data_path, 'yarrrml'), exist_ok=True)
42        super().__init__(f'blindreviewing/yarrrml:v{VERSION}', 'YARRRML',
43                         self._logger,
44                         volumes=[f'{self._data_path}/yarrrml:/data',
45                                  f'{self._data_path}/shared:/data/shared'])

Creates an instance of the YARRRML class.

Parameters
  • data_path (str): Path to the data directory of the case.
  • config_path (str): Path to the config directory of the case.
  • directory (str): Path to the directory to store logs.
  • verbose (bool): Enable verbose logs.
root_mount_directory: str

Subdirectory in the root directory of the case for YARRRML.

Returns
  • subdirectory (str): Subdirectory of the root directory for YARRRML.
def transform_mapping( self, yarrrml_file: str, mapping_file: str, r2rml: bool = False, pretty: bool = True) -> bool:
58    def transform_mapping(self, yarrrml_file: str, mapping_file: str,
59                          r2rml: bool = False, pretty: bool = True) -> bool:
60        """Transform a YARRRML mapping into a RML mapping.
61
62        Parameters
63        ----------
64        yarrrml_file : str
65            Name of the YARRRML mapping file.
66        mapping_file : str
67            Name of the RML mapping file.
68        r2rml : bool
69            Whether the RML mapping file must be R2RML compatible.
70        pretty : bool
71            Whether the generated mapping file must be pretty or not.
72
73        Returns
74        -------
75        success : bool
76            Whether the YARRRML was initialized successfull or not.
77        """
78        arguments = ['-i', os.path.join('/data/shared/', yarrrml_file),
79                     '-o', os.path.join('/data/shared/', mapping_file)]
80
81        if r2rml:
82            arguments.append('-c')
83            arguments.append('-f R2RML')
84
85        if pretty:
86            arguments.append('-p')
87
88        self._logger.debug(f'Executing YARRRML with arguments '
89                           f'"{" ".join(arguments)}"\n')
90
91        cmd = f'{" ".join(arguments)}'
92        success = self.run_and_wait_for_exit(cmd)
93        return success

Transform a YARRRML mapping into a RML mapping.

Parameters
  • yarrrml_file (str): Name of the YARRRML mapping file.
  • mapping_file (str): Name of the RML mapping file.
  • r2rml (bool): Whether the RML mapping file must be R2RML compatible.
  • pretty (bool): Whether the generated mapping file must be pretty or not.
Returns
  • success (bool): Whether the YARRRML was initialized successfull or not.