一个用于处理建筑物砖块本体的库(brickschema.org网站)

brickschema的Python项目详细描述


积木本体Python包

Build StatusDocumentation Status

文档可从readthedocs获得

安装

brickschema包需要Python>;=3.6。它可以与pip一起安装:

pip install brickschema

brickschema包提供了几个用于推理的安装配置选项。 默认的捆绑的OWLRLreasoner提供了正确的结果,但是由于其野蛮的实现,在大型或复杂的本体论(我们观察到几分钟到几小时)上表现出较差的性能。在

Allegro reasoner具有更好的性能,并且实现了足够多的owrl概要文件,因此非常有用。我们在Docker容器中执行Allegrograph,它需要docker包。要安装Allegrograph reasoner的支持,请使用

^{pr2}$

reasonable Reasoner提供了比Allegro reasoner更好的性能,但目前只为Linux平台打包。(注意:这里没有基本限制,只是由于交叉编译.so)而导致的一些打包复杂性。为合理推理机安装支架,使用

pip install brickschema[reasonable]

特点

owrl推断

brickschema使在图上使用owrl推理更容易。软件包将自动为您的系统使用最快的可用推理实现:

  • reasonable(最快,目前仅限Linux):pip install brickschema[reasonable]
  • Allegro(下一个最快的,需要Docker):pip install brickschema[allegro]
  • owrl(默认,本机Python实现):pip install brickschema

要使用OWL推理,请导入OWLRLInferenceSession类(这将自动选择最快的推理器;请查看inference module documentation以了解如何使用特定的推理器)。创建一个brickschema.Graph,其中加载了本体规则和实例,并将reasoner的会话应用于它:

frombrickschema.graphimportGraphfrombrickschema.namespacesimportBRICKfrombrickschema.inferenceimportOWLRLInferenceSessiong=Graph(load_brick=True)g.load_file("test.ttl")sess=OWLRLInferenceSession()inferred_graph=sess.expand(g)print(f"Inferred graph has {len(inferred_graph)} triples")

干草堆推断

需要Haystack模型的JSON导出。 首先,将Haystack模型导出为JSON;我们使用的是公共引用模型carytown.json。 然后您可以按如下方式使用此软件包:

importjsonfrombrickschema.inferenceimportHaystackInferenceSessionhaysess=HaystackInferenceSession("http://project-haystack.org/carytown#")model=json.load(open('carytown.json'))model=haysess.infer_model(model)print(len(model))points=model.query("""SELECT ?point ?type WHERE {    ?point rdf:type/rdfs:subClassOf* brick:Point .    ?point rdf:type ?type}""")print(points)

SQL
frombrickschema.graphimportGraphfrombrickschema.namespacesimportBRICKfrombrickschema.ormimportSQLORM,Location,Equipment,Point# loads in default Brick ontologyg=Graph(load_brick=True)# load in our modelg.load_file("test.ttl")# put the ORM in a SQLite database file called "brick_test.db"orm=SQLORM(g,connection_string="sqlite:///brick_test.db")# get the points for each equipmentforequipinorm.session.query(Equipment):print(f"Equpiment {equip.name} is a {equip.type} with {len(equip.points)} points")forpointinequip.points:print(f"    Point {point.name} has type {point.type}")# filter for a given name or typehvac_zones=orm.session.query(Location)\
                        .filter(Location.type==BRICK.HVAC_Zone)\
                        .all()print(f"Model has {len(hvac_zones)} HVAC Zones")

用形状约束语言验证

该模块利用pySHACL包来验证构建本体 对于Brick模式,它的默认约束(形状)和用户提供的形状。在

frombrickschema.validateimportValidatorfromrdflibimportGraphdataG=Graph()dataG.parse('myBuilding.ttl',format='turtle')shapeG=Graph()shapeG.parse('extraShapes.ttl',format='turtle')v=Validator()result=v.validate(dataG,shacl_graphs=[shapeG])print(result.textOutput)
  • result.conforms:如果为真,结果.textOutput是Validation Report\nConforms: True。在
  • result.textOutput:文本输出pyshacl.validate(),附加额外信息,为每个违规行为提供违规者提示,以帮助用户在数据图中定位特定的违规行为。有关示例输出,请参见readthedocs。在
  • result.violationGraphs:冲突列表,每一个都以图形的形式显示。在

模块提供一个命令 brick_validate类似于pyshacl命令。以下命令在功能上 相当于上面的代码。在

brick_validate myBuilding.ttl -s extraShapes.ttl

发展

Brick需要Python>;=3.6。我们使用pre-commit hooks在提交时自动运行代码格式化程序和样式检查程序。在

使用Poetry管理打包和依赖关系。安装诗歌后,请使用以下内容安装依赖项:

# -D flag installs development dependencies
poetry install -D

使用以下命令进入开发环境(这类似于激活虚拟环境。在

poetry shell

在第一次安装时,请确保安装预提交钩子以运行格式化和linting工具:

# from within the environment; e.g. after running 'poetry shell'
pre-commit install

运行测试以确保生成未损坏

# from within the environment; e.g. after running 'poetry shell'
make test

文件

文档是用重组文本编写的。请确保将您的软件包要求添加到docs/requirements.txt

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

推荐PyPI第三方库


热门话题
java后台通知:安卓   java Resultset未返回具有特殊字符/,   等待加载主帧时的java JxBrowser TimeoutException(invokeAndWaitFinishLoadingMainFrame)   java EclipseLink级联持久化异常   JavaMail 1.5.0漏洞还是gmail奇怪的问题?   java循环和IFT语句的装箱   java API不起作用,progressBar一直在旋转   java httpget在“执行”之后不工作   用户界面Java basic GUI程序错误   捕获异常后java代码失败   noclassdeffounderror在一个简单的网络程序中。我正在使用EclipseIDE运行java程序   安卓:java。朗,反思一下。InvocationTargetException有什么建议吗?   java Spring引导未创建数据源   ID为的java RichFaces 4.5 commandLink执行表单   java Struts2:JSP页面无法从数据库获取值   java缓存修改通知?   在java/spring中审计方法变量的最佳方法是什么?