跳转至

Implement an interface(实现接口(Implement an interface))

Once defined, an interface can be implemented by any object type that conforms to the interface definition. This means that object types must have properties that satisfy the interface's required properties, links that satisfy all required link type constraints, and action types that satisfy all required action type constraints defined on the interface.

Implementing an interface with an object type indicates that that object type is a concrete instance of the interface within the Ontology. This declaration facilitates additional functionality on the object type, namely:

  • Object Set Service searches against the interface will return matching objects of the implementing object type.
  • Objects of the implementing object type can be interacted with using both their local API names when typed as the concrete object type and the interface API names for properties and links when typed as the interface type.

In short, implementing an interface allows application consumers to interact with any and all implementing objects through the interface definition. This allows application code to be written using the interface as an API layer instead of requiring the application to support every implementing object type individually. Additionally, by using the interface as an application API layer, new object types can be added to the application by having them implement the application interface without requiring code changes to explicitly support the new object type.

How to implement an interface in Ontology Manager

Follow the steps below to implement an interface with an object type.

1. Select your interface and object type

First, navigate to the object type in Ontology Manager and open the Interfaces tab. Select + Implement new interface in the top right corner of the page.

Implement an interface from an object type.

In the dialog that appears, select the interface to implement.

Select interface to implement.

Alternatively, navigate to the interface overview page and select + New in the Implementations section.

Implement an interface from the interface overview.

Then, select the object type to implement the interface.

Select interface to implement.

2. Map local properties

To implement an interface, an object type must declare a mapping of existing object properties onto the required interface properties. If an interface property is marked as optional, mapping may be skipped.

Map properties between the interface and the implementing object type.

If any required link type constraints are declared on the interface, you must select a link type on the object type that satisfies each required link type constraint. You can also optionally provide a link mapping for any non-required link type constraints. You can choose an existing link type or create a new one to satisfy each constraint.

Map link types to fulfill link type constraints.

4. Map action type constraints

If any required action type constraints are declared on the interface, you must select an action type on the object type that satisfies each required action type constraint. You can also optionally provide an action mapping for any non-required action type constraints.

After the interface implementation is created, configure parameter mappings from the object type's Interfaces tab. You must map any required parameter constraints to compatible required parameters on the concrete action type before saving changes to the Ontology.

5. Save changes

Select Save to make the changes to your Ontology.

How to implement an interface in Pipeline Builder

Follow the steps below to implement an interface on an object type output in Pipeline Builder.

1. Open output type configuration

Select the object type output that you would like to implement an interface, then select the Edit option.

Edit object type output.

2. Select the interface to implement

Select Implement interface.

Select Implement interface.

Then, select the interface to implement and choose Implement and go to mapping.

Interface selection and go to mapping.

3. Map local properties

To implement an interface, an object type must contain the interface's shared properties or declare a mapping of existing object properties onto the interface shared properties. Shared properties that are present on both the interface and object type will be automatically mapped. Any shared properties that are not on the object type will require you to manually input a mapping to satisfy the interface definition.

Map local properties.

4. Review implemented interfaces

You can view the interfaces implemented by this object type output from the output type configuration panel.

Review implemented interfaces.

:::callout{theme="neutral"} Pipeline Builder does not currently support link type constraint or action type constraint mapping when implementing an interface. If your interface contains required link type constraints or required action type constraints, you must implement the interface through Ontology Manager. :::


中文翻译


实现接口(Implement an interface)

接口一旦定义,任何符合接口定义的对象类型均可实现该接口。这意味着对象类型必须包含满足接口必需属性的属性、满足所有必需链接类型约束的链接,以及满足接口定义中所有必需操作类型约束的操作类型。

通过对象类型实现接口,表明该对象类型是本体(Ontology)中接口的具体实例。此声明为对象类型提供了额外功能,具体包括:

  • 针对接口的对象集服务(Object Set Service)搜索将返回实现该接口的对象类型中的匹配对象。
  • 当实现接口的对象类型被具体化为具体对象类型时,可使用其本地API名称进行交互;当被类型化为接口类型时,可使用接口的属性与链接API名称进行交互。

简而言之,实现接口允许应用程序使用者通过接口定义与所有实现对象进行交互。这使得应用程序代码可以基于接口作为API层编写,而无需为每个实现对象类型单独提供支持。此外,通过将接口作为应用程序API层,新增对象类型只需实现该应用程序接口即可接入,无需修改代码来显式支持新对象类型。

如何在Ontology Manager中实现接口

按照以下步骤通过对象类型实现接口。

1. 选择接口与对象类型

首先,在Ontology Manager中导航至目标对象类型,打开接口(Interfaces)选项卡。点击页面右上角的+ 实现新接口(Implement new interface)

从对象类型实现接口。

在弹出的对话框中,选择要实现的接口。

选择要实现的接口。

或者,导航至接口概览页面,在实现(Implementations)部分点击+ 新建(New)

从接口概览实现接口。

然后,选择要实现该接口的对象类型。

选择要实现的接口。

2. 映射本地属性

为实现接口,对象类型必须声明现有对象属性到接口必需属性的映射。如果接口属性标记为可选(optional),则可跳过映射。

映射接口与实现对象类型之间的属性。

3. 映射链接类型约束

如果接口声明了任何必需的链接类型约束(link type constraints),则必须在对象类型上选择满足每个必需链接类型约束的链接类型。你也可以为非必需的链接类型约束提供可选的链接映射。你可以选择现有链接类型或创建新链接类型来满足每个约束。

映射链接类型以满足链接类型约束。

4. 映射操作类型约束

如果接口声明了任何必需的操作类型约束(action type constraints),则必须在对象类型上选择满足每个必需操作类型约束的操作类型。你也可以为非必需的操作类型约束提供可选的映射。

创建接口实现后,通过对象类型的接口(Interfaces)选项卡配置参数映射。在保存对本体的更改之前,必须将所有必需的参数约束映射到具体操作类型上的兼容必需参数。

5. 保存更改

点击保存(Save)以将更改应用到本体。

如何在Pipeline Builder中实现接口

按照以下步骤在Pipeline Builder中为对象类型输出(object type output)实现接口。

1. 打开输出类型配置

选择要实现接口的对象类型输出,然后点击编辑(Edit)选项。

编辑对象类型输出。

2. 选择要实现的接口

点击实现接口(Implement interface)

选择实现接口。

然后,选择要实现的接口,并点击实现并跳转至映射(Implement and go to mapping)

接口选择并跳转至映射。

3. 映射本地属性

为实现接口,对象类型必须包含接口的共享属性,声明现有对象属性到接口共享属性的映射。接口与对象类型共有的共享属性将自动映射。对于对象类型中不存在的共享属性,你需要手动输入映射以满足接口定义。

映射本地属性。

4. 查看已实现的接口

你可以通过输出类型配置面板查看此对象类型输出已实现的接口。

查看已实现的接口。

:::callout{theme="neutral"} Pipeline Builder目前不支持在实现接口时进行链接类型约束或操作类型约束的映射。如果你的接口包含必需的链接类型约束或必需的操作类型约束,则必须通过Ontology Manager实现接口。 :::