All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.uniroma2.art.sheet2rdf.header.AdvancedGraphApplication Maven / Gradle / Ivy

There is a newer version: 6.0.6
Show newest version
package it.uniroma2.art.sheet2rdf.header;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.rdf4j.model.IRI;
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 it.uniroma2.art.sheet2rdf.utils.JsonConstants;

public class AdvancedGraphApplication extends GraphApplication {
	
	private List nodeIds; //ids of the nodes referenced in the graph pattern
	private Map prefixMapping;
	private String pattern;
	private IRI defaultPredicate;
	
	public static final String PREDICATE_PLACEHOLDER = "{{pred}}";
	
	public AdvancedGraphApplication() {
		super();
		nodeIds = new ArrayList();
		prefixMapping = new HashMap();
	}
	
	public List getNodeIds() {
		return nodeIds;
	}

	public void setNodeIds(List nodeIds) {
		this.nodeIds = nodeIds;
	}
	
	@Override
	public void removeNode(String nodeId) {
		nodeIds.remove(nodeId);
	}
	
	public String getPattern() {
		return pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public Map getPrefixMapping() {
		return prefixMapping;
	}

	public void setPrefixMapping(Map prefixMapping) {
		this.prefixMapping = prefixMapping;
	}
	
	public IRI getDefaultPredicate() {
		return defaultPredicate;
	}

	public void setDefaultPredicate(IRI defaultPredicate) {
		this.defaultPredicate = defaultPredicate;
	}

	@Override
	public void fromJson(JsonNode jsonNode) {
		ObjectMapper mapper = new ObjectMapper();
		this.id = jsonNode.get(JsonConstants.ADVANCED_GRAPH_APPLICATION_ID).asText();
		this.pattern = jsonNode.get(JsonConstants.ADVANCED_GRAPH_APPLICATION_PATTERN).asText();
		this.nodeIds = mapper.convertValue(jsonNode.get(JsonConstants.ADVANCED_GRAPH_APPLICATION_NODE_IDS), new TypeReference>(){});
		this.prefixMapping = mapper.convertValue(jsonNode.get(JsonConstants.ADVANCED_GRAPH_APPLICATION_PREFIX_MAPPING), new TypeReference>(){});
		JsonNode defaultPredJson = jsonNode.get(JsonConstants.ADVANCED_GRAPH_APPLICATION_DEFAULT_PREDICATE);
		if (!defaultPredJson.isNull()) {
			this.defaultPredicate = NTriplesUtil.parseURI(defaultPredJson.asText(), SimpleValueFactory.getInstance());
		}
	}
	
	@Override
	public String toString() {
		String s = "";
		s += "id:\t\t" + this.id + "\n";
		s += "pattern:\t" + this.pattern + "\n";
		s += "nodeIds:\t" + this.nodeIds + "\n";
		s += "prefNs:\t\t" + this.prefixMapping + "\n";
		s += "def Pred:\t" + (this.defaultPredicate == null ? "null" : this.defaultPredicate.stringValue());
		return s;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy