Перевод SiDiF на Weaviate
У меня есть несколько описаний онтологий в формате простого обмена данными, и я хотел бы преобразовать или импортировать их, чтобы использовать их с Weaviate.
Пример можно найти по адресу:
http://cr.bitplan.com/index.php/CrSchema (см. исходный код ниже).
Мне удалось создать классы и свойства вручную, но я не уверен, как делать отношения в стиле описания схемы Weaviates. Например, если у меня есть класс "Событие" и я хочу связать для него город, как мне это сделать, если вообще?
Вы найдете более подробную информацию о схеме на http://cr.bitplan.com/index.php/Concept:Event, а также для нее
есть диаграмма UML:
которая также доступна по адресу http://diagrams.bitplan.com/render/png/0x2637ba5e.png.
Можно ли вообще преобразовать ядро домена файлов SiDIF в стиль Weaviate Schema?
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
1 ответ
Сначала вам нужно определить ссылочное свойство. У них есть ссылочный класс какdataType
. Например, для обозначения города:
{
"name": "inCity",
"description": "city reference",
"dataType": [
"City"
],
"cardinality": "many"
}
Затем вы можете добавить ссылки через маяк:
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"}'
В этом примере свойство hasEvent
вещи объект с uuid c60505f9-8271-4eec-b998-81d016648d85
ссылается на объект с помощью uuid 2a8d56b7-2dd5-4e68-aa40-53c9196aecde
.
Проверьте справочную документацию для более подробной информации.
Вот минимальный пример использования клиента python:
#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 Schema?
Это зависит от вашего варианта использования и объема работы, которую вы хотите выполнить.
- Если вас интересуют только семантические возможности: в этом случае вам может вообще не понадобиться создавать сложную схему. Достаточно создать 4 класса
subject
,predicate
,object
а такжеtriple
и загружаем все вот так. - Вы хотите загрузить определенный набор определений: вы должны воспроизвести интересующий словарь в виде сложной схемы. Weaviate не поддерживает наследование классов, поэтому вам придется как-то определять их по ссылкам. Если у вас четко определенный словарный запас, это должно быть относительно просто.
- Вы хотите динамически загружать все виды словарей: я не совсем уверен, легко ли это сделать. Я предполагаю, что вам нужно создать очень сложный парсер.
Надеюсь, это поможет развлечься.