LoadingOntologyFilesFromGitHub - mdebellis/SemanticKG-Design GitHub Wiki
Loading ontology files from GitHub can be a bit unintuitive. Protégé and other tools can load ontologies directly from GitHub, but only if the URL points to the raw ontology file, rather than the human-readable GitHub webpage.
Using the People Ontology as an example, when you navigate to the file in GitHub, the URL looks like this:
https://github.com/mdebellis/SemanticKG-Design/blob/main/ontologies/people_ontology.ttl
This is not the actual ontology file. It is the HTML page that displays the file in the GitHub interface. For example, if you give this URL to Protégé’s import wizard, Protégé attempts to parse the HTML as Turtle or RDF/XML and fails, showing messages such as:
Nothing to import
or a blank summary page, along with a Java parsing error in the log.
Many Semantic Knowledge Graph tools allow you to load an ontology directly from a URL. This is convenient because it ensures that the ontology used by your tools, your team, and your automated processes all come from a single authoritative source.
When using GitHub, the easiest way to obtain a stable URL for an ontology file is through the Raw view.
GitHub presents every file in two ways:
- A formatted preview version
- A raw version
The preview version shows syntax highlighting and GitHub metadata. The raw version provides the exact file contents. To load an ontology into tools such as Protégé, GraphDB, Apache Jena, or AllegroGraph, you should always use the raw version.
To obtain the correct URL:
- Navigate to the file in your GitHub repository.
- Click the Raw button in the upper-right corner of the file viewer.
- When the file opens in your browser, copy the URL from the address bar.
- Use that URL in the tool you are working with.
The raw URL follows this general pattern:
https://raw.githubusercontent.com/<user>/<repo>/<branch>/<path>
For example, the People Ontology used throughout the book can be loaded with the following URL:
https://raw.githubusercontent.com/mdebellis/SemanticKG-Design/main/ontologies/people_ontology.ttl
This URL returns the exact file contents and can be used anywhere a tool expects an ontology IRI or a URL for importing RDF/OWL files.
GitHub occasionally displays long or tokenized URLs when viewing files while logged in, especially if you are the repository owner or a collaborator. These URLs may contain session information or access tokens and are not intended for sharing or long-term use.
If you see a URL with a long query string, for example one ending with something like this:
?token=...
click Raw again or open the Raw view in a private or incognito browser window. The canonical raw URL will always have the simpler raw.githubusercontent.com structure shown above.
You can copy the raw file URL and paste it into any field in Protégé or another Semantic Knowledge Graph tool that prompts you for a URL path.
For example, in Protégé:
- Select File > Open from URL.
- Paste the raw GitHub URL into the field that appears.
- Protégé will load the ontology directly from GitHub.
Whenever you load ontologies from GitHub, make sure you are giving Protégé or any other tool the link to the raw file, not the GitHub preview page.
Use this form:
https://raw.githubusercontent.com/<user>/<repo>/<branch>/<path>
not this form:
https://github.com/<user>/<repo>/blob/<branch>/<path>