定义rdf许可证部分顺序的python包

pycali的Python项目详细描述


校准

Build StatusPyPI version

定义RDF许可证部分顺序的Python包

简介

cali是一个基于格的许可订购模型。这个存储库包含一个实现这个模型的python包。

代码使用odrl cali顺序a,ls,cl,c这样:

  • a是odrl的72个动作集(例如cc:distribution、cc:sharelike等),
  • ls是状态Undefined <= Permissions <= Duty <= Prohibition的限制性格(操作可以是允许的、强制的、禁止的或未指定的;在此ls中,未定义的状态是限制性最小的,禁止的状态是限制性最强的),
  • cl
  • c是一组约束。

CaLi online demonstrator是 使用cali模型的符合许可证的搜索引擎。

安装

建议在virtualenv中安装。

假设您已经安装了python 3pip

pip install pycali

这将自动安装用于操作rdf的rdflib

入门

本节演示如何轻松创建cali顺序。

加载词汇

词汇表对象是一组标识操作(例如cc:distribution、cc:sharelike、odrl:play等)的uri(rdflib.term.URIRef)。

创建自己的词汇表继承自词汇表对象或 使用已实现的odrl词汇表:

frompycali.vocabularyimportODRLVocabularyodrl=ODRLVocabulary()# access the list of actionsodrl.actions

加载状态的限制性格(ls)

ls是一个定义 行动(允许、义务、禁止)。 存储库包含rdf中的examples of LS。 使用rdf中的ls(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'))

注意,您可以使用location parameter解析自己的文件

加载许可证

许可证一组与词汇表的操作相关联的状态。 可以通过创建继承自许可对象的类或 使用实现的odrllicense对象。 存储库包含examples of ODRL licenses dataset

加载许可证数据集

odrllicenses对象能够从许可证的rdf数据集生成一组odrllicense对象 使用ODRL 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)

注意,您可以使用location parameter解析自己的文件

加载特定许可证

许可证的IRI可用于检索特定的许可证:

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'])

定义约束

对许可证cl的约束定义了许可证是否有效。兼容性约束c 定义限制性关系是否为兼容性关系。 存储库包含examples of license and compatibility constraints

许可证限制

许可证约束是一个python函数,它接受两个参数, 词汇表和许可证并返回布尔值:

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'])!=Duty

兼容性约束

兼容性约束是一个python函数,它包含3个参数、一个词汇表和2个许可证 并返回布尔值:

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'])!=Duty

实例化约束

使用LicenseConstraints和CompatibilityConstraints对象实例化约束。 它们由一个约束列表启动(在初始化过程中测试函数(约束)的签名)。

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)

实例化cali排序(完整示例)

cali排序自动定义许可证之间的兼容性关系。 它包含4个参数:状态的限制性格(ls)、词汇表、许可证约束和兼容性约束。 然后,在cali_顺序中添加的每个许可证在其他许可证中使用兼容性关系进行排序。

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)

浏览cali排序

# 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')

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何与两个平台(OS X和Win)共享我的工作空间?   java QuickBooks在线编程访问   JavaJSP:useBean,使用先前创建的会话范围bean   在java中从多个类swing更改setText   带有x x x输入的java JFrame setsize不是正方形   java完成空活动   java在Redhat MRG/Apache QPID中创建一个只浏览的队列   Java中的多线程,将对HashMap的引用更改为并发读取安全吗   java在使用数组时崩溃。填满   java如何从文本文件中排序并行数组   java JsonIdentityInfo用于hibernate映射   Java/Android检索和保存值   java如何通过wifi配置连接到wifi   java提高竞争性编程问题的性能   java崩溃onLocationChanged()Android