Package: pycali
CaLiA python package that defines a partial order over RDF licensesIntroductionCaLi is a lattice-based model for license orderings. This repository contains a python package that implements this model.Code uses the ODRL CaLi ordering ⟨A, LS, CL, C→⟩ such that:A is the set of 72 actions of ODRL (e.g., cc:Distribution, cc:ShareAlike, etc.),LS is the restrictiveness lattice of statusUndefined <= Permissions <= Duty <= Prohibition(actions can be either permitted, obliged, prohibited or not specified; in this LS, the undefined status is the least restrictive and the prohibited one the most restrictive),CLandC→are sets of constraints.CaLi online demonstratorIs an exemple of
license compliant search engine using CaLi model.InstallationInstallation in avirtualenvis recommended.Assuming you already havepython 3andpipinstalledpipinstallpycalithis will automatically installrdflibused to manipulate RDF.Getting startedThis section shows how to create a CaLi ordering with ease.Load a vocabularyA vocabulary object is a set of URIs (rdflib.term.URIRef) identifying actions (e.g., cc:Distribution, cc:ShareAlike, odrl:play, etc.)Create your own vocabulary inheriting from Vocabulary object or
use the implemented ODRL Vocabulary:frompycali.vocabularyimportODRLVocabularyodrl=ODRLVocabulary()# access the list of actionsodrl.actionsLoad a Restrictiveness lattice of status (LS)LS is a lattice defining the restrictiveness order between statuses of the
actions (permitted, obliged, prohibited).
Repository containsexamples of LSin RDF.
A Restrictiveness lattice of status is instantiated using a LS in RDF (rdflib.Graph):fromrdflibimportGraphfrompycali.restrictiveness_lattice_of_statusimportRestrictivenessLatticeOfStatusfrompycali.examples.restrictiveness_lattice_of_status.DL1importdl1_rdf# Load the LS in the examplesDL1=RestrictivenessLatticeOfStatus(Graph().parse(data=dl1_rdf,format='ttl'))Note that you can parse your own file usinglocation parameterLoad licensesA license i a set of statuses associated to actions of the vocabulary.
You can define your own license by creating a class inheriting from License object or
use the implemented ODRLLicense object.
Repository containsexamples of ODRL licenses dataset.Load a dataset of licensesODRLLicenses object is able to generate a set of ODRLlicense object from a rdf dataset of licenses
described usingODRL Vocabulary:fromrdflibimportGraphfrompycali.licenseimportODRLLicensesfrompycali.examples.licenses.ld_licenses_odrlimportld_licenses_rdfld_licenses_graph=Graph().parse(data=ld_licenses_rdf,format='ttl')licenses=ODRLLicenses(vocabulary=odrl,ls=DL1,rdf_graph=ld_licenses_graph)Note that you can parse your own file usinglocation parameterLoad a specific licenseIRI of the license can be used to retrieve a specific license:frompycali.licenseimportODRLLicensefromrdflibimportGraph,URIReffrompycali.vocabularyimportODRLfrompycali.ontologies.cali_ontoimportPermissionfrompycali.examples.licenses.ld_licenses_odrlimportld_licenses_rdfMIT=URIRef('http://cali.priloo.univ-nantes.fr/api/ld/licenses/65927752496731336041529177465061342556133156838395276')ld_licenses_graph=Graph().parse(data=ld_licenses_rdf,format='ttl')mit_license=ODRLLicense(vocabulary=odrl,ls=DL1,rdf_graph=ld_licenses_graph,iri=MIT)# Returns a list of actions in the specified stateactions=mit_license.get_action(vocabulary=odrl,status=Permission)# Returns the state of an actionstate=mit_license.get_status(vocabulary=odrl,action=ODRL['derive'])Define constraintsConstraints on license CLdefines if a license is valid or not. Compatibility constraints C→defines if a restrictiveness relation is a compatibility relation or not.
Repository containsexamples of license and compatibility constraints.Constraints on licensesA constraints on license is a a python function that takes 2 parameters,
a vocabulary and a license and returns a boolean:frompycali.ontologies.cali_ontoimportDutyfrompycali.vocabularyimportCC# A License should not obligates the commercial use of a resourcedefCommercialUse_Not_Duty(vocabulary,license):returnlicense.get_status(vocabulary,CC['CommericalUse'])!=DutyCompatibility constraintsA compatibility constraint is a a python function that takes 3 parameters, a vocabulary and 2 licenses
and returns a boolean:frompycali.ontologies.cali_ontoimportDutyfrompycali.vocabularyimportCC# A license that obligates to share alike should not be compatible with another licensedefShareAlike_Compatibility(vocabulary,license1,license2):returnlicense1.get_status(vocabulary,CC['ShareAlike'])!=DutyInstantiate constraintsConstraints are instantiated using LicenseConstraints and CompatibilityConstraints objects.
They are initiated with a list of constraints (signature of functions (constraints) are tested during initialization).frompycali.constraintsimportLicenseConstraints,CompatibilityConstraintsfrompycali.examples.license_constraintsimportCommercialUse_Not_Duty,ShareAlike_Not_Prohibition,CommercialUse_Include_Usefrompycali.examples.compatibility_constraintsimportShareAlike_Compatibility,DerivativeWorks_Compatibilitylicense_constraints=LicenseConstraints(odrl,[CommercialUse_Not_Duty,ShareAlike_Not_Prohibition,CommercialUse_Include_Use])compatibility_constraints=CompatibilityConstraints(ODRL,[ShareAlike_Compatibility,DerivativeWorks_Compatibility])# Checks if license respects all constraints on licenselicense_constraints.is_valid(license)# Checks if the restrictiveness relation between license1 and license2 repects all compatibility relationscompatibility_constraints.is_compatible(license1,license2)Instanciate a CaLi Ordering (Complete Example)CaLi ordering automatically defines compatibility relations between licenses.
It takes 4 parameters, the restrictiveness lattice of status (LS), the vocabulary, licenses constraints and compatibility constraints.
Then, every license added in the cali_ordering is ordered among other using compatibility relation.fromrdflibimportGraphfrompycali.cali_orderingimportCaliOrderingfrompycali.restrictiveness_lattice_of_statusimportRestrictivenessLatticeOfStatusfrompycali.licenseimportODRLLicensesfrompycali.vocabularyimportODRLVocabularyfrompycali.constraintsimportLicenseConstraints,CompatibilityConstraintsfrompycali.examples.license_constraintsimportCommercialUse_Not_Duty,ShareAlike_Not_Prohibition,CommercialUse_Include_Usefrompycali.examples.compatibility_constraintsimportShareAlike_Compatibility,DerivativeWorks_Compatibilityfrompycali.examples.restrictiveness_lattice_of_status.DL1importdl1_rdffrompycali.examples.licenses.ld_licenses_odrlimportld_licenses_rdf# instantiate a cali orderingodrl=ODRLVocabulary()DL1=RestrictivenessLatticeOfStatus(Graph().parse(data=dl1_rdf,format='ttl'))cali_ordering=CaliOrdering(ls=DL1,vocabulary=odrl,license_constraints=LicenseConstraints(odrl,[CommercialUse_Not_Duty,ShareAlike_Not_Prohibition,CommercialUse_Include_Use]),compatibility_constraints=CompatibilityConstraints(odrl,[ShareAlike_Compatibility,DerivativeWorks_Compatibility]))# add licenses to orderld_licenses_graph=Graph().parse(data=ld_licenses_rdf,format='ttl')licenses=ODRLLicenses(vocabulary=odrl,ls=DL1,rdf_graph=ld_licenses_graph)# use cali_ordering.add_license(license) to add one licensecali_ordering.add_licenses(licenses)Browse the CaLi Ordering# checks if license1 is compatible with license2boolean=cali_ordering.is_compatible(license1,license2)# checks if license2 is compatible with license1boolean=cali_ordering.is_compliant(license1,license2)# Returns all licenses that are compatible with license entered in parameterlicenses=cali_ordering.all_compatible(license)# Returns all licenses that are compliant with license entered in parameterlicenses=cali_ordering.all_compliant(license)# Returns an RDF graph containing license IRI's and compatibility relationsrdf_graph=cali_ordering.get_rdf_graph()# serialize rdf graph in turtleturtle_string=rdf_graph.serialize(format='turtle')