Skip to content
forked from RDFLib/pyLODE

An OWL ontology documentation tool using Python and templating, based on LODE

License

Notifications You must be signed in to change notification settings

koslambrou/pyLODE

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyLODE

An OWL ontology documentation tool using Python and templating, based on LODE.

Contents

  1. Quick Intro
  2. Examples
  3. Installation
  4. Use
  5. What pyLODE understands
  6. Profiles
  7. Differences from LODE
  8. License
  9. Citation
  10. Collaboration
  11. Contacts

Quick Intro

The Live OWL Documentation Environment tool (LODE) is a well-known (in Semantic Web circles) Java & XSLT-based tool used to generate human-readable HTML documents for OWL and RDF ontologies. That tool is now a bit dated (old-style HTML, use of older technologies like XSLT) and it's (online version) is not always online.

This tool is a complete re-implementation of LODE's functionality using Python and Python's RDF manipulation module, rdflib. An ontology to be documented is parsed and inspected using rdflib and HTML or Markdown is generated using basic Python scripting and Python's Jinja2 templating.

The tool can be run as in these ways:

Examples

pyLODE has been tested with all of the 30+ ontologies in src/pylode/examples/ and we are trying to ensure it captures all of their annotations. For each example, there is the original RDF file and the corresponding output, either HTML, Markdown or both.

For example, Epimorphic's's Registry Ontology is:

Ontologies online using pyLODE:

See pairs of RDF & HTML files in the pylode/examples/ directory for other, preprocessed examples.

Installation

This tool can be used either as a command line utility (Linux, Mac or Windows, see below) or as a Python module in other Python code. It can also be used via an online API. This repo contains executable files for Mac & Windows (soon Linux!) that you can use without any installation too.

Python

Do this to use pyLODE as a Python command line program.

This tool is available on PyPI, the Python Package Index, at https://pypi.org/project/pyLODE/ and can be installed for use as a Python module via pip:

pip install pylode

For desktop command line use, just clone this repository and either use cli.py as per the command line instructions below or use makedocco.py as a Python script directly.

Use

pyLODE presents natively as a Python command-line utility, pylode/cli.py and there are also a BASH, Windows & Mac OS options available for command line use:

Additionally, there is a Falcon framework local HTTP server option.

All use the same command line arguments.

Command line arguments

These are the command line arguments to run pyLODE as a BASH or Python script on Linux, Mac etc. or via the Windows executable:

  • -i or --inputfile, required if -u not used
    • The RDF ontology file you wish to generate HTML for Must be in either Turtle, RDF/XML, JSON-LD or N-Triples formats indicated by the file type extensions .rdf, .owl, .ttl, .n3, .nt, .json respectively
  • -u or --url, required if -i not used
    • The RDF ontology you wish to generate HTML for, online. Must be an absolute URL that can be resolved to RDF, preferably via Content Negotiation.
  • -c or --css, optional, default 'false'
    • Whether (true) or not (false) to copy the default CSS file to the output directory.
  • -o or --outputfile, optional
    • A name you wish to assign to the output file. Will be postfixed with .html or .md. If not specified, the name of the input file or last segment of RDF URI will be used, + .html/.md.
  • -f or --outputformat, optional, default 'html'
    • The output format of the documentation. 'html' or 'md' accepted.
  • -p or --profile, optional, default 'owl'
    • The profile (specification) for ontology documentation used. This has been "owl" (for OWL Ontology) only until the recent introduction of "skos" (according to the Simple Knowledge Organization System (SKOS)). See -lp for all profiles supported.
  • -lp or --listprofiles, optional, no arguments
    • Lists all the profiles (specifications) for ontology documentation supported by pyLODE

Example call

This call to the BASH script in pylode/bin/ will create an HTML document for an ontology called placenames.html and save it with a basic CSS file into pylode/output_files/:

$ ./pylode -i ../example/prof.ttl --css true

Online API

An online API to access pyLODE is now available in test mode at https://kurrawong.net/pylode-online.

Local server - Falcon

You can run pyLODE using your own, local, HTTP server like this: ` gunicorn server:api ` Then, in another terminal: ` curl localhost:8000/lode?url=http://sweetontology.net/sweetAll.ttl `

Windows - create EXE from source

Pyinstaller can be used to create an executable for Windows that has the same characteristics as the Linux/Mac CLI program. The necessary .spec file is already included in pylode-cli.spec. The pylode-cli.spec PyInstaller spec file creates a .exe for the pyLODE Command Line utility. See above for the pyLODE command line util usage instructions.

See the PyInstaller installation guide for info on how to install PyInstaller for Windows.

Once you have pyinstaller, use pyinstaller to generate the pyLODE.exe CLI file like so:

$ cd src/pylode
$ pyinstaller pylode-cli.spec

This will output pylode.exe in the dist directory in src/pylode.

You can now run the pyLODE Command Line utility via pylode.exe. See above for the pyLODE command line util usage instructions.

Mac OS - create APP from source

As per instructions for PyInstaller use on Windows, just do it on a Mac!

What pyLODE understands

Annotations

pyLODE understands the following ontology constructs:

  • ontology metadata
    • imports - owl:imports
    • title - rdfs:label or skos:prefLabel or dct:title or dc:title
    • description - rdfs:comment or skos:definition or dct:description or dc:description
      • Markdown is supported
    • historyNote - skos:historyNote
      • Markdown is supported
    • version URI - owl:versionIRI as a URI
    • version info - owl:versionInfo as a string
      • preferred namespace prefix - vann:preferredNamespacePrefix as a token
      • preferred namespace URI - vann:preferredNamespaceUri as a URI
    • agents: publishers, creators, contributors
      • see Agent Formatting below for details
      • see the pylode/examples/ directory for examples!
    • dates: created, modified, issued - dct:created etc., all as xsd:date or xsd:dateTime datatype properties
    • rights: license - dct:license as a URI & rights - dct:rights as a string
    • code respository - schema:codeRepository as a URI
    • source - dcterms:source as a URI or text
  • classes
    • per rdfs:Class or owl:Class
    • title - rdfs:label or skos:prefLabel or dct:title
    • description - rdf:comment or skos:definition or dct:description as a string or using Markdown or HTML
    • usage note - a skos:scopeNote string
    • example - a skos:example string containing RDF
    • super classes - by declaring a class to be owl:subClassOf something
    • sub classes - pyLODE will work these out itself
    • restrictions - by declaring a class to be owl:subClassOf of an owl:Restriction with any of the normal cardinality or property existence etc. restrictions
    • in domain/range of - pyLODE will auto-calculate these
  • properties
    • per owl:ObjectProperty, owl:DatatypeProperty or owl:AnnotationProperty
    • title - rdfs:label or skos:prefLabel or dct:title
    • description - rdf:comment or skos:definition or dct:description
    • usage note - a skos:scopeNote string
    • example - a skos:example string containing RDF
    • super properties - by declaring a class to be owl:subPropertyOf something
    • sub properties - pyLODE will work these out itself
    • equivalent properties - by declaring a class to be owl:equivalentProperty something
    • inverse of - by declaring a class to be owl:inverseOf something
    • domains - rdfs:domain or schema:domainIncludes
    • ranges - rdfs:range or schema:rangeIncludes
  • namespaces
    • pyLODE will honour any namespace prefixes you set and look up others in http://prefix.cc
    • it will either read your ontology's default/base URI in annotations or guess it using a number of methods
  • named individuals
    • coming!
Agent Formatting
  • Use either the DC versions of properties (dc:publisher etc.) or the DCT versions (dct:publisher etc.)
  • if using the DC form, the range should just be a string, e.g. dc:publisher "Geoscience Australia" . or dc:creator "Nicholas J. Car" .
  • if using the DCT form, the range should be a foaf:Agent or schema:Person Blank Node or URI (if details are given elsewhere in the ontology) with the following properties:
    • foaf:name/sdo:name
    • foaf:mbox/sdo:email
    • foaf:homepage/schema:identifier / sdo:url
  • Affiliation of people to organisation can be made if schem.aorg is used using sdo:member or sdo:affiliation (latter preferred)
    • e.g.
<ontology_x>
    dct:creator [
        sdo:name "Nicholas J. Car" ;
        sdo:identifier <http://orcid.org/0000-0002-8742-7730> ;
        schema:email <mailto:nicholas.car@surroundaustralia.com> ;
        sdo:affiliation [
            sdo:name "SURROUND Australia Pty Ltd" ;
            sdo:url <https://surroundaustralia.com> ;
        ] ;
    ] ;
Additions

To help pyLODE understand more annotations, see Suggestions below.

schema.org

When an HTML document is generated, i.e. not Markdown or other format, schema.org metadata is added to the HTML header in the form of properties of a DigitalDocument subject. The schema.org properties catered for are:

  • name
  • dateCreated
  • dateModified
  • description
  • license
  • copyrightYear
  • repository

Not yet handled, but will be soon, are:

  • publisher
  • creator
  • copyrightHolder

See SNIPPETS for detailed examples on what pyLODE knows about Agents Provenance etc.

Please suggest any more required schema.org annotations!

Styling

This tool generates HTML that is shamelessly similar to LODE's styling. That's because we want things to look familiar and LODE's outputs look great. The Markdown's pretty vanilla.

Also, pyLODE generates and uses only static HTML + CSS, no JavaScript, live loading Google Fonts etc. This is to ensure that all you need for nice display is within a couple of static, easy to use and maintain, files. Prevents documentation breaking over time.

Feel free to extend your styling with your own CSS.

Profiles

pyLODE can document ontologies and other taxonomies according to different profiles which are specifications. The basic, default, profile is pyLODE's OWL Profile, which means documentation is generated according to OWL properties and classes and the various annotation properties listed here in the What pyLODE understands section.

pyLODE can tell you what profiles it supports: just run ~$ pylode -lp ("list profiles") or, if calling from Python:

m = MakeDocco(input_data_file="examples/data-access-rights.ttl", profile="skos")
print(m.list_profiles())

Supported Profiles

Currently pyLODE supports its OWL profile, as described above, and a profile of SKOS. For full details of what the profiles include, see the profiles' definitions at:

Token URI
owlp https://w3id.org/profile/pylode-owl
skosp https://w3id.org/profile/pylode-skos

Transformation by Profile

You can, of course, document an OWL ontology using the owlp profile or a SKOS taxonomy using the skosp profile however, you can also document an OWL ontology using the skosp profile! This is because SKOS is conceptually a subset of OWL - whatever you can express in SKOS you can express in OWL.

pyLODE performs an OWL > SKOS transformation on OWL ontologies to produce a taxonomy document. The following conversions are made:

  • owl:Ontology > skos:ConceptScheme
    • and all the ontology metadata is used with the ConceptScheme
  • owl:Class > skos:Concept
    • and other class annotation properties used with Concept
  • owl:subClassOf > skos:broader

To see the full list of transformations, see the function _expand_graph_for_skos() in makedocco.py.

Examples of a small taxonomies documented using the skosp profile are:

An example of a large one:

An example of a skosp-documented OWL ontology and the corresponding owlp original is AGRIF:

Differences from LODE

  • command line access
    • you can use this on your own desktop so you don't need me to maintain a live service for use
  • use of more modern & simpler HTML
  • catering for a wider range of ontology options such as:
    • schema.org domainIncludes & rangeIncludes for properties
  • better Agent linking
    • foaf:Agent or schema:Person objects for creators, contributors & publishers
    • you can still use simple string peoperties like dc:contributor "Nicholas J. Car" too if you really must!
<ontology_x>
    dct:creator [
        sdo:name "Nicholas J. Car" ;
        sdo:identifier <http://orcid.org/0000-0002-8742-7730> ;
    ] ;
  • smarter CURIES
    • pyLODE caches and looks up well-known prefixes to make more/better CURIES
    • it tries to be smart with CURIE presentation by CURIE-ising all URIs it finds, rather than printing them
  • active development
    • this software is in use and will be improved for the foreseeable future so we will cater for more and more things
    • recent ontology documentation initiatives such as the MOD Ontology will be handled, if requested

License

This code is licensed using the GPL v3 licence. See the LICENSE file for the deed. Note Citation below though for attribution.

Citation

If you use pyLODE, please leave the pyLODE logo with a hyperlink back here in the top left of published HTML pages.

Collaboration

The maintainers welcome any collaboration.

If you have suggestions, please email the contacts below or leave Issues in this repository's Issue tracker.

But the very best thing you could do is create a Pull Request for us to action!

Contacts

Author:
Nicholas Car
Data System Architect
SURROUND Australia Pty Ltd

About

An OWL ontology documentation tool using Python and templating, based on LODE

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 92.0%
  • Python 7.7%
  • Other 0.3%