-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ts4nfdi/skosmos_agrovoc
Feature: Add SKOSMOS integration
- Loading branch information
Showing
5 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/org/semantics/apigateway/api/SkosmosTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.semantics.apigateway.api; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SkosmosTransformer implements DatabaseTransformer { | ||
@Override | ||
public Map<String, Object> transformItem(Map<String, Object> item) { | ||
if (item == null) { | ||
return null; | ||
} | ||
|
||
Map<String, Object> transformedItem = new HashMap<>(); | ||
|
||
// Check for null values before accessing properties | ||
if (item.containsKey("@id") && item.get("@id") != null) { | ||
transformedItem.put("iri", item.get("@id")); | ||
} | ||
if (item.containsKey("label") && item.get("label") != null) { | ||
transformedItem.put("prefLabel", item.get("label")); | ||
} | ||
if (item.containsKey("ontology") && item.get("ontology") != null) { | ||
transformedItem.put("vocab", item.get("ontology")); | ||
} | ||
if (item.containsKey("synonym") && item.get("synonym") != null) { | ||
transformedItem.put("altLabel", item.get("synonym")); | ||
} | ||
if (item.containsKey("backend_type") && item.get("backend_type") != null) { | ||
transformedItem.put("backend_type", item.get("backend_type")); | ||
} | ||
if (item.containsKey("short_form") && item.get("short_form") != null) { | ||
transformedItem.put("short_form", item.get("short_form")); | ||
} | ||
if (item.containsKey("description") && item.get("description") != null) { | ||
transformedItem.put("scopeNote", item.get("description")); | ||
} | ||
if (item.containsKey("source") && item.get("source") != null) { | ||
transformedItem.put("source", item.get("source")); | ||
} | ||
if (item.containsKey("type") && item.get("type") != null) { | ||
// the value of the key @type in OntoPortal is saved as an IRI | ||
if (item.containsKey("backend_type") && String.valueOf(item.get("backend_type")).equals("ols")) { | ||
if (item.get("type").equals("class")) { | ||
transformedItem.put("type", "http://www.w3.org/2002/07/owl#Class"); | ||
} else { | ||
transformedItem.put("type", item.get("type")); | ||
} | ||
} else { | ||
transformedItem.put("type", item.get("type")); | ||
} | ||
} | ||
return transformedItem; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> constructResponse(List<Map<String, Object>> transformedResults) { | ||
Map<String, Object> response = new HashMap<>(); | ||
response.put("results", transformedResults); | ||
response.put("@context", Collections.singletonMap("@context", "")); | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"request": { | ||
"type": "object", | ||
"properties": { | ||
"query": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
}, | ||
"required": ["query"] | ||
}, | ||
"@context": { | ||
"type": "object", | ||
"properties": { | ||
"skos": { "type": "string", "format": "uri" }, | ||
"isothes": { "type": "string", "format": "uri" }, | ||
"onki": { "type": "string", "format": "uri" }, | ||
"uri": { "type": "string" }, | ||
"type": { "type": "string" }, | ||
"prefLabel": { "type": "string" }, | ||
"altLabel": { "type": "string" }, | ||
"hiddenLabel": { "type": "string" }, | ||
"results": { "type": "array", | ||
"items": { | ||
"@id": { "type": "string" }, | ||
"@container": { "type": "array" } | ||
} | ||
} | ||
} | ||
}, | ||
"uri": { "type": "string" }, | ||
"results": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"uri": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"type": { | ||
"type": "array", | ||
"items": { "type": "string" } | ||
}, | ||
"prefLabel": { "type": "string" }, | ||
"lang": { "type": "string" }, | ||
"hiddenLabel": { "type": "string" }, | ||
"altLabel": { "type": "string" }, | ||
"vocab": { "type": "string" }, | ||
"exvocab": { "type": "string" } | ||
}, | ||
"required": ["prefLabel", "uri", "vocab", "type"] | ||
} | ||
} | ||
}, | ||
"required": ["request", "results"] | ||
} |