Skip to content

Commit 31e620d

Browse files
[fix]知识图谱label字段大小写 review by qiw
1 parent d85c0fa commit 31e620d

File tree

7 files changed

+117
-19
lines changed

7 files changed

+117
-19
lines changed

src/common/overlay/KnowledgeGraph.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ export class KnowledgeGraph {
160160
* @function KnowledgeGraph.dataFromGraphMap
161161
* @description 将iServer GraphMap数据转换成KnowledgeGraph数据。
162162
* @param {Object} queryResult - iServer知识图谱服务query数据。
163-
* @param {Object} graphMapStyle - iServer知识图谱服务GraphMap的style属性(graphMap.styles.style)。
163+
* @param {Object} graphMap - iServer知识图谱服务GraphMap数据(data.graphMap)。
164164
* @return {KnowledgeGraph.Data} 返回数据。
165165
*/
166-
static dataFromGraphMap(queryResult, graphMapStyle) {
167-
return transformGraphMap(queryResult, graphMapStyle);
166+
static dataFromGraphMap(queryResult, graphMap) {
167+
return transformGraphMap(queryResult, graphMap);
168168
}
169169

170170
/**

src/common/overlay/knowledge-graph/format.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import uniqBy from 'lodash.uniqby';
22

3-
export function transformGraphMap(data, style) {
3+
export function transformGraphMap(data, graphMap) {
4+
const style = graphMap && graphMap.styles && graphMap.styles.style;
5+
const captionField = graphMap && graphMap.captionFields && graphMap.captionFields.captionField;
6+
47
const rst = { nodes: [], edges: [] };
58
data.forEach((item) => {
69
const pathData = item.path;
710
if (pathData) {
8-
const { nodes, edges } = transformPath(pathData, style);
11+
const { nodes, edges } = transformPath(pathData, style, captionField);
912
rst.nodes.push(...nodes);
1013
rst.edges.push(...edges);
1114
} else if (isEdge(item)) {
1215
const edge = edgeFromGraphMap(item, style);
1316
rst.edges.push(edge);
1417
} else {
15-
const node = nodeFromGraphMap(item, style);
18+
const node = nodeFromGraphMap(item, style, captionField);
1619
rst.nodes.push(node);
1720
}
1821
});
@@ -27,24 +30,24 @@ function isEdge(entity) {
2730
return entity.hasOwnProperty('start') && entity.hasOwnProperty('end');
2831
}
2932

30-
function transformPath(pathData, style) {
33+
function transformPath(pathData, style, captionField) {
3134
const rst = { nodes: [], edges: [] };
3235
pathData.forEach((item) => {
3336
if (isEdge(item)) {
3437
const edge = edgeFromGraphMap(item, style);
3538
rst.edges.push(edge);
3639
} else {
37-
const node = nodeFromGraphMap(item, style);
40+
const node = nodeFromGraphMap(item, style, captionField);
3841
rst.nodes.push(node);
3942
}
4043
});
4144
return rst;
4245
}
4346

44-
export function nodeFromGraphMap(entity, style) {
47+
export function nodeFromGraphMap(entity, style, captionField) {
4548
const { id, properties, lables } = entity;
4649
const styleData = style ? getNodeStyle(entity, style) : {};
47-
const label = getNodeLabel(entity);
50+
const label = getNodeLabel(entity, captionField);
4851
const fillColor = styleData.fillColor || '';
4952
const node = {
5053
id: id + '',
@@ -133,10 +136,20 @@ function getNodeStyle(entity, style) {
133136
return {};
134137
}
135138

136-
function getNodeLabel(entity) {
137-
const { properties } = entity;
138-
const name = properties._labelfieldname;
139-
return properties[name] || '';
139+
function getNodeLabel(entity, captionField) {
140+
const { id, labels, properties } = entity;
141+
if (captionField) {
142+
const data = captionField instanceof Array ? captionField : [captionField];
143+
for (let i = 0; i < data.length; i++) {
144+
const { name, entityTypes, entityIds } = data[i];
145+
const ids = JSON.parse(entityIds || '[]');
146+
const types = JSON.parse(entityTypes || '[]');
147+
if (ids.includes(id) || types.includes(labels[0])) {
148+
return properties[name] || '';
149+
}
150+
}
151+
}
152+
return properties[properties._labelfieldname] || '';
140153
}
141154

142155
function formatFontStyle(fontStyle) {

src/leaflet/overlay/GraphMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class GraphMap extends L.Evented {
6363
async createGraphMap(graphMapName, options) {
6464
this.knowledgeGraphService = this.createKnowledgeGraphService(this.url, options);
6565
const res = await this.knowledgeGraphService.getGraphMapData(graphMapName);
66-
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap.styles && res.graphMap.styles.style);
66+
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap);
6767
this.graph = new KnowledgeGraph(options && options.config);
6868
this.graph.on('beforelayout', () => {
6969
/**

src/mapboxgl/overlay/GraphMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class GraphMap extends mapboxgl.Evented {
5959
async createGraphMap(graphMapName, options) {
6060
this.knowledgeGraphService = this.createKnowledgeGraphService(this.url, options);
6161
const res = await this.knowledgeGraphService.getGraphMapData(graphMapName);
62-
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap.styles && res.graphMap.styles.style);
62+
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap);
6363
this.graph = new KnowledgeGraph(options && options.config);
6464
this.graph.on('beforelayout', () => {
6565
/**

src/maplibregl/overlay/GraphMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class GraphMap extends maplibregl.Evented {
5959
async createGraphMap(graphMapName, options) {
6060
this.knowledgeGraphService = this.createKnowledgeGraphService(this.url, options);
6161
const res = await this.knowledgeGraphService.getGraphMapData(graphMapName);
62-
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap.styles && res.graphMap.styles.style);
62+
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap);
6363
this.graph = new KnowledgeGraph(options && options.config);
6464
this.graph.on('beforelayout', () => {
6565
/**

src/openlayers/overlay/GraphMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class GraphMap extends Observable {
6161
async createGraphMap(graphMapName, options) {
6262
this.knowledgeGraphService = this.createKnowledgeGraphService(this.url, options);
6363
const res = await this.knowledgeGraphService.getGraphMapData(graphMapName);
64-
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap.styles && res.graphMap.styles.style);
64+
const result = KnowledgeGraph.dataFromGraphMap(res.data, res.graphMap);
6565
this.graph = new KnowledgeGraph(options && options.config);
6666
this.graph.on('beforelayout', () => {
6767
/**

test/common/overlay/KnowledgeGraphSpec.js

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,97 @@ describe('KnowledgeGraph', () => {
159159
entityTypes: '["地籍子区"]'
160160
}
161161
];
162-
var data = KnowledgeGraph.dataFromGraphMap(graphData, style);
162+
var data = KnowledgeGraph.dataFromGraphMap(graphData, { styles: { style } });
163163
expect(data.nodes).not.toBeNull();
164164
expect(data.edges).not.toBeNull();
165165
done();
166166
});
167167

168+
it('dataFromGraphMap captionField array', (done) => {
169+
var graphData = [
170+
{
171+
path: [
172+
{
173+
id: 17732923532771331,
174+
properties: {
175+
server: '--server=E:/00testdata/知识图谱/基础地理实体/院落.udbx --dbType=UDBX --dataset=面1'
176+
},
177+
labels: ['面1']
178+
},
179+
{
180+
start: 17732923532771331,
181+
end: 18014398509481990,
182+
id: 20547673299877890,
183+
type: '邻接',
184+
properties: {}
185+
},
186+
{
187+
id: 18014398509481990,
188+
properties: {
189+
server: '--server=E:/00testdata/知识图谱/基础地理实体/院落.udbx --dbType=UDBX --dataset=面2'
190+
},
191+
labels: ['面2']
192+
}
193+
]
194+
},
195+
{
196+
id: 177329231,
197+
properties: {
198+
server: '--server=E:/00testdata/知识图谱/基础地理实体/院落.udbx --dbType=UDBX --dataset=面1'
199+
},
200+
labels: ['面1']
201+
},
202+
{
203+
start: 177329231,
204+
end: 17732923,
205+
id: 20547673890,
206+
type: '邻接1',
207+
properties: {}
208+
}
209+
];
210+
var style = [
211+
{
212+
type: 'entity',
213+
color: '#ffc454',
214+
textColor: '#ffffff',
215+
font: {
216+
fontName: 'Microsoft Yahei UI',
217+
fontSize: 13,
218+
fontStyle: 0
219+
},
220+
size: 20,
221+
entityIds: '[12,16,18,21,23,25,28,29]'
222+
},
223+
{
224+
type: 'entity',
225+
color: '#c990c0',
226+
textColor: '#595959',
227+
font: {
228+
fontName: 'Microsoft Yahei UI',
229+
fontSize: 6,
230+
fontStyle: 0
231+
},
232+
size: 20,
233+
entityTypes: '["地籍子区"]'
234+
}
235+
];
236+
var captionField = { entityTypes: '["面1"]', name: 'server' };
237+
var data = KnowledgeGraph.dataFromGraphMap(graphData, {
238+
styles: { style },
239+
captionFields: { captionField: [captionField] }
240+
});
241+
expect(data.nodes[0].label).toBe(
242+
'--server=E:/00testdata/知识图谱/基础地理实体/院落.udbx --dbType=UDBX --dataset=面1'
243+
);
244+
expect(data.edges).not.toBeNull();
245+
var data1 = KnowledgeGraph.dataFromGraphMap(graphData, { styles: { style }, captionFields: { captionField } });
246+
expect(data1.nodes[0].label).toBe(
247+
'--server=E:/00testdata/知识图谱/基础地理实体/院落.udbx --dbType=UDBX --dataset=面1'
248+
);
249+
expect(data1.edges).not.toBeNull();
250+
done();
251+
});
252+
168253
it('dataFromKnowledgeGraphQuery', (done) => {
169254
var graphData = [
170255
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy