it.uniroma2.art.sheet2rdf.header.SimpleGraphApplication Maven / Gradle / Ivy
package it.uniroma2.art.sheet2rdf.header;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import com.fasterxml.jackson.databind.JsonNode;
import it.uniroma2.art.sheet2rdf.utils.JsonConstants;
import org.eclipse.rdf4j.rio.ntriples.NTriplesUtil;
public class SimpleGraphApplication extends GraphApplication {
private String nodeId; //id of the node that represent the subject in the s-p-o triple defined by the graph application
private IRI property;
private IRI type; //in case of rangeType resource
public SimpleGraphApplication() {
super();
}
public String getNodeId() {
return nodeId;
}
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
@Override
public void removeNode(String nodeId) {
if (this.nodeId.equals(nodeId)) {
this.nodeId = null;
}
}
public IRI getProperty() {
return property;
}
public void setProperty(IRI property) {
this.property = property;
}
public IRI getType() {
return type;
}
public void setType(IRI type) {
this.type = type;
}
@Override
public void fromJson(JsonNode jsonNode) {
SimpleValueFactory svf = SimpleValueFactory.getInstance();
this.id = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_ID).asText();
String propertyJson = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_PROPERY).asText();
this.property = (!propertyJson.equals("null")) ? NTriplesUtil.parseURI(propertyJson, svf) : null;
String typeJson = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_TYPE).asText();
this.type = (!typeJson.equals("null")) ? NTriplesUtil.parseURI(typeJson, svf) : null;
this.nodeId = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_NODE_ID).asText();
}
@Override
public String toString() {
String s = "";
s += "id:\t" + this.id + "\n";
s += "prop:\t" + (this.property != null ? this.property.stringValue() : null) + "\n";
s += "type:\t" + (this.type != null ? this.type.stringValue() : null) + "\n";
s += "nodeId:\t" + this.nodeId;
return s;
}
}