Skip to content

Add functionality to guess the intended input file format #1058

@jamesaoverton

Description

@jamesaoverton

Building on #1038.

PR #1056 is already very useful, but it made me wonder: Why don't we have a utility that would determine the file format, or at least make a good guess at what was intended? It could be added to #1056 as a --input-format detect or --input-format auto option, and maybe used whenever parsing fails.

The root problem is that a .owl extension is used for several different formats supported by OWLAPI. For most of the OBO use cases we expect RDF/XML, but it could be OWL/XML or Manchester or OWL Functional or Turtle. The OWLAPI will try a dozen different parsers until one of them works, and if it successfully loads then we can ask with OWLOntologyManager.getOntologyFormat(). The interesting case is #1038 where the ontology fails to load but we should still be able to guess the intended format, and then report the most useful parsing error.

When I'm not sure about the format, I just look at the first few lines of the file. It shouldn't be hard to write code for some crude heuristics. This would be useful even if it misses some weird edge cases.

  • RDF/XML: look for the <rdf:RDF> (skip XML DTD stuff)
  • Turtle: look for @prefix
  • OWL Functional: look for Prefix(

We could also have useful error messages for common failure modes:

  • HTML, e.g. a 404 reponse
  • empty file

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions