Skip to content

Commit

Permalink
Add synonyms to entity details in neighborhood explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
cav-ipb committed Jun 19, 2024
1 parent 982d9cf commit 5d56734
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,13 @@ const NeighborhoodExplorerComponent: React.FC<GraphExplorerProps> = ({graphServi


const init = async () => {
// let graph = await graphService.getInitial(messageService!);
// const newElements = [...graph.nodes.map((x:any)=>{ return {data: x}}), ...graph.links?.map((x:any)=>{ return {data: x}})];
// setElements([...newElements]);

setQueryHistory(await graphVisualizationHistoryService.getAllAsOptions(messageService!));

// const nodes = neighborhoodExplorerStore.getIds();
// if (nodes.length > 0){
// const graph = {nodes: nodes.map(x => {return {data: x}}), edges: []};
// myComponentRef.current!.setElements(JSON.stringify(graph));
// } else {
// const viz = await graphVisualizationHistoryService.get("0", messageService!);
// myComponentRef.current!.setElements(viz.visualization);
// }

// console.log(neighborhoodExplorerStore.elements);
// if (neighborhoodExplorerStore.elements?.nodes){
// console.log("here");
// console.log(neighborhoodExplorerStore.elements.nodes);
// myComponentRef.current!.setElements(JSON.stringify(neighborhoodExplorerStore.elements))
// }
if (!neighborhoodExplorerStore.elements?.nodes){
const viz = await graphVisualizationHistoryService.get("0", messageService!);
myComponentRef.current!.setElements(viz.visualization);
}

const entityTypes = await entityTypeService.getAll(messageService!);
setTypes(entityTypes.map(x => {return {name: x.name, id: x.id, color: x.color}}));
Expand Down Expand Up @@ -199,6 +186,25 @@ const NeighborhoodExplorerComponent: React.FC<GraphExplorerProps> = ({graphServi
];
};

const nodeSynonymsTemplate = (items: any[]) : ReactNode[] | undefined => {
if (!items || items.length === 0) return undefined;

let list = items.sort().map((query, index) => {
return (<div style={{padding: 5, backgroundColor: "#F8F9FA", marginBottom: 5, borderRadius: 10, border: '1px solid #DEE2E6', overflowX: 'scroll'} }>

<span style={{marginLeft: 5}}>{query}</span>

</div>)
});

return [
<>
<b style={{paddingLeft: "3px"}}>Synonyms:</b>
{list}
</>
];
};

const nodeReferencesTemplate = (items: any[]) : ReactNode[] | undefined => {
if (!items || items.length === 0) return undefined;

Expand Down Expand Up @@ -591,6 +597,7 @@ const NeighborhoodExplorerComponent: React.FC<GraphExplorerProps> = ({graphServi
<MolecularDrawComponent element={element}></MolecularDrawComponent>
<canvas id="mol_structure" width="500" height="500" style={{display: 'none'}}></canvas>
<DataView value={element.properties} listTemplate={nodePropertiesTemplate} />
<DataView value={element.synonyms} listTemplate={nodeSynonymsTemplate}/>
<DataView value={element.references} listTemplate={nodeReferencesTemplate} />
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class EntityDTO {
private List<String> labels;
private List<PropertyValueDTO> properties;
private List<ReferenceDTO> references;
private List<String> synonyms;
private String color;

public EntityDTO() {
Expand Down Expand Up @@ -79,4 +80,12 @@ public List<ReferenceDTO> getReferences() {
public void setReferences(List<ReferenceDTO> references) {
this.references = references;
}

public List<String> getSynonyms() {
return synonyms;
}

public void setSynonyms(List<String> synonyms) {
this.synonyms = synonyms;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ipbhalle.de.ontologymanagerserver.data.dtos;

public class SynonymDTO
{
private String name;

public SynonymDTO() {}
public SynonymDTO(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public EntityDTO GetNode(String nodeId) {

var entity = neo4jTemplate.findOne(getNodeQuery, new HashMap<>(), N4JEntity.class);

if (entity.isEmpty())
return null;

Node sourceNode = Cypher.node("Source").named("s");
Relationship fromSourceRelationship = entityNode.relationshipTo(sourceNode, "FROM_SOURCE").named("r");

Expand All @@ -218,8 +221,17 @@ public EntityDTO GetNode(String nodeId) {

var references = neo4jTemplate.findAll(getReferencesQuery, ReferenceDTO.class);

if (entity.isEmpty())
return null;

Node synonymNode = Cypher.node("Synonym").named("s");
Relationship hasSynonymRelationship = entityNode.relationshipTo(synonymNode, "HAS_SYNONYM").named("r");
Statement getSynonymsQuery = Cypher
.match(hasSynonymRelationship)
.where(entityNode.property("OHUUID").isEqualTo(nodeIdParam))
.returning(
synonymNode.property("name").as("name")
).build();

var synonyms = neo4jTemplate.findAll(getSynonymsQuery, SynonymDTO.class);

var entityValue = entity.get();

Expand Down Expand Up @@ -257,6 +269,7 @@ public EntityDTO GetNode(String nodeId) {

entityDto.setProperties(propertyValues);
entityDto.setReferences(references);
entityDto.setSynonyms(synonyms.stream().map(SynonymDTO::getName).toList());

return entityDto;

Expand Down

0 comments on commit 5d56734

Please sign in to comment.