Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: ReadTheDocs Integration #17

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Docs

on:
pull_request:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: Debug with tmate
required: false
default: false

jobs:
docs:
runs-on: ubuntu-latest

name: Docs

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Fetch all tags and branches
run: git fetch --prune --unshallow

- name: Create ArangoDB Docker container
run: docker create --name adb -p 8529:8529 -e ARANGO_ROOT_PASSWORD= arangodb/arangodb

- name: Start ArangoDB Docker container
run: docker start adb

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Debug with tmate
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}

- name: Install dependencies
run: pip install .[dev]

- name: Run Sphinx doctest
run: python -m sphinx -b doctest docs docs/_build

- name: Generate Sphinx HTML
run: python -m sphinx -b html -W docs docs/_build
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
python-version: "3.10"

- name: Install release packages
run: pip install setuptools wheel twine setuptools-scm[toml]
run: pip install build twine

- name: Build distribution
run: python setup.py sdist bdist_wheel
run: python -m build

- name: Publish to Test PyPi
env:
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ adbrdf = ArangoRDF(db)
g = Graph()
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")

# RDF to ArangoDB
###################################################################################
###################
# RDF to ArangoDB #
###################

# 1.1: RDF-Topology Preserving Transformation (RPT)
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, overwrite_graph=True)
Expand All @@ -77,8 +78,9 @@ adb_mapping = adbrdf.build_adb_mapping_for_pgt(g)
print(adb_mapping.serialize())
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, adb_mapping, contextualize_graph=True, overwrite_graph=True)

# ArangoDB to RDF
###################################################################################
###################
# ArangoDB to RDF #
###################

# Start from scratch!
g = Graph()
Expand Down
41 changes: 19 additions & 22 deletions arango_rdf/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@


class ArangoRDFController(AbstractArangoRDFController):
"""ArangoDB-RDF controller.

You can derive your own custom ArangoRDFController.
"""
"""ArangoDB-RDF controller. You can derive your own custom ArangoRDFController."""

def __init__(self) -> None:
self.db: StandardDatabase
Expand Down Expand Up @@ -42,28 +39,28 @@ def identify_best_class(

The current identification process goes as follows:
1) If an RDF Resource only has one `rdf:type` statement
(either by explicit definition or by domain/range inference),
then the local name of the single RDFS Class is used as the ArangoDB
Document Collection name. For example,
<http://example.com/Bob> <rdf:type> <http://example.com/Person>
would place the JSON Document for <http://example.com/Bob>
under the ArangoDB "Person" Document Collection.
(either by explicit definition or by domain/range inference),
then the local name of the single RDFS Class is used as the ArangoDB
Document Collection name. For example,
<http://example.com/Bob> <rdf:type> <http://example.com/Person>
would place the JSON Document for <http://example.com/Bob>
under the ArangoDB "Person" Document Collection.

2) If an RDF Resource has multiple `rdf:type` statements
(either by explicit definition or by domain/range inference),
with some (or all) of the RDFS Classes of those statements
belonging in an `rdfs:subClassOf` Taxonomy, then the
local name of the "most specific" Class within the Taxonomy is
used (i.e the Class with the biggest depth). If there is a
tie between 2+ Classes, then the URIs are alphabetically
sorted & the first one is picked. Relies on **subclass_tree**.
(either by explicit definition or by domain/range inference),
with some (or all) of the RDFS Classes of those statements
belonging in an `rdfs:subClassOf` Taxonomy, then the
local name of the "most specific" Class within the Taxonomy is
used (i.e the Class with the biggest depth). If there is a
tie between 2+ Classes, then the URIs are alphabetically
sorted & the first one is picked. Relies on **subclass_tree**.

3) If an RDF Resource has multiple `rdf:type` statements, with
none of the RDFS Classes of those statements belonging in an
`rdfs:subClassOf` Taxonomy, then the URIs are
alphabetically sorted & the first one is picked. The local
name of the selected URI will be designated as the Document
Collection for **rdf_resource**.
none of the RDFS Classes of those statements belonging in an
`rdfs:subClassOf` Taxonomy, then the URIs are
alphabetically sorted & the first one is picked. The local
name of the selected URI will be designated as the Document
Collection for **rdf_resource**.

:param rdf_resource: The RDF Resource in question.
:type rdf_resource: URIRef | BNode
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Binary file added docs/_static/adb_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/rdf_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os
import sys

sys.path.insert(0, os.path.abspath('../arango_rdf'))

project = 'ArangoRDF'
copyright = '2023, Anthony Mahanna'
author = 'Anthony Mahanna'
release = '0.1.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx_rtd_theme",
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.viewcode",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']

autodoc_member_order = "bysource"


doctest_global_setup = """
from arango import ArangoClient
from arango_rdf import ArangoRDF
from rdflib import Graph

# Initialize the ArangoDB client db.
db = ArangoClient().db('_system', username='root', password='passwd')

# Initialize the ArangoRDF client.
adbrdf = ArangoRDF(db)

# Create a new RDF graph.
rdf_graph = Graph()
rdf_graph.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl", format="ttl")

# RDF to ArangoDB
adb_graph_rpt = adbrdf.rdf_to_arangodb_by_rpt("BeatlesRPT", rdf_graph, overwrite_graph=True)
adb_graph_pgt = adbrdf.rdf_to_arangodb_by_pgt("BeatlesPGT", rdf_graph, overwrite_graph=True)

# ArangoDB to RDF
rdf_graph_2, adb_mapping = adbrdf.arangodb_graph_to_rdf("Beatles", Graph())
"""
34 changes: 34 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.. image:: /static/adb_logo.png
.. image:: /static/rdf_logo.png

|

ArangoRDF
-------------

Welcome to the documentation for **ArangoRDF**, a Python adapter for ArangoDB_ & RDF_.

Requirements
=============

- ArangoDB version 3.9+
- Python version 3.8+

Installation
============

.. code-block:: bash

~$ pip install arango-rdf --upgrade

Contents
========

.. toctree::
:maxdepth: 1

overview
specs

.. _ArangoDB: https://www.arangodb.com
.. _RDF: https://www.w3.org/RDF/
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
27 changes: 27 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Getting Started
---------------

Here is an example showing how the **arango-rdf** package can be used:

.. testcode::

from rdflib import Graph
from arango import ArangoClient
from arango_rdf import ArangoRDF

# Initialize the ArangoDB db client.
db = ArangoClient(hosts='http://localhost:8529).db('_system', username='root', password='passwd')

# Initialize ArangoRDF
arangordf = ArangoRDF(db)

# Create a new RDF graph.
rdf_graph = Graph()
rdf_graph.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")

# RDF to ArangoDB
adb_graph_rpt = adbrdf.rdf_to_arangodb_by_rpt("BeatlesRPT", rdf_graph, overwrite_graph=True)
adb_graph_pgt = adbrdf.rdf_to_arangodb_by_pgt("BeatlesPGT", rdf_graph, overwrite_graph=True)

# ArangoDB to RDF
rdf_graph_2, adb_mapping = adbrdf.arangodb_graph_to_rdf("Beatles", Graph())
21 changes: 21 additions & 0 deletions docs/specs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
API Specification
-----------------

This page contains the specification for all classes and methods available in
arango-rdf.

.. _ArangoRDF:

ArangoRDF
=========

.. autoclass:: arango_rdf.main.ArangoRDF
:members:

.. _ArangoRDFController:

ArangoRDFController
===================

.. autoclass:: arango_rdf.controller.ArangoRDFController
:members:
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Documentation :: Sphinx",
"Topic :: Utilities",
"Typing :: Typed",
]
Expand All @@ -50,6 +51,8 @@ dev = [
"pytest-cov>=2.0.0",
"coveralls>=3.3.1",
"types-setuptools",
"sphinx",
"sphinx_rtd_theme",
]

[project.urls]
Expand Down
Loading