Skip to content

Commit

Permalink
3.0.0 PR
Browse files Browse the repository at this point in the history
3.0.0 - Merge pull request #191 from Capitains/dev
  • Loading branch information
PonteIneptique committed Oct 15, 2019
2 parents 60d325e + 3ff0f27 commit ecaef76
Show file tree
Hide file tree
Showing 110 changed files with 8,146 additions and 1,653 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.ipynb_checkpoints/
_test.py
*.pkl
# Compiled python modules.
*.pyc
Expand Down
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: python
python:
- "2.7"
- "3.4.5"
- "3.5"
- "3.6"

install:
- pip install -r requirements.txt
Expand All @@ -12,10 +11,6 @@ install:
script:
- coverage run --source=MyCapytain setup.py test

matrix:
allow_failures:
- python: "2.7"

after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then coveralls; fi

Expand Down
35 changes: 35 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
### 2019-07-01 3.0.0 @ponteineptique

- Added DTS !
- New Generic / Prototype CitationSetObject
- New .match(passageId) function
- New Generic / Prototype Citation Object
- New .children Property
- New .depth property (Not ported to CTS Citation object yet)
- New meaning of .__len__() magic method
- New .root and is_root properties to link back to the citation set (for match implementations)
- Guidelines / CTS Citation Object
- Implementation of the .match(passageId) method
- CitationSet.is_root -> CitationSet.is_root() # Keep in check with other practices
- BaseCitation.is_empty() now checks if the object has children
- BaseCitation.is_set() checks if objects have their properties set
- cts.Citation.isEmpty() old behaviour is now in .is_set() and has been reversed in meaning
- Old system would check if the CTS Citation was not set, old code such as
- if citation.isEmpty() should be moved to if citation.is_set()
- Guidelines / CTS Citation Object
- New Generic / Prototype Citation Object
- RetroPorted .start and .end Properties (see below for breaking change)
- New .is_range property

From MyCapytain.resources.prototypes.text to MyCapytain.resources.prototypes.cts.text :

- `CtsNode` now `PrototypeCtsNode`
- `CtsPassage` now `PrototypeCtsPassage`
- `CtsText` now `PrototypeCtsText`

Texts class:
- `self.__attr__` to `self._attr`

CTS Citation:
- `CTSCitation.isEmpty()` to `CTSCitation.is_empty()`

### 2019-04-10 2.0.10 @sonofmun

- Corrected JSON.Std export for metadata to include all objects for a predicate
Expand Down
2 changes: 1 addition & 1 deletion MyCapytain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"""

__version__ = "2.0.10"
__version__ = "3.0.0"
5 changes: 5 additions & 0 deletions MyCapytain/common/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from inspect import getmro


__all__ = [
"Exportable"
]


class Exportable(object):
""" Objects that supports Export
Expand Down
45 changes: 37 additions & 8 deletions MyCapytain/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from rdflib.namespace import SKOS


__all__ = [
"XPATH_NAMESPACES",
"RDF_NAMESPACES",
"Mimetypes",
"GRAPH_BINDINGS",
"bind_graph",
"get_graph",
"set_graph",
"RDFLIB_MAPPING"
]

#: List of XPath Namespaces used in guidelines
XPATH_NAMESPACES = {
"tei": "http://www.tei-c.org/ns/1.0",
Expand All @@ -26,9 +37,10 @@ class RDF_NAMESPACES:
:type CAPITAINS: Namespace
"""
CTS = Namespace("http://chs.harvard.edu/xmlns/cts/")
DTS = Namespace("http://w3id.org/dts-ontology/")
DTS = Namespace("https://w3id.org/dts/api#")
TEI = Namespace("http://www.tei-c.org/ns/1.0/")
CAPITAINS = Namespace("http://purl.org/capitains/ns/1.0#")
HYDRA = Namespace("https://www.w3.org/ns/hydra/core#")


class Mimetypes:
Expand Down Expand Up @@ -92,20 +104,37 @@ class PYTHON:
class MyCapytain:
""" MyCapytain Objects
:cvar ReadableText: MyCapytain.resources.prototypes.text.CitableText
:cvar ReadableText: MyCapytain.resources.prototypes.text.CtsText
"""
TextualElement = "Capitains/TextualElement"

PLAINTEXT = "text/plain"


GRAPH_BINDINGS = {
"": RDF_NAMESPACES.CTS,
"dts": RDF_NAMESPACES.DTS,
"tei": RDF_NAMESPACES.TEI,
"skos": SKOS,
"cpt": RDF_NAMESPACES.CAPITAINS
}


def bind_graph(graph=None):
""" Bind a graph with generic MyCapytain prefixes
:param graph: Graph (Optional)
:return: Bound graph
"""
if graph is None:
graph = Graph()
for prefix, ns in GRAPH_BINDINGS.items():
graph.bind(prefix, ns, True)
return graph


global __MYCAPYTAIN_TRIPLE_GRAPH__
__MYCAPYTAIN_TRIPLE_GRAPH__ = Graph()
__MYCAPYTAIN_TRIPLE_GRAPH__.bind("", RDF_NAMESPACES.CTS)
__MYCAPYTAIN_TRIPLE_GRAPH__.bind("dts", RDF_NAMESPACES.DTS)
__MYCAPYTAIN_TRIPLE_GRAPH__.bind("tei", RDF_NAMESPACES.TEI)
__MYCAPYTAIN_TRIPLE_GRAPH__.bind("skos", SKOS)
__MYCAPYTAIN_TRIPLE_GRAPH__.bind("cpt", RDF_NAMESPACES.CAPITAINS)
__MYCAPYTAIN_TRIPLE_GRAPH__ = bind_graph()


def set_graph(graph):
Expand Down
32 changes: 29 additions & 3 deletions MyCapytain/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
"""
from __future__ import unicode_literals
from MyCapytain.common.utils import make_xml_node
from MyCapytain.common.utils.xml import make_xml_node
from MyCapytain.common.constants import Mimetypes, get_graph
from MyCapytain.common.base import Exportable
from rdflib import BNode, Literal, Graph, URIRef, term
from typing import Union, Optional


__all__ = [
"Metadata"
]


class Metadata(Exportable):
Expand All @@ -24,7 +29,8 @@ class Metadata(Exportable):
:cvar DEFAULT_EXPORT: Default export (CTS XML Inventory)
:cvar STORE: RDF Store
"""
EXPORT_TO = [Mimetypes.JSON.Std, Mimetypes.XML.RDF, Mimetypes.XML.RDFa, Mimetypes.JSON.LD, Mimetypes.XML.CapiTainS.CTS]
EXPORT_TO = [Mimetypes.JSON.Std, Mimetypes.XML.RDF, Mimetypes.XML.RDFa, Mimetypes.JSON.LD,
Mimetypes.XML.CapiTainS.CTS]
DEFAULT_EXPORT = Mimetypes.JSON.Std

def __init__(self, node=None, *args, **kwargs):
Expand All @@ -46,6 +52,23 @@ def graph(self):
"""
return self.__graph__

def set(self, key: URIRef, value: Union[Literal, BNode, URIRef, str, int], lang: Optional[str]=None):
""" Set the VALUE for KEY predicate in the Metadata Graph
:param key: Predicate to be set (eg. DCT.creator)
:param value: Value to be stored (eg. "Cicero")
:param lang: [Optional] Language of the value (eg. "la")
"""
if not isinstance(value, Literal) and lang is not None:
value = Literal(value, lang=lang)
elif not isinstance(value, (BNode, URIRef)):
value, _type = term._castPythonToLiteral(value)
if _type is None:
value = Literal(value)
else:
value = Literal(value, datatype=_type)
self.graph.set((self.asNode(), key, value))

def add(self, key, value, lang=None):
""" Add a triple to the graph related to this node
Expand Down Expand Up @@ -85,6 +108,9 @@ def get_single(self, key, lang=None):
:param lang: Language of the triple if applicable
:rtype: Literal or BNode or URIRef
"""
if not isinstance(key, URIRef):
key = URIRef(key)

if lang is not None:
default = None
for o in self.graph.objects(self.asNode(), key):
Expand Down
11 changes: 11 additions & 0 deletions MyCapytain/common/reference/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""
.. module:: MyCapytain.common.reference
:synopsis: URN related objects
.. moduleauthor:: Thibault Clérice <[email protected]>
"""
from ._base import NodeId, BaseCitationSet, BaseReference, BaseReferenceSet
from ._capitains_cts import Citation, CtsReference, CtsReferenceSet, URN
from ._dts_1 import DtsCitation, DtsCitationSet, DtsReference, DtsReferenceSet
Loading

0 comments on commit ecaef76

Please sign in to comment.