Skip to content

ProjetPP/PPP-datamodel-Python

Repository files navigation

PPP DataModel

Build Status Code Coverage Scrutinizer Code Quality PyPi version

How to install

With a recent version of pip:

pip3 install git+https://github.com/ProjetPP/PPP-datamodel-Python.git

With an older one:

git clone https://github.com/ProjetPP/PPP-datamodel-Python.git
cd PPP-datamodel-Python
python3 setup.py install

Use the --user option if you want to install it only for the current user.

How to use

You can use any of the classes in the ppp_datamodel package: Triple, Resource, and Missing. They all have a nice constructor, getters for their attributes, and serialization methods, etc.

An example:

>>> import ppp_datamodel
>>> my_triple = ppp_datamodel.Triple(subject=ppp_datamodel.Resource(value='George Washington'), predicate=ppp_datamodel.Resource(value='birth date'), object=ppp_datamodel.Missing())
>>> print(my_triple.as_json())
{"type": "triple", "predicate": {"type": "resource", "value": "birth date"}, "subject": {"type": "resource", "value": "George Washington"}, "object": {"type": "missing"}}
>>> my_triple.predicate
<PPP node "resource" {'value': 'birth date'}>

You can also deserialize them:

>>> ppp_datamodel.AbstractNode.from_json('{"type": "resource", "value": "George Washington"}')
<PPP node "resource" {'value': 'George Washington'}>
>>> ppp_datamodel.AbstractNode.from_json('{"type": "resource", "value": "George Washington"}') == ppp_datamodel.Resource(value='George Washington')
True

For a list of their accepted attributes, see the PPP data model specification