Пример #1
0
    def matchmaking(
        self,
        resource_file: str,
        request_file: str,
        output_file: Optional[str] = None,
        timeout: Optional[float] = None,
        mode: EvaluationMode = EvaluationMode.CORRECTNESS
    ) -> MatchmakingResults:
        """Runs abductions or contractions between all resource and request individuals."""
        exc.raise_if_not_found(resource_file, file_type=exc.FileType.FILE)
        exc.raise_if_not_found(request_file, file_type=exc.FileType.FILE)

        if output_file:
            fileutils.remove(output_file)

        args = MetaArgs.replace(args=self.args(task=ReasoningTask.MATCHMAKING,
                                               mode=mode),
                                input_arg=resource_file,
                                request_arg=request_file,
                                output_arg=output_file)

        task = self._run(args, timeout=timeout, mode=mode)

        results = self.results_parser.parse_matchmaking_results(task)
        return results.with_output(output_file, is_file=True)
Пример #2
0
    def classify(
            self,
            input_file: str,
            output_file: Optional[str] = None,
            timeout: Optional[float] = None,
            mode: EvaluationMode = EvaluationMode.CORRECTNESS
    ) -> ReasoningResults:
        """Runs the classification reasoning task."""
        exc.raise_if_not_found(input_file, file_type=exc.FileType.FILE)

        classification_out = None
        use_owl_tool = self.classification_output_format == OutputFormat.ONTOLOGY

        if output_file:
            if use_owl_tool:
                classification_out = os.path.splitext(output_file)[0]
            else:
                classification_out = output_file
            fileutils.remove(output_file)
            fileutils.remove(classification_out)

        args = MetaArgs.replace(args=self.args(
            task=ReasoningTask.CLASSIFICATION, mode=mode),
                                input_arg=input_file,
                                output_arg=classification_out)

        task = self._run(args=args, timeout=timeout, mode=mode)

        if mode == EvaluationMode.CORRECTNESS and use_owl_tool:
            owltool.print_tbox(classification_out, output_file)

        results = self.results_parser.parse_classification_results(task)
        return results.with_output(output_file, is_file=True)
Пример #3
0
 def _run(self, args: List[str], timeout: Optional[float],
          mode: EvaluationMode) -> Task:
     exc.raise_if_not_found(self._absolute_path(self.path),
                            file_type=exc.FileType.FILE)
     task = Task(self._absolute_path(self.path), args=args)
     task.run(timeout=timeout)
     return task
Пример #4
0
    def consistency(
            self,
            input_file: str,
            timeout: Optional[float] = None,
            mode: EvaluationMode = EvaluationMode.CORRECTNESS
    ) -> ReasoningResults:
        """Checks if the given ontology is consistent."""
        exc.raise_if_not_found(input_file, file_type=exc.FileType.FILE)

        args = MetaArgs.replace(args=self.args(task=ReasoningTask.CONSISTENCY,
                                               mode=mode),
                                input_arg=input_file)

        task = self._run(args, timeout=timeout, mode=mode)
        return self.results_parser.parse_consistency_results(task)
Пример #5
0
    def _run(self, args: List[str], timeout: Optional[float],
             mode: EvaluationMode) -> Task:
        """Runs the reasoner."""
        exc.raise_if_not_found(self._absolute_path(self.path),
                               file_type=exc.FileType.FILE)
        task = self._task(args)

        if mode == EvaluationMode.PERFORMANCE:
            task = Benchmark(task)
        elif mode == EvaluationMode.ENERGY:
            task = EnergyProfiler(task,
                                  self.energy_probe,
                                  sampling_interval=500)

        task.run(timeout=timeout)
        task.raise_if_failed(
            message=f'{self.name} exited with code: {task.exit_code}')

        return task
Пример #6
0
def _spawn_owltool(args: List[str]) -> bool:
    exc.raise_if_not_found(OWLTool.PATH, file_type=exc.FileType.FILE)
    return Jar.spawn(OWLTool.PATH,
                     jar_args=args,
                     vm_opts=OWLTool.VM_OPTS,
                     output_action=OutputAction.DISCARD).exit_code == 0