Giter Site home page Giter Site logo

rdflib / pylode Goto Github PK

View Code? Open in Web Editor NEW
162.0 162.0 70.0 90.71 MB

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

License: BSD 3-Clause "New" or "Revised" License

Python 87.07% CSS 11.75% Shell 0.06% Dockerfile 0.04% JavaScript 1.08%
documentation jinja2 lode owl python rdf templates

pylode's Introduction

RDFLib

Build Status Documentation Status Coveralls branch

GitHub stars Downloads PyPI PyPI DOI

Contribute with Gitpod Gitter Matrix

RDFLib is a pure Python package for working with RDF. RDFLib contains most things you need to work with RDF, including:

  • parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, Trig and JSON-LD
  • a Graph interface which can be backed by any one of a number of Store implementations
  • store implementations for in-memory, persistent on disk (Berkeley DB) and remote SPARQL endpoints
  • a SPARQL 1.1 implementation - supporting SPARQL 1.1 Queries and Update statements
  • SPARQL function extension mechanisms

RDFlib Family of packages

The RDFlib community maintains many RDF-related Python code repositories with different purposes. For example:

  • rdflib - the RDFLib core
  • sparqlwrapper - a simple Python wrapper around a SPARQL service to remotely execute your queries
  • pyLODE - An OWL ontology documentation tool using Python and templating, based on LODE.
  • pyrdfa3 - RDFa 1.1 distiller/parser library: can extract RDFa 1.1/1.0 from (X)HTML, SVG, or XML in general.
  • pymicrodata - A module to extract RDF from an HTML5 page annotated with microdata.
  • pySHACL - A pure Python module which allows for the validation of RDF graphs against SHACL graphs.
  • OWL-RL - A simple implementation of the OWL2 RL Profile which expands the graph with all possible triples that OWL RL defines.

Please see the list for all packages/repositories here:

Help with maintenance of all of the RDFLib family of packages is always welcome and appreciated.

Versions & Releases

See https://rdflib.dev for the release overview.

Documentation

See https://rdflib.readthedocs.io for our documentation built from the code. Note that there are latest, stable 5.0.0 and 4.2.2 documentation versions, matching releases.

Installation

The stable release of RDFLib may be installed with Python's package management tool pip:

$ pip install rdflib

Some features of RDFLib require optional dependencies which may be installed using pip extras:

$ pip install rdflib[berkeleydb,networkx,html,lxml,orjson]

Alternatively manually download the package from the Python Package Index (PyPI) at https://pypi.python.org/pypi/rdflib

The current version of RDFLib is 7.0.0, see the CHANGELOG.md file for what's new in this release.

Installation of the current main branch (for developers)

With pip you can also install rdflib from the git repository with one of the following options:

$ pip install git+https://github.com/rdflib/rdflib@main

or

$ pip install -e git+https://github.com/rdflib/rdflib@main#egg=rdflib

or from your locally cloned repository you can install it with one of the following options:

$ poetry install  # installs into a poetry-managed venv

or

$ pip install -e .

Getting Started

RDFLib aims to be a pythonic RDF API. RDFLib's main data object is a Graph which is a Python collection of RDF Subject, Predicate, Object Triples:

To create graph and load it with RDF data from DBPedia then print the results:

from rdflib import Graph
g = Graph()
g.parse('http://dbpedia.org/resource/Semantic_Web')

for s, p, o in g:
    print(s, p, o)

The components of the triples are URIs (resources) or Literals (values).

URIs are grouped together by namespace, common namespaces are included in RDFLib:

from rdflib.namespace import DC, DCTERMS, DOAP, FOAF, SKOS, OWL, RDF, RDFS, VOID, XMLNS, XSD

You can use them like this:

from rdflib import Graph, URIRef, Literal
from rdflib.namespace import RDFS, XSD

g = Graph()
semweb = URIRef('http://dbpedia.org/resource/Semantic_Web')
type = g.value(semweb, RDFS.label)

Where RDFS is the RDFS namespace, XSD the XML Schema Datatypes namespace and g.value returns an object of the triple-pattern given (or an arbitrary one if multiple exist).

Or like this, adding a triple to a graph g:

g.add((
    URIRef("http://example.com/person/nick"),
    FOAF.givenName,
    Literal("Nick", datatype=XSD.string)
))

The triple (in n-triples notation) <http://example.com/person/nick> <http://xmlns.com/foaf/0.1/givenName> "Nick"^^<http://www.w3.org/2001/XMLSchema#string> . is created where the property FOAF.givenName is the URI <http://xmlns.com/foaf/0.1/givenName> and XSD.string is the URI <http://www.w3.org/2001/XMLSchema#string>.

You can bind namespaces to prefixes to shorten the URIs for RDF/XML, Turtle, N3, TriG, TriX & JSON-LD serializations:

g.bind("foaf", FOAF)
g.bind("xsd", XSD)

This will allow the n-triples triple above to be serialised like this:

print(g.serialize(format="turtle"))

With these results:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

<http://example.com/person/nick> foaf:givenName "Nick"^^xsd:string .

New Namespaces can also be defined:

dbpedia = Namespace('http://dbpedia.org/ontology/')

abstracts = list(x for x in g.objects(semweb, dbpedia['abstract']) if x.language=='en')

See also ./examples

Features

The library contains parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, JSON-LD, RDFa and Microdata.

The library presents a Graph interface which can be backed by any one of a number of Store implementations.

This core RDFLib package includes store implementations for in-memory storage and persistent storage on top of the Berkeley DB.

A SPARQL 1.1 implementation is included - supporting SPARQL 1.1 Queries and Update statements.

RDFLib is open source and is maintained on GitHub. RDFLib releases, current and previous are listed on PyPI

Multiple other projects are contained within the RDFlib "family", see https://github.com/RDFLib/.

Running tests

Running the tests on the host

Run the test suite with pytest.

poetry install
poetry run pytest

Running test coverage on the host with coverage report

Run the test suite and generate a HTML coverage report with pytest and pytest-cov.

poetry run pytest --cov

Viewing test coverage

Once tests have produced HTML output of the coverage report, view it by running:

poetry run pytest --cov --cov-report term --cov-report html
python -m http.server --directory=htmlcov

Contributing

RDFLib survives and grows via user contributions! Please read our contributing guide and developers guide to get started. Please consider lodging Pull Requests here:

To get a development environment consider using Gitpod or Google Cloud Shell.

Open in Gitpod Open in Cloud Shell

You can also raise issues here:

Support & Contacts

For general "how do I..." queries, please use https://stackoverflow.com and tag your question with rdflib. Existing questions:

If you want to contact the rdflib maintainers, please do so via:

pylode's People

Contributors

adamml avatar alejandrods avatar ananya2711 avatar bradh avatar bretelerjmw avatar carueda avatar charlesvardeman avatar dannykennedy avatar diggidydev avatar drahnreb avatar dwinston avatar edmondchuc avatar epoz avatar f3rr3t avatar gordiandziwis avatar hammar avatar hankruiger avatar hoijui avatar jaetldr avatar jyucsiro avatar keski avatar kwsamarasinghe avatar lewismc avatar nicholascar avatar stefa168 avatar tehaef avatar yum-yab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pylode's Issues

Allow export to PDF

Currently only export to HTML (+CSS) is supported, what about native support to PDF?

Respect case in fragments

Make FID generator use the same font case at class names so PIDs like http://linked.data.gov.au/def/geofabric#ContractedCatchment redirect to a working fragment, not the page top. Here for ContractedCatchment, currently only http://www.linked.data.gov.au/def/geofabric/#contractedcatchment works.

Run pyLODE-as-a-service

Hi @nicholascar hope all is going well.
We would like to host pyLODE and make it available *aaS to anyone who wants to use it. Specifically, we want to replace the LODE links in the ESIP COR (see screenshot below) with the new pyLODE which would be hosted on the same server.
What is the current status of running pyLODE as a Python service?
Screen Shot 2019-07-22 at 4 57 39 PM

Cater for ontology dependencies

  • owl:imports
  • prof:isProfileOf
    • if this property is found, we should infer owl:imports
  • alignments to other ontologies
  • normal sub-classing/sub-propertying
    • will infer owl:imports

Possible enhancement : generate JSON from ontology

Use case: Useful when trying to build a custom HTML/CSS to render. When wanting to use frameworks such as SemanticUI or Bootstrap, classes need to be added in HTML elements in order to apply style.

The generated JSON could be used in a HTML template library (Pug.js, React, etc.) in order to generate the desired view and style.

What do you think ? Useless there is currently a way to do this.

Create link to ORCID & use ORCID icon for people

When a person (a dcterms:creator, dcterms:contributor etc.) is referred to via a URI, currently the name, email address & affiliation of the person is show but not the URI! If the URI is an ORCID, a link to it should be made and using the ORCID icon, as scientific papers do.

Cater for links to repositories

<http://linked.data.gov.au/def/placenames> a owl:Ontology ;
       prov: wasGeneratedBy [
              a doap:Project ;
              doap:repository [
                     doap:browse <https://github.com/CSIRO-enviro-informatics/placenames-profile/> ;
                     doap:location <https://github.com/CSIRO-enviro-informatics/placenames-profile.git> ;
                     a doap:GitRepository
              ] ;
       ] ;
.

Refactor code that calls templates

Currently HTML and Markdown templates are able to be used and ReSt is hoped for too (Issue #35) but the functions that call templates are duplicated (e.g. _make_metadata_html)( & _make_metadata_md()) and need to be refactored.

Generated Markdown is not rendered correctly

Following on #33, after fixing some of these by manually copying files from the repo itself, I was able to build the markdown documentation. Unfortunately, the generated markdown tables didn't appear to render correctly in either the Sphinx + Recommonmark render nor the GitLab Markdown renderer. I think this is an issue with some markdown parsers disabling markdown parsing once HTML is detected, thus intermingled HTML and MD isn't accepted.

Lastly, I couldn't get a large majority of anchor links to work. This is observable even on GitHub's MD renderer: the Delegated link in the Classes section links to https://github.com/RDFLib/pyLODE/blob/master/src/pylode/examples/reg.md#Delegated, which does not anchor correctly.

Support for reStructuredText

Because rdflib and pyLODE are Python projects, and Python projects tend to lean towards using rST as the standard for the documentation, it would be great to have an rST output format in addition to HTML / MD.

Cannot build Markdown documentation after pip install

I installed pylode via pip (technically via poetry, but that just uses pip), but I'm unable to build documentation successfully. I debugged a little and noted a few issues, but don't have an abundance of time to fix them and submit a PR myself:

Happy to help test further to help you reproduce, and hopefully fix, these issues.

Hyperlinks in generated Markdown don't work

This issue concerns the generated Markdown format.

For example, in the table of contents section, clicking on "Classes" won't jump to the right section. This is because there isn't a <section id="classes"> in Markdown.

Any solutions for this ?

Concatenate multile descriptions

e.g. Registry Ontology:

	dct:description <https://github.com/ukgovld/registry-core/wiki/images/registry-diagram.png> , "Core ontology for linked data registry services. Based on ISO19135 but heavily modified to suit Linked Data representations and applications."@en ;

Render HTML fragments correctly

Many RDF properties that typically take string literals (^^xsd:string) may also have HTML fragments (^^rdf:HTML) which allows for formatted documentation. pyLODE currently re-writes these into pre-formatted code. This content should be passed through as HTML.

Create tests for complex restrictions

Tests could be made with tiny input ontologies & expected HTML. A couple of tests for complex restrictions (intersectionOf classes for domain etc.) would be good to implement before re-writing much code for improvements

Handle documentation profiles

Allow the user to set different 'annotation profiles' which tell the system which properties it may handle, e.g. MOD, RDFS-only etc. Accessible via another command line arg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.