此类定义了要在知识图谱服务的图谱资源中添加、删除和更新的实体和关系。使用 entityUpdates 或 relationshipUpdates 更改属性值。
注
- 用户必须具有编辑内容的足够权限并且必须启用编辑才能使知识图谱服务成功执行此操作。
- 另请参阅
// add a new `Supplier` entity
require([
"geoscene/rest/knowledgeGraphService",
"geoscene/rest/knowledgeGraph/Entity",
"geoscene/rest/knowledgeGraph/GraphApplyEdits"
], (knowledgeGraphModule, Entity, GraphApplyEdits) => {
const newEntity = new Entity({
typeName: "Supplier",
properties: {
Name: "Supplier 5",
EmployeeCount: 681
}
});
KnowledgeGraphModule.executeApplyEdits(
graph,
new GraphApplyEdits({
entityAdds: [newEntity]
})
).then((editResult) => {
console.log("Graph Add Result", editResult);
});
});
// add multiple new items
const newEntity = new Entity({
typeName: "Supplier",
properties: {
Name: "Supplier 5",
EmployeeCount: 681
},
});
const newRelationship = new 关系({
typeName: "buys_part",
properties: {
quantity: 5000
},
// origin and destination entities must already exist in the graph
originId: "{AN4E4G85-41F1-49A4-8412-CACCC9906E88}",
destinationId: "{9D2D6AFD-41F1-49A4-8412-1DGR8E5D6S1G4}"
});
KnowledgeGraphModule.executeApplyEdits(graph, {
entityAdds: [newEntity],
relationshipAdds: [newRelationship]
})
.then((editResult) => {
console.log("Graph Add Result", editResult);
});
// update existing records
const updateEntity = new Entity({
typeName: "Supplier",
// update the EmployeeCount from 681 to 685
properties: {
Name: "Supplier 5",
EmployeeCount: 685
},
id:"{G1E5G3D4-41F1-49A4-8412-1S5GE8S4D5S1G}" //id of entity already in knowledge graph
});
const updateRelationship = new 关系({
typeName: "buys_part",
// update the quantity from 5000 to 5500
properties: {
quantity: 5500
},
id: "{MSIGESNG-A1F5-1A8F-3W5F-15A8W4F3S5F8W}" //id of relationship already in knowledge graph
});
KnowledgeGraphModule.executeApplyEdits(graph, {
entityUpdates: [updateEntity],
relationshipUpdates: [updateRelationships]
})
.then((editResult) => {
console.log("Graph Update Result", editResult);
});
// delete existing records
KnowledgeGraphModule.executeApplyEdits(graph, {
entityDeletes: [{
typeName: "Supplier",
ids: ["{AMGIE541G-41F1-49A4-8412-CACCC9906E88}", "{HNWIGHE15-WH52-2GE6-1A5W-A1F8W4FS3A1S5}"]
},{
typeName: "Part",
ids: ["{FNIW4GF1-ANFW-49A4-ANW7-GNWIGHAF4S51FS}"]
}],
relationshipDeletes: [{
typeName: "Buys_part",
ids: ["{MH4E54G8E-MF4W-1842-2S44-15AF5W8F4S2W8}"]
}],
// delete all relationships connected to the deleted entities.
options:{
cascadeDelete: true
}
})
.then((editResult) => {
console.log("Graph Delete Result", editResult);
});
// Basic example results of adding one entity to the `Supplier` entity type
{
editResults:[{
adds:[
{
id: "{ANWIFLWF-ANFW-49A4-ANW7-GM51GN5G1878}",
error: false
}],
deletes:[],
typeName: "Supplier",
updates:[]
}],
hasError: false,
error: undefined
}
构造函数
属性概述
名称 | 类型 | 描述 | 类 |
---|---|---|---|
String | 类的名称。 更多详情 | Accessor | |
Entity[] | 更多详情 | GraphApplyEdits | |
GraphNamedObjectDeletes[] | 更多详情 | GraphApplyEdits | |
Entity[] | 更多详情 | GraphApplyEdits | |
Object | 其他选项,用于为添加到图谱中的任何几何设置输入量化,并自动删除与已删除实体关联的所有关系。 更多详情 | GraphApplyEdits | |
关系[] | 更多详情 | GraphApplyEdits | |
GraphNamedObjectDeletes[] | 更多详情 | GraphApplyEdits | |
关系[] | 更多详情 | GraphApplyEdits |
属性详细信息
-
类的名称。声明的类名称格式化为
geoscene.folder.className
。
-
示例
//add a new `Supplier` entity const newEntity = new Entity({ typeName: "Supplier", properties: { Name: "Supplier 5", EmployeeCount: 681 } }); KnowledgeGraphModule.executeApplyEdits( graph, { entityAdds: [newEntity], }) .then((editResult) => { console.log("Graph Add Result", editResult); });
-
entityDeletes GraphNamedObjectDeletes[]
-
示例
entityDeletes: [{ typeName: "Supplier", ids: ["{AMGIE541G-41F1-49A4-8412-CACCC9906E88}", "{HNWIGHE15-WH52-2GE6-1A5W-A1F8W4FS3A1S5}"] },{ typeName: "Part", ids: ["{FNIW4GF1-ANFW-49A4-ANW7-GNWIGHAF4S51FS}"] }]
-
options Object
-
其他选项,用于为添加到图谱中的任何几何设置输入量化,并自动删除与已删除实体关联的所有关系。
- 属性
-
inputQuantizationParameters InputQuantizationParameters
输入几何的自定义量化参数,用于压缩几何以传输到服务器。覆盖默认的无损 WGS84 量化。
cascadeDelete Boolean如果为
true
,则删除实体将自动删除与该实体相连接的所有关系。如果为false
,则必须同时提供实体及其所有连接关系,否则 executeApplyEdits() 操作将失败。 - 默认值:false
-
示例
//add a new `Supplier` entity const newRelationship = new 关系({ typeName: "buys_part", properties: { quantity: 18880, }, originId: "{AN4E4G85-41F1-49A4-8412-CACCC9906E88}", destinationId: "{9D2D6AFD-41F1-49A4-8412-1DGR8E5D6S1G4}" }); KnowledgeGraphModule.executeApplyEdits( graph, { relationshipAdds: [newRelationship], }) .then((editResult) => { console.log("Graph Add Result", editResult); });
-
relationshipDeletes GraphNamedObjectDeletes[]
-
示例
relationshipDeletes: [{ typeName: "Buys_part", ids: ["{MH4E54G8E-MF4W-1842-2S44-15AF5W8F4S2W8}"] }],
方法概述
名称 | 返回值类值 | 描述 | 类 |
---|---|---|---|
添加一个或多个与对象的生命周期相关联的句柄。 更多详情 | Accessor | ||
Boolean | 如果存在指定的句柄组,则返回 true。 更多详情 | Accessor | |
移除对象拥有的句柄组。 更多详情 | Accessor |
方法详细说明
-
addHandles(handleOrHandles, groupKey)inherited
-
添加一个或多个与对象的生命周期相关联的句柄。当对象被销毁时,将移除句柄。
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); // Handle gets removed when the object is destroyed. this.addHandles(handle);
参数handleOrHandles WatchHandle|WatchHandle[]对象销毁后,标记为要移除的句柄。
groupKey *optional标识句柄应添加到的组的键。组中的所有句柄稍后都可使用 Accessor.removeHandles() 进行删除。如果未提供键,则句柄将被添加到默认组。
-
如果存在指定的句柄组,则返回 true。
参数groupKey *optional组键。
返回类型 描述 Boolean 如果存在指定的句柄组,则返回 true
。示例// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
removeHandles(groupKey)inherited
-
移除对象拥有的句柄组。
参数groupKey *optional要移除的密钥组或密钥组的数组或集合。
示例obj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
类型定义
-
GraphNamedObjectDeletes Object
-
GraphNamedObjectDeletes 表示将从知识图谱中删除的特定类型的 GraphNamedObjects (entities 或 relationships) 列表。
- 属性
-
typeName String
实体所属的 EntityType 的名称。
要删除的指定类型的 ID 列表。
示例//typical use case GraphApplyEdits.entityDeletes = [{ typeName: "Supplier", ids: ["{AMGIE541G-41F1-49A4-8412-CACCC9906E88}", "{HNWIGHE15-WH52-2GE6-1A5W-A1F8W4FS3A1S5}"] }]