首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将SiDiF翻译成Weaviate

将SiDiF翻译成Weaviate
EN

Stack Overflow用户
提问于 2020-07-24 14:34:57
回答 1查看 70关注 0票数 3

我在简单数据交换格式中有几个本体描述,并且希望转换或导入这些描述,以便与Weaviate一起使用。

可以在以下网站找到一个例子:

http://cr.bitplan.com/index.php/CrSchema#sidif (见下面的源代码)。

我能够手动创建类和属性,但我不知道如何用Weaviates模式描述风格来实现关系。例如,如果我有一个类“事件”,并希望为它链接城市,,我如何做到这一点,如果有呢?

您将在http://cr.bitplan.com/index.php/Concept:Event上找到更多关于该模式的详细信息,并为其提供一个UML图:

它也可在http://diagrams.bitplan.com/render/png/0x2637ba5e.png上使用。

是否可以将SiDIF文件的域核心一般转换为Weaviate风格?

CrSchema

代码语言:javascript
复制
#
# 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
EN

回答 1

Stack Overflow用户

发布于 2020-07-24 16:14:56

首先需要定义引用属性。这些类的引用类为dataType。指城市:

代码语言:javascript
复制
{
  "name": "inCity",
  "description": "city reference",
  "dataType": [
    "City"
  ],
  "cardinality": "many"
}

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

代码语言:javascript
复制
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"}'

在本例中,具有uuid hasEvent c60505f9-8271-4eec-b998-81d016648d85的对象的属性2a8d56b7-2dd5-4e68-aa40-53c9196aecde引用了uuid 2a8d56b7-2dd5-4e68-aa40-53c9196aecde对象。

查看参考文献以获得更多信息。

下面是一个使用python客户机的最小示例:

代码语言:javascript
复制
#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")

在一般情况下,是否可以将SiDIF文件的域核心转换为Weaviate样式?

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

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

希望这能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63075787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档