it.uniroma2.art.sheet2rdf.cfg.GraphApplicationConfigurationParser Maven / Gradle / Ivy
package it.uniroma2.art.sheet2rdf.cfg;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.rio.ntriples.NTriplesUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import it.uniroma2.art.coda.interfaces.annotations.converters.RDFCapabilityType;
import it.uniroma2.art.sheet2rdf.coda.CODAConverter;
import it.uniroma2.art.sheet2rdf.header.AdvancedGraphApplication;
import it.uniroma2.art.sheet2rdf.header.NodeConversion;
import it.uniroma2.art.sheet2rdf.utils.S2RDFUtils;
public class GraphApplicationConfigurationParser {
private ObjectNode cfgJson;
private ObjectMapper mapper;
private String placeholderPrefix;
private Map nodeIdReplacementMap;
public GraphApplicationConfigurationParser(ObjectNode cfgJson, String placeholderPrefix) {
this.cfgJson = cfgJson;
mapper = new ObjectMapper();
this.placeholderPrefix = placeholderPrefix;
nodeIdReplacementMap = new HashMap();
}
public List getNodeConversions() {
JsonNode nodesJson = cfgJson.get("nodes");
List nodes = new ArrayList();
for (int i = 0; i < nodesJson.size(); i++) {
NodeConversion node = new NodeConversion();
JsonNode nodeJson = nodesJson.get(i);
//id
String nodeId = nodeJson.get("nodeId").asText();
String prefixedNodeId = placeholderPrefix + "_" + nodeId;
nodeIdReplacementMap.put(nodeId, prefixedNodeId);
node.setNodeId(prefixedNodeId);
//converter
CODAConverter converter = new CODAConverter();
JsonNode converterJson = nodeJson.get("converter");
converter.setType(RDFCapabilityType.valueOf(converterJson.get("type").asText()));
converter.setContractUri(converterJson.get("contractUri").asText());
JsonNode langJson = converterJson.get("language");
if (!langJson.isNull()) {
converter.setLanguage(langJson.asText());
}
JsonNode dtUriJson = converterJson.get("datatypeUri");
if (!dtUriJson.isNull()) {
converter.setDatatypeUri(dtUriJson.asText());
}
JsonNode paramsJson = converterJson.get("params");
Map paramsMap = mapper.convertValue(paramsJson, new TypeReference