Skip to content

Commit

Permalink
Merge branch 'ingest-subclass'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Cuddihy committed Oct 25, 2022
2 parents b029d16 + 134170e commit eb9a1ec
Show file tree
Hide file tree
Showing 21 changed files with 1,466 additions and 330 deletions.
135 changes: 135 additions & 0 deletions sparqlGraphLibrary/loadTestDuraBatterySubtype.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"version": 3,
"sparqlConn": {
"name": "Junit fuseki",
"domain": "",
"enableOwlImports": true,
"model": [
{
"type": "fuseki",
"url": "http://localhost:3030/JUNIT",
"graph": "http://junit/GG2NQYY2E/200001934/both"
}
],
"data": [
{
"type": "fuseki",
"url": "http://localhost:3030/JUNIT",
"graph": "http://junit/GG2NQYY2E/200001934/both"
}
]
},
"sNodeGroup": {
"version": 19,
"limit": 0,
"offset": 0,
"sNodeList": [
{
"propList": [
{
"valueTypes": [
"string"
],
"rangeURI": "http://www.w3.org/2001/XMLSchema#string",
"UriRelationship": "http://kdl.ge.com/durabattery#batteryDesc",
"Constraints": "",
"SparqlID": "?batteryDesc",
"isReturned": true,
"optMinus": 1,
"isRuntimeConstrained": false,
"instanceValues": [],
"isMarkedForDeletion": false
},
{
"valueTypes": [
"string"
],
"rangeURI": "http://www.w3.org/2001/XMLSchema#string",
"UriRelationship": "http://kdl.ge.com/durabattery#batteryId",
"Constraints": "",
"SparqlID": "?batteryId",
"isReturned": true,
"optMinus": 0,
"isRuntimeConstrained": false,
"instanceValues": [],
"isMarkedForDeletion": false
}
],
"nodeList": [],
"fullURIName": "http://kdl.ge.com/durabattery#Battery",
"SparqlID": "?Battery",
"isReturned": true,
"isRuntimeConstrained": false,
"valueConstraint": "",
"instanceValue": null,
"deletionMode": "NO_DELETE",
"isTypeReturned": true
}
],
"orderBy": [],
"groupBy": [],
"unionHash": {},
"columnOrder": []
},
"importSpec": {
"version": "1",
"baseURI": "",
"columns": [
{
"colId": "col_0",
"colName": "subtype"
},
{
"colId": "col_1",
"colName": "id"
},
{
"colId": "col_2",
"colName": "desc"
}
],
"dataValidator": [],
"texts": [],
"transforms": [],
"nodes": [
{
"sparqlID": "?Battery",
"type": "http://kdl.ge.com/durabattery#Battery",
"URILookupMode": "createIfMissing",
"mapping": [],
"props": [
{
"URIRelation": "http://kdl.ge.com/durabattery#batteryDesc",
"mapping": [
{
"colId": "col_2"
}
]
},
{
"URIRelation": "http://kdl.ge.com/durabattery#batteryId",
"URILookup": [
"?Battery"
],
"mapping": [
{
"colId": "col_1"
}
]
}
],
"type_restriction": {
"URILookup": [
"?Battery"
],
"mapping": [
{
"colId": "col_0"
}
]
}
}
]
},
"plotSpecs": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ private static enum ClauseTypes {
// version 17: property item valueTypes, domainURI, rangeURI
// version 18: complex ranges
// version 19 - fixed buggy wrong name propertyItem.domainURI back to old propertyItem.UriRelationship
private static final int VERSION = 19;
// version 20 - ingestion with subtypes
private static final int VERSION = 20;

// actually used to keep track of our nodes and the nomenclature in use.
private ArrayList<Node> nodes = new ArrayList<Node>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void setIsBindingReturned(Boolean isBindingReturned) {
}

public String getTypeSparqlID() {
return this.sparqlID + "_type";
return this.getBindingOrSparqlID() + "_type";
}

public HashSet<String> getFunctionSparqlIDs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
public class ImportMapping {
public static String NO_PROPERTY = "";
public static String TYPE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
private String nodeSparqlID = null;
private String propURI = NO_PROPERTY;
private ArrayList<MappingItem> itemList = new ArrayList<MappingItem>();
Expand Down Expand Up @@ -67,9 +68,12 @@ public boolean getIsEnum() {
return this.isEnum;
}
public boolean isProperty() {
return !this.propURI.equals(NO_PROPERTY);
return !this.propURI.equals(NO_PROPERTY) && !this.isTypeRestriction();
}

public boolean isTypeRestriction() {
return this.propURI.equals(ImportMapping.TYPE_URI);
}

public boolean isNode() {
return this.propURI.equals(NO_PROPERTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class ImportSpec {
public static final String JKEY_IS_TRANS_TYPE = "transType";
public static final String JKEY_IS_TRANS_ARG1 = "arg1";
public static final String JKEY_IS_TRANS_ARG2 = "arg2";
public static final String JKEY_IS_TYPE_RESTRICTION = "type_restriction";
public static final String JKEY_IS_NODES = "nodes";
public static final String JKEY_IS_NODE_SPARQL_ID = "sparqlID";
public static final String JKEY_IS_NODE_TYPE = "type";
Expand All @@ -70,6 +71,8 @@ public class ImportSpec {
public static final String JKEY_IS_PROPS = "props";
public static final String JKEY_IS_MAPPING_PROPS_URI_REL = "URIRelation";

public static final int TYPE_RESTRICTION_PROP = -1;

JSONObject json = new JSONObject();

public ImportSpec() {
Expand Down Expand Up @@ -276,17 +279,42 @@ public ArrayList<String> getNodeMappingTransformList(int nodeIndex, int mappingI
JSONArray arr = (JSONArray) this.getNodeMapping(nodeIndex, mappingIndex).get(JKEY_IS_MAPPING_TRANSFORM_LIST);
return toStringList(arr);
}

public boolean getNodeHasTypeRestriction(int nodeIndex) {
return this.getNodeProp(nodeIndex, TYPE_RESTRICTION_PROP) != null;
}

/**
* Count number of normal properties (does not include special type_restriction)
* @param index
* @return
*/
public int getNodeNumProperties(int index) {
JSONArray arr = (JSONArray) this.getNode(index).get(JKEY_IS_PROPS);
return arr == null ? 0 : arr.size();
}

/**
* Get property: where there are special property constants beyond the normal [0,n]
* @param n - node index
* @param p - prop index or special prop constant (TYPE_RESTRICTION_PROP)
* @return
*/
private JSONObject getNodeProp(int n, int p) {
JSONArray arr = (JSONArray) this.getNode(n).get(JKEY_IS_PROPS);
return (JSONObject) arr.get(p);
if (p == TYPE_RESTRICTION_PROP) {
return (JSONObject) this.getNode(n).get(JKEY_IS_TYPE_RESTRICTION);
} else {
JSONArray arr = (JSONArray) this.getNode(n).get(JKEY_IS_PROPS);
return (JSONObject) arr.get(p);
}
}

public String getNodePropUriRel(int n, int p) {
return (String) this.getNodeProp(n, p).get(JKEY_IS_MAPPING_PROPS_URI_REL);
if (p == TYPE_RESTRICTION_PROP) {
return ImportMapping.TYPE_URI;
} else {
return (String) this.getNodeProp(n, p).get(JKEY_IS_MAPPING_PROPS_URI_REL);
}
}


Expand Down Expand Up @@ -437,6 +465,7 @@ private JSONObject findNode(String sparqlId) throws Exception {
private JSONObject findProp(String nodeSparqlId, String propUri) throws Exception {

JSONObject node = this.findNode(nodeSparqlId);

JSONArray props = (JSONArray) node.get(JKEY_IS_PROPS);
if (props != null) {
for (Object o : props) {
Expand All @@ -447,6 +476,7 @@ private JSONObject findProp(String nodeSparqlId, String propUri) throws Exceptio
}
}
throw new Exception("Can't find property in importSpec: " + propUri + " in node " + nodeSparqlId);

}

/**
Expand Down Expand Up @@ -704,6 +734,27 @@ public void updateSpecFromReturns(NodeGroup ng) throws Exception {
nObj.put(JKEY_IS_MAPPING, new JSONArray());
}

// if node is returned in nodegroup
if (node.getIsTypeReturned()) {

// find or create type restriction
JSONObject trObj = (JSONObject) nObj.get(JKEY_IS_TYPE_RESTRICTION);
if (trObj == null) {
trObj = new JSONObject();
nObj.put(JKEY_IS_TYPE_RESTRICTION, trObj);
}

String colName = ImportSpec.sparqlIDToColname(node.getBindingOrSparqlID() + "_type");
JSONArray mapArr = new JSONArray();
mapArr.add( this.buildMappingWithCol(colName));
trObj.put(JKEY_IS_MAPPING, mapArr);

} else {
// remove if no longer returned
nObj.remove(JKEY_IS_TYPE_RESTRICTION);
}


// loop through properties that are returned
for (PropertyItem prop : node.getPropertyItems()) {
JSONObject pObj;
Expand Down
Loading

0 comments on commit eb9a1ec

Please sign in to comment.