将 SiDiF 翻译成 Weaviate [英] Translating SiDiF to Weaviate

查看:67
本文介绍了将 SiDiF 翻译成 Weaviate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这也可以在 http://diagrams.bitplan.com/render/png/0x2637ba5e.png.

是否可以将 SiDIF 文件的域核心转换为一般的 Weaviate Schema 样式?

CrSchema

## 上下文:CrSchema#CrSchema 是一个上下文CrSchema"是它的名字http://cr.bitplan.com"是它的主人《2020-07-22》是因为它## 事件#事件是一个话题事件"是它的名字事件"是它的复数名称在特定时间和地点召开的研究人员会议"是它的文档在特定时间和地点(虚拟或物理)举行的研究人员会议,并具有特定的主题重点,以展示、听取和讨论研究成果";是它的维基文档文件:EventLogo-64px.png"是它的图标/images/cr/e/e0/EventLogo-64px.png"是它的 iconUrl财产"是它的 defaultstoremodeCrSchema"是它的上下文Event_acronym 添加到它# 事件的属性# 属性缩写Event_acronym isA 属性缩写"是它的名字缩写"是它的标签文本"是它的类型1 是它的索引1 是它的 sortPostrue 是它的主键false 是强制性的50是它的大小false 是可以上传的学术活动的官方缩写,如果有的话."是它的文档false 是它的链接事件"是它的主题# 属性 wikidataidEvent_wikidataid isA 属性维基数据"是它的名字维基数据"是它的标签文本"是它的类型2 是它的索引false 是它的主键false 是强制性的50是它的大小false 是可以上传的事件的维基数据"是它的文档false 是它的链接事件"是它的主题## 城市#城市是一个话题《城市》是它的名字《城市》是它的复数名称大型永久性人类住区"是它的文档[https://www.wikidata.org/wiki/Q515 大型永久人类住区]"是它的维基文档财产"是它的 defaultstoremode文件:CityIcon-64px.png"是它的图标/images/cr/9/9e/CityIcon-64px.png"是它的 iconUrlCrSchema"是它的上下文City_name 添加到它City_wikidataid 添加到它# 城市的属性# 属性名称City_name 是一个属性姓名"是它的名字姓名"是它的标签文本"是它的类型1 是它的索引1 是它的 sortPostrue 是它的主键true 是强制性的50是它的大小false 是可以上传的《城市名称》是它的文档false 是它的链接《城市》是它的主题# 属性 wikidataidCity_wikidataid 是一个属性维基数据"是它的名字维基数据"是它的标签文本"是它的类型2 是它的索引false 是它的主键false 是强制性的50是它的大小false 是可以上传的城市的维基数据"是它的文档false 是它的链接《城市》是它的主题## 国家#国家是一个话题国家"是它的名字国家"是它的复数名称地理上的独特区域;一个广义的术语,可以包括与不同政治特征相关的政治分歧或地区"是它的文档"[https://www.wikidata.org/wiki/Q6256 地理上的不同区域;一个广义的术语,可以包括与不同政治特征相关的政治分歧或地区]"是它的维基文档文件:CountryIcon-64px.png"是它的图标/images/cr/4/4c/CountryIcon-64px.png"是它的 iconUrl财产"是它的 defaultstoremodeCrSchema"是它的上下文Country_name 添加到它Country_wikidataid 添加到它# 国家的属性# 属性名称Country_name 是一个属性姓名"是它的名字姓名"是它的标签文本"是它的类型1 是它的索引1 是它的 sortPostrue 是它的主键true 是强制性的50是它的大小false 是可以上传的《国名》是它的文档false 是它的链接国家"是它的主题# 属性 wikidataidCountry_wikidataid 是一个属性维基数据"是它的名字维基数据"是它的标签文本"是它的类型2 是它的索引false 是它的主键false 是强制性的50是它的大小false 是可以上传的国家的维基数据"是它的文档false 是它的链接国家"是它的主题## 状态#状态是一个话题状态"是它的名字国家"是它的复数名称构成联邦联盟一部分的领土和宪法社区"是它的文档[https://www.wikidata.org/wiki/Q107390 构成联邦联盟一部分的领土和宪法社区]"是它的维基文档文件:StateIcon-64px.png"是它的图标/images/cr/f/fe/StateIcon-64px.png"是它的 iconUrl财产"是它的 defaultstoremodeCrSchema"是它的上下文State_name 添加到它State_wikidataid 添加到它# 状态的属性# 属性名称State_name 是一个属性姓名"是它的名字姓名"是它的标签文本"是它的类型1 是它的索引1 是它的 sortPostrue 是它的主键true 是强制性的50是它的大小false 是可以上传的国家名称"是它的文档false 是它的链接状态"是它的主题# 属性 wikidataidState_wikidataid 是一个属性维基数据"是它的名字维基数据"是它的标签文本"是它的类型2 是它的索引false 是它的主键false 是强制性的50是它的大小false 是可以上传的国家的维基数据"是它的文档false 是它的链接状态"是它的主题## 主题链接## 事件 n : 1 个城市Event_in_City 是一个话题链接eventInCity"是它的名字城市"是它的源角色false 是 sourceMultiple it《城市》是它的来源事件"是它的目标角色true 是目标的倍数事件"是它的目标# 事件 n : 1 状态Event_in_State 是一个 TopicLink事件状态"是它的名字状态"是它的源角色false 是 sourceMultiple it状态"是它的来源事件"是它的目标角色true 是目标的倍数事件"是它的目标# 事件 n : 1 个国家Event_in_Country 是一个话题链接eventInCountry"是它的名字国家"是它的源角色false 是 sourceMultiple it国家"是它的来源事件"是它的目标角色true 是目标的倍数事件"是它的目标

解决方案

您首先需要定义一个引用属性.它们具有作为 dataType 的引用类.例如.用于引用城市:

<代码>{名称":inCity",描述":城市参考",数据类型":[《城市》],基数":许多"}

然后您可以通过信标添加引用:

curl -X POST "http://localhost:8080/v1/things/c60505f9-8271-4eec-b998-81d016648d85/references/hasEvent"-H '内容类型:应用程序/json' -d '{信标":weaviate://localhost/things/2a8d56b7-2dd5-4e68-aa40-53c9196aecde"}'

在这个例子中,带有 uuid c60505f9-8271-4eec-b998-81d016648d85 的对象的属性 hasEvent 正在引用带有 uuid 2a8d56b7-2dd5 的对象-4e68-aa40-53c9196aecde.

查看参考文档 了解更多信息.

这是一个使用 python 客户端的最小示例:

#pip install weaviate-client==0.4.0进口编织导入时间架构 = {东西":{类型":事物",类":[{类":事件",描述":事件",属性":[{名称":缩写",描述":缩写",数据类型":[文本"]},{名称":inCity",描述":城市参考",数据类型":[《城市》],基数":许多"}]},{类":城市",描述":城市",属性":[{名称":名称",描述":名称",数据类型":[文本"]},{名称":hasEvent",描述":事件引用",数据类型":[事件"],基数":许多"}]}]}}client = weaviate.Client("http://localhost:8080")如果不是 client.contains_schema():client.create_schema(schema)事件 = {首字母缩略词":示例"}client.create(事件,事件",2a8d56b7-2dd5-4e68-aa40-53c9196aecde")城市 = {名称":阿姆斯特丹"}client.create(city, "City", "c60505f9-8271-4eec-b998-81d016648d85")时间.sleep(2.0)client.add_reference("c60505f9-8271-4eec-b998-81d016648d85", "hasEvent", "2a8d56b7-2dd5-4e68-aa40-53c9196aecde")

<块引用>

是否可以将 SiDIF 文件的域核心转换为一般的 Weaviate Schema 样式?

这取决于您的用例和您想要投入的工作量.

  • 如果您只对语义功能感兴趣:在这种情况下,您可能根本不需要构建复杂的模式.创建 4 个类 subjectpredicateobjecttriple 并像这样加载所有内容可能就足够了.
  • 您想加载一组特定的定义:您必须将感兴趣的词汇表复制为编织模式.Weaviate 不支持类继承,因此您必须通过引用以某种方式定义这些.如果你有一个清晰定义的词汇,这应该是相对简单的.
  • 您想动态加载各种词汇表:我不完全确定这是否容易实现.我假设您必须构建一个非常精细的解析器.

希望这有助于欢呼.

I have several ontology descriptions in Simple Data Interchange Format and would like to transform or import these to use them with Weaviate.

An example can be found at:

http://cr.bitplan.com/index.php/CrSchema#sidif (see source code below).

I was able to create classes and properties manually but i am not sure how to do relations in Weaviates Schema description style. E.g. if i have a class "Event" and want to link the City for it how do i do this if at all?

You'll find more details on the schema at http://cr.bitplan.com/index.php/Concept:Event and there is also an UML diagram for it: which is also available at http://diagrams.bitplan.com/render/png/0x2637ba5e.png.

Would it be possible to convert the domain core of SiDIF files to Weaviate Schema style in general?

CrSchema

#
# Context:CrSchema
#
CrSchema isA Context
"CrSchema" is name of it
"http://cr.bitplan.com" is master of it
"2020-07-22" is since of it
#
# Event
#
Event isA Topic
"Event" is name of it
"Events" is pluralName of it
"a meeting of researchers at a specific time and place" is documentation of it
"a meeting of researchers at a specific time and place (virtual or physical) and with a specific thematic focus to present, hear and discuss research outputs " is wikiDocumentation of it
"File:EventLogo-64px.png" is icon of it
"/images/cr/e/e0/EventLogo-64px.png" is iconUrl of it
"property" is defaultstoremode of it
"CrSchema" is context of it
Event_acronym addsTo it
# properties of Event
# property acronym
Event_acronym isA Property
"acronym" is name of it
"acronym" is label of it
"text" is type of it
1 is index of it
1 is sortPos of it
true is primaryKey of it
false is mandatory of it
50 is size of it
false is uploadable of it
"The official acronym of the academic event, if it has one. " is documentation of it
false is isLink of it
"Event" is topic of it
# property wikidataid
Event_wikidataid isA Property
"wikidataid" is name of it
"wikidataid" is label of it
"text" is type of it
2 is index of it
false is primaryKey of it
false is mandatory of it
50 is size of it
false is uploadable of it
"The wikidataid of the event" is documentation of it
false is isLink of it
"Event" is topic of it
#
# City
#
City isA Topic
"City" is name of it
"Cities" is pluralName of it
"large permanent human settlement" is documentation of it
"[https://www.wikidata.org/wiki/Q515 large permanent human settlement]" is wikiDocumentation of it
"property" is defaultstoremode of it
"File:CityIcon-64px.png" is icon of it
"/images/cr/9/9e/CityIcon-64px.png" is iconUrl of it
"CrSchema" is context of it
City_name addsTo it
City_wikidataid addsTo it
# properties of City
# property name
City_name isA Property
"name" is name of it
"name" is label of it
"text" is type of it
1 is index of it
1 is sortPos of it
true is primaryKey of it
true is mandatory of it
50 is size of it
false is uploadable of it
"The name of the city" is documentation of it
false is isLink of it
"City" is topic of it
# property wikidataid
City_wikidataid isA Property
"wikidataid" is name of it
"wikidataid" is label of it
"text" is type of it
2 is index of it
false is primaryKey of it
false is mandatory of it
50 is size of it
false is uploadable of it
"The wikidataid of the city" is documentation of it
false is isLink of it
"City" is topic of it
#
# Country
#
Country isA Topic
"Country" is name of it
"Countries" is pluralName of it
"distinct region in geography; a broad term that can include political divisions or regions associated with distinct political characteristics" is documentation of it
"[https://www.wikidata.org/wiki/Q6256 distinct region in geography; a broad term that can include political divisions or regions associated with distinct political characteristics]" is wikiDocumentation of it
"File:CountryIcon-64px.png" is icon of it
"/images/cr/4/4c/CountryIcon-64px.png" is iconUrl of it
"property" is defaultstoremode of it
"CrSchema" is context of it
Country_name addsTo it
Country_wikidataid addsTo it
# properties of Country
# property name
Country_name isA Property
"name" is name of it
"name" is label of it
"text" is type of it
1 is index of it
1 is sortPos of it
true is primaryKey of it
true is mandatory of it
50 is size of it
false is uploadable of it
"The name of the Country" is documentation of it
false is isLink of it
"Country" is topic of it
# property wikidataid
Country_wikidataid isA Property
"wikidataid" is name of it
"wikidataid" is label of it
"text" is type of it
2 is index of it
false is primaryKey of it
false is mandatory of it
50 is size of it
false is uploadable of it
"The wikidataid of the Country" is documentation of it
false is isLink of it
"Country" is topic of it
#
# State
#
State isA Topic
"State" is name of it
"States" is pluralName of it
"territorial and constitutional community forming part of a federal union" is documentation of it
"[https://www.wikidata.org/wiki/Q107390 territorial and constitutional community forming part of a federal union]" is wikiDocumentation of it
"File:StateIcon-64px.png" is icon of it
"/images/cr/f/fe/StateIcon-64px.png" is iconUrl of it
"property" is defaultstoremode of it
"CrSchema" is context of it
State_name addsTo it
State_wikidataid addsTo it
# properties of State
# property name
State_name isA Property
"name" is name of it
"name" is label of it
"text" is type of it
1 is index of it
1 is sortPos of it
true is primaryKey of it
true is mandatory of it
50 is size of it
false is uploadable of it
"The name of the State" is documentation of it
false is isLink of it
"State" is topic of it
# property wikidataid
State_wikidataid isA Property
"wikidataid" is name of it
"wikidataid" is label of it
"text" is type of it
2 is index of it
false is primaryKey of it
false is mandatory of it
50 is size of it
false is uploadable of it
"The wikidataid of the State" is documentation of it
false is isLink of it
"State" is topic of it
#
# TopicLinks
#
# Event n : 1 City
Event_in_City isA TopicLink
"eventInCity" is name of it
"city" is sourceRole of it
false is sourceMultiple of it
"City" is source of it
"event" is targetRole of it
true is targetMultiple of it
"Event" is target of it 
# Event n : 1 State
Event_in_State isA TopicLink
"eventInState" is name of it
"state" is sourceRole of it
false is sourceMultiple of it
"State" is source of it
"event" is targetRole of it
true is targetMultiple of it
"Event" is target of it 
# Event n : 1 Country
Event_in_Country isA TopicLink
"eventInCountry" is name of it
"country" is sourceRole of it
false is sourceMultiple of it
"Country" is source of it
"event" is targetRole of it
true is targetMultiple of it
"Event" is target of it

解决方案

You first need to define a reference property. These have the referenced class as dataType. E.g. for referencing a city:

{
  "name": "inCity",
  "description": "city reference",
  "dataType": [
    "City"
  ],
  "cardinality": "many"
}

Then you can add references via a beacon:

curl -X POST "http://localhost:8080/v1/things/c60505f9-8271-4eec-b998-81d016648d85/references/hasEvent" -H 'Content-Type: application/json' -d '{"beacon": "weaviate://localhost/things/2a8d56b7-2dd5-4e68-aa40-53c9196aecde"}'

In this example the property hasEvent of thing the object with uuid c60505f9-8271-4eec-b998-81d016648d85 is referencing the object with uuid 2a8d56b7-2dd5-4e68-aa40-53c9196aecde.

Check the reference documentation for more infos.

Here is a minimal example using the python client:

#pip install weaviate-client==0.4.0
import weaviate
import time

schema = {
  "things": {
    "type": "thing",
    "classes": [
      {
        "class": "Event",
        "description": "event",
        "properties": [
          {
            "name": "acronym",
            "description": "acronym",
            "dataType": [
              "text"
            ]
          },
          {
            "name": "inCity",
            "description": "city reference",
            "dataType": [
              "City"
            ],
            "cardinality": "many"
          }
        ]
      },
      {
        "class": "City",
        "description": "city",
        "properties": [
          {
            "name": "name",
            "description": "name",
            "dataType": [
              "text"
            ]
          },
          {
            "name": "hasEvent",
            "description": "event references",
            "dataType": [
              "Event"
            ],
            "cardinality": "many"
          }
        ]
      }
    ]
  }
}


client = weaviate.Client("http://localhost:8080")

if not client.contains_schema():
    client.create_schema(schema)

event = {"acronym": "example"}
client.create(event, "Event", "2a8d56b7-2dd5-4e68-aa40-53c9196aecde")
city = {"name": "Amsterdam"}
client.create(city, "City", "c60505f9-8271-4eec-b998-81d016648d85")

time.sleep(2.0)
client.add_reference("c60505f9-8271-4eec-b998-81d016648d85", "hasEvent", "2a8d56b7-2dd5-4e68-aa40-53c9196aecde")

Would it be possible to convert the domain core of SiDIF files to Weaviate Schema style in general?

This depends on your use-case and the amount of work that you want to put in.

  • If you are only interested in the semantic capabilities: In this case you might not need to build an elaborate schema at all. It might be enough to just create 4 classes subject, predicate, object and triple and load everything like so.
  • You want to load a specific set of definitions: You have to replicate the vocabulary of interest in as a weaviate schema. Weaviate does not support class inheritance so you'd have to define these somehow over references. If you have a cleanly defined vocabulary this should be relatively straight forward.
  • You want to dynamically load all kinds of vocabularies: I am not entirely sure if that is easily achievable. I'd assume that you have to build a very elaborate parser.

Hope this helps cheers.

这篇关于将 SiDiF 翻译成 Weaviate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆