Skip to content

Commit

Permalink
undid recent horrible propertyItem.domainURI name in the nodegroup. i…
Browse files Browse the repository at this point in the history
…ncremented to VERSION 19
  • Loading branch information
Paul Cuddihy committed Mar 11, 2022
1 parent 66199bf commit 1da07c9
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,10 @@ public JSONObject changeItemURI(@RequestBody NodeGroupItemUriRequest requestBod
PropertyItem prop = itemStr.getpItem();
if (deleteFlag) {
nodegroup.deleteProperty(node, prop);
importSpec.deleteProperty(node.getSparqlID(), prop.getDomainURI());
importSpec.deleteProperty(node.getSparqlID(), prop.getUriRelationship());
} else {
PropertyItem newProp = nodegroup.changeItemDomain(node, prop, newURI);
importSpec.changePropertyDomain(node.getSparqlID(), prop.getDomainURI(), newURI);
importSpec.changePropertyDomain(node.getSparqlID(), prop.getUriRelationship(), newURI);

// If newURI is a valid property in ontology, make sure range is correct too
OntologyProperty oProp = oInfo.getProperty(newURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void inflateAndValidate(OntologyInfo oInfo, ImportSpec importSpec, ArrayL
// build hash of suggested properties for this class
HashMap<String, PropertyItem> inputPItemHash = new HashMap<>();
for (PropertyItem p : this.props) {
inputPItemHash.put(p.getDomainURI(), p);
inputPItemHash.put(p.getUriRelationship(), p);
}

// build hash of suggested nodes for this class
Expand Down Expand Up @@ -510,16 +510,16 @@ public void validateAgainstModel(OntologyInfo oInfo) throws Exception {
// check each property's URI and range
for (PropertyItem myPropItem : this.props) {
// domain
if (! oPropHash.containsKey(myPropItem.getDomainURI())) {
if (! oPropHash.containsKey(myPropItem.getUriRelationship())) {
throw new ValidationException(String.format("Node %s contains property %s which does not exist in the model",
this.getSparqlID(), myPropItem.getDomainURI()));
this.getSparqlID(), myPropItem.getUriRelationship()));
}

// range
OntologyRange oRange = oPropHash.get(myPropItem.getDomainURI()).getRange(oClass, oInfo);
OntologyRange oRange = oPropHash.get(myPropItem.getUriRelationship()).getRange(oClass, oInfo);
if (!oRange.equalsUri(myPropItem.getRangeURI())) {
throw new ValidationException(String.format("Node %s, property %s has type %s which doesn't match %s in model",
this.getSparqlID(), myPropItem.getDomainURI(), myPropItem.getRangeURI(), oRange.getDisplayString(true)));
this.getSparqlID(), myPropItem.getUriRelationship(), myPropItem.getRangeURI(), oRange.getDisplayString(true)));
}
}

Expand Down Expand Up @@ -948,7 +948,7 @@ public PropertyItem getPropertyItem(int i) {

public int getPropertyIndexByURIRelation(String uriRel) {
for (int i = 0; i < this.props.size(); i++) {
if (this.props.get(i).getDomainURI().equals(uriRel)) {
if (this.props.get(i).getUriRelationship().equals(uriRel)) {
return i;
}
}
Expand All @@ -957,7 +957,7 @@ public int getPropertyIndexByURIRelation(String uriRel) {

public PropertyItem getPropertyByURIRelation(String uriRel) {
for (int i = 0; i < this.props.size(); i++) {
if (this.props.get(i).getDomainURI().equals(uriRel)) {
if (this.props.get(i).getUriRelationship().equals(uriRel)) {
return this.props.get(i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private static enum ClauseTypes {
// version 16: columnOrder
// version 17: property item valueTypes, domainURI, rangeURI
// version 18: complex ranges
private static final int VERSION = 18;
// version 19 - fixed buggy wrong name propertyItem.domainURI back to old propertyItem.UriRelationship
private static final int VERSION = 19;

// actually used to keep track of our nodes and the nomenclature in use.
private ArrayList<Node> nodes = new ArrayList<Node>();
Expand Down Expand Up @@ -809,9 +810,9 @@ private void addAllToPrefixHash(){
}
// add the URIs for the properties as well:
for(PropertyItem pi : n.getPropertyItems()){
this.addToPrefixHash(pi.getDomainURI());
this.addToPrefixHash(pi.getUriRelationship());
if (this.oInfo != null) {
for (String subProp : this.oInfo.inferSubPropertyNames(pi.getDomainURI(), n.getFullUriName())) {
for (String subProp : this.oInfo.inferSubPropertyNames(pi.getUriRelationship(), n.getFullUriName())) {
this.addToPrefixHash(subProp);
}
}
Expand Down Expand Up @@ -2731,7 +2732,7 @@ private String generateSparqlSubgraphClausesPropItem(ClauseTypes clauseType, Nod
}

// get subPropNames or null for IDK
HashSet<String> subPropNames = (this.oInfo == null) ? null : this.oInfo.inferSubPropertyNames(prop.getDomainURI(), snode.getUri());
HashSet<String> subPropNames = (this.oInfo == null) ? null : this.oInfo.inferSubPropertyNames(prop.getUriRelationship(), snode.getUri());

/**
// Virtuoso can't handle subPropertyOf:
Expand Down Expand Up @@ -2765,11 +2766,11 @@ private String generateSparqlSubgraphClausesPropItem(ClauseTypes clauseType, Nod
// CONSTRUCT uses the binding, where others use the sparqlID
String nodeId = (clauseType == ClauseTypes.CONSTRUCT_LEADER) ? snode.getBindingOrSparqlID() : snode.getSparqlID();

sparql.append(tab + nodeId + " " + this.applyPrefixing(prop.getDomainURI()) + " " + prop.getSparqlID() + " .\n");
sparql.append(tab + nodeId + " " + this.applyPrefixing(prop.getUriRelationship()) + " " + prop.getSparqlID() + " .\n");

} else {
// prop with sub-props
String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getDomainURI());
String predVarName = SparqlToXUtils.safeSparqlVar(snode.getSparqlID() + "_" + prop.getUriRelationship());

if (clauseType == ClauseTypes.CONSTRUCT_LEADER) {
// varname no values clause
Expand All @@ -2778,16 +2779,16 @@ private String generateSparqlSubgraphClausesPropItem(ClauseTypes clauseType, Nod
} else if ( clauseType == ClauseTypes.CONSTRUCT_WHERE) {
// varname plus values clause
sparql.append(tab + snode.getBindingOrSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getDomainURI(), subPropNames) + " .\n");
sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");

} else if ( clauseType == ClauseTypes.DELETE_WHERE) {
// varname plus values clause
sparql.append(tab + snode.getSparqlID() + " " + predVarName + " " + prop.getSparqlID() + " .\n");
sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getDomainURI(), subPropNames) + " .\n");
sparql.append(tab + this.genSubPropertiesContraint(predVarName, prop.getUriRelationship(), subPropNames) + " .\n");

} else {
// "normal": parenthesized predicate
sparql.append(tab + snode.getSparqlID() + " " + this.genSubPropertyListParenthesized(prop.getDomainURI(), subPropNames)+ " " + prop.getSparqlID() + " .\n");
sparql.append(tab + snode.getSparqlID() + " " + this.genSubPropertyListParenthesized(prop.getUriRelationship(), subPropNames)+ " " + prop.getSparqlID() + " .\n");
}

}
Expand Down Expand Up @@ -4415,13 +4416,13 @@ private String genDeletionLeader() throws Exception {
// check the properties.
for( PropertyItem pi : n.getPropertyItems() ){
if(pi.getIsMarkedForDeletion()){
HashSet<String> subPropNames = (this.oInfo == null) ? new HashSet<String>() : this.oInfo.inferSubPropertyNames(pi.getDomainURI(), n.getUri());
HashSet<String> subPropNames = (this.oInfo == null) ? new HashSet<String>() : this.oInfo.inferSubPropertyNames(pi.getUriRelationship(), n.getUri());
if (subPropNames.size() == 0) {
// no sub-props: use prefixed property uri
retval.append(" " + n.sparqlID + " " + this.applyPrefixing( pi.getDomainURI() ) + " " + pi.sparqlID + " . \n");
retval.append(" " + n.sparqlID + " " + this.applyPrefixing( pi.getUriRelationship() ) + " " + pi.sparqlID + " . \n");
} else {
// sub-props: use variable
String varName = SparqlToXUtils.safeSparqlVar(n.getSparqlID() + "_" + pi.getDomainURI());
String varName = SparqlToXUtils.safeSparqlVar(n.getSparqlID() + "_" + pi.getUriRelationship());
retval.append(" " + n.sparqlID + " " + varName + " " + pi.sparqlID + " .\n");
}
}
Expand Down Expand Up @@ -4679,7 +4680,7 @@ public String getInsertLeader(String sparqlIDSuffix, OntologyInfo oInfo) throws
// insert each property we know of.
for(PropertyItem prop : node.getPropertyItems()){
for(String inst : prop.getInstanceValues()){
retval += "\t" + subject + " " + this.applyPrefixing(prop.getDomainURI()) + " " + prop.buildRDF11ValueString(inst, "XMLSchema") + " .\n";
retval += "\t" + subject + " " + this.applyPrefixing(prop.getUriRelationship()) + " " + prop.buildRDF11ValueString(inst, "XMLSchema") + " .\n";
}
}

Expand Down Expand Up @@ -4751,7 +4752,7 @@ public String getInsertWhereBody(String sparqlIDSuffix, OntologyInfo oInfo) thro
for (PropertyItem pi : constrainedProps) {

sparql.append(
" " + sparqlId + " " + this.applyPrefixing(pi.getDomainURI()) +
" " + sparqlId + " " + this.applyPrefixing(pi.getUriRelationship()) +
" " + pi.getSparqlID() + " . " + pi.getConstraints() + " .\n");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public NodeGroupItemStr(Node snode, NodeItem item, Node target) {
public NodeGroupItemStr(Node snode, PropertyItem item) {
this.snode = snode;
this.pItem = item;
this.str = snode.getSparqlID() + "|" + item.getDomainURI();
this.str = snode.getSparqlID() + "|" + item.getUriRelationship();
}
public NodeGroupItemStr(Node snode) {
this.snode = snode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PropertyItem extends Returnable {
private HashSet<XSDSupportedType> valueTypes = null; // if range is a OntologyDatatype, could be multiple
// only the XSDSupportedTypes are in the PropertyItem
private String rangeURI = null;
private String domainURI = null;
private String uriRelationship = null;

private int optMinus = OPT_MINUS_NONE;
private ArrayList<String> instanceValues = new ArrayList<String>();
Expand All @@ -54,13 +54,13 @@ public PropertyItem(XSDSupportedType valueType, String rangeUri, String uriRelat
this.valueTypes = new HashSet<XSDSupportedType>();
this.valueTypes.add(valueType);
this.rangeURI = rangeUri;
this.domainURI = uriRelationship;
this.uriRelationship = uriRelationship;
}

public PropertyItem(HashSet<XSDSupportedType> valueTypes, String rangeUri, String uriRelationship){
this.valueTypes = valueTypes;
this.rangeURI = rangeUri;
this.domainURI = uriRelationship;
this.uriRelationship = uriRelationship;
}


Expand Down Expand Up @@ -98,11 +98,15 @@ public PropertyItem(JSONObject jObj) throws Exception {
}

if (jObj.containsKey("relationship")) {
this.rangeURI = jObj.get("relationship").toString(); // note that label "relationship" in the JSON is misleading
this.domainURI = jObj.get("UriRelationship").toString();
this.rangeURI = jObj.get("relationship").toString(); // deprecated: note that label "relationship" in the JSON is misleading
} else {
this.rangeURI = jObj.get("rangeURI").toString(); // note that label "relationship" in the JSON is misleading
this.domainURI = jObj.get("domainURI").toString();
this.rangeURI = jObj.get("rangeURI").toString(); // correct new name
}

if (jObj.containsKey("UriRelationship")) {
this.uriRelationship = jObj.get("UriRelationship").toString(); // the usual name
} else {
this.uriRelationship = jObj.get("domainURI").toString(); // this bug of a bad name was used for a brief time
}

this.optMinus = OPT_MINUS_NONE;
Expand Down Expand Up @@ -143,7 +147,7 @@ public JSONObject toJson() {
}
ret.put("valueTypes", valTypes);
ret.put("rangeURI", this.rangeURI);
ret.put("domainURI", this.domainURI);
ret.put("UriRelationship", this.uriRelationship);
ret.put("optMinus", this.optMinus);
ret.put("isMarkedForDeletion", this.isMarkedForDeletion);
ret.put("instanceValues", iVals);
Expand Down Expand Up @@ -172,15 +176,15 @@ public int getOptMinus() {
}

public String getKeyName() {
return new OntologyName(domainURI).getLocalName();
return new OntologyName(uriRelationship).getLocalName();
}

public String getDomainURI() {
return this.domainURI;
public String getUriRelationship() {
return this.uriRelationship;
}

public void setDomainURI(String uri) {
this.domainURI = uri;
public void setUriRelationship(String uri) {
this.uriRelationship = uri;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static ArrayList<String> suggestNodeClass(OntologyInfo oInfo, NodeGroup n
// get URI for each property and node item
ArrayList<String> snodeProps = new ArrayList<String>();
for (PropertyItem pItem : snode.getPropertyItems()) {
snodeProps.add(pItem.getDomainURI());
snodeProps.add(pItem.getUriRelationship());
}
for (NodeItem nItem : snode.getNodeItemList()) {
snodeProps.add(nItem.getUriConnectBy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,25 +712,25 @@ public void updateSpecFromReturns(NodeGroup ng) throws Exception {
if (prop.getIsReturned() || prop.getIsBindingReturned()) {
// find or add
try {
pObj = this.findProp(node.getSparqlID(), prop.getDomainURI());
pObj = this.findProp(node.getSparqlID(), prop.getUriRelationship());
} catch (Exception e) {
pObj = this.addProp(node.getSparqlID(), prop.getDomainURI());
pObj = this.addProp(node.getSparqlID(), prop.getUriRelationship());
}

// if mapping is empty
JSONArray mapping = (JSONArray) pObj.get(JKEY_IS_MAPPING);
if (mapping.size() == 0) {
// add a column and simple mapping
String colName = ImportSpec.sparqlIDToColname(prop.getBindingOrSparqlID());
this.addMapping(node.getSparqlID(), prop.getDomainURI(), this.buildMappingWithCol(colName));
this.addMapping(node.getSparqlID(), prop.getUriRelationship(), this.buildMappingWithCol(colName));
}
} else {
// remove if no longer returned
try {
pObj = this.findProp(node.getSparqlID(), prop.getDomainURI());
pObj = this.findProp(node.getSparqlID(), prop.getUriRelationship());
JSONArray mapping = (JSONArray) pObj.get(JKEY_IS_MAPPING);
if (mapping.size() == 0)
this.deleteProperty(node.getSparqlID(), prop.getDomainURI());
this.deleteProperty(node.getSparqlID(), prop.getUriRelationship());
} catch (Exception e) {
// ignore if findProp failed
}
Expand Down Expand Up @@ -772,7 +772,7 @@ public void addURILookups(NodeGroup ng, String propRegex, String lookupMode) thr
for (PropertyItem prop : node.getPropertyItems()) {
String name = prop.getBindingOrSparqlID();
if (p.matcher(name).find()) {
JSONObject pObj = this.findProp(nodeID, prop.getDomainURI());
JSONObject pObj = this.findProp(nodeID, prop.getUriRelationship());
JSONArray mArr = (JSONArray) pObj.get(JKEY_IS_MAPPING);

// if the property is mapped, add lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public void build() throws Exception {
nodegroup.setIsReturned(pItem, true);

// add to import spec
ispecBuilder.addProp(node.getSparqlID(), pItem.getDomainURI());
ispecBuilder.addProp(node.getSparqlID(), pItem.getUriRelationship());

if (this.idRegex != null && Pattern.compile(this.idRegex).matcher(pItem.getKeyName()).find()) {
// lookup ID is a lookup and is NOT optional
ispecBuilder.addURILookup(node.getSparqlID(), pItem.getDomainURI(), node.getSparqlID());
ispecBuilder.addURILookup(node.getSparqlID(), pItem.getUriRelationship(), node.getSparqlID());
ispecBuilder.addLookupMode(node.getSparqlID(), ImportSpec.LOOKUP_MODE_CREATE);
} else {
// normal properties ARE optional
Expand All @@ -120,7 +120,7 @@ public void build() throws Exception {

String colName = buildColName(pItem.getSparqlID());
ispecBuilder.addColumn(colName);
ispecBuilder.addMapping(node.getSparqlID(), pItem.getDomainURI(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));
ispecBuilder.addMapping(node.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));

// add to csvTemplate
csvTemplate.append(colName + ",");
Expand Down Expand Up @@ -160,13 +160,13 @@ public void build() throws Exception {


// add to importspec, using it to look up parent node
ispecBuilder.addProp(objNode.getSparqlID(), pItem.getDomainURI());
ispecBuilder.addURILookup(objNode.getSparqlID(), pItem.getDomainURI(), objNode.getSparqlID());
ispecBuilder.addProp(objNode.getSparqlID(), pItem.getUriRelationship());
ispecBuilder.addURILookup(objNode.getSparqlID(), pItem.getUriRelationship(), objNode.getSparqlID());

// add the column and mapping to the importspec
String colName = buildColName(propId);
ispecBuilder.addColumn(colName);
ispecBuilder.addMapping(objNode.getSparqlID(), pItem.getDomainURI(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));
ispecBuilder.addMapping(objNode.getSparqlID(), pItem.getUriRelationship(), ispecBuilder.buildMappingWithCol(colName, new String [] {transformId}));

// add to csvTemplate
csvTemplate.append(colName + ",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void parseConstructQueryResults() throws Exception {
assertEquals(TShirtPrintingNode.getNodeItemList().size(),0);

pi = TShirtPrintingNode.getPropertyByKeyname("mouseLot");
assertEquals(pi.getDomainURI(),"http://research.ge.com/soft/testconfig#mouseLot");
assertEquals(pi.getUriRelationship(),"http://research.ge.com/soft/testconfig#mouseLot");
assertEquals(pi.getInstanceValues().get(0),"50416-1");
assertTrue(pi.getValueTypes().contains(XSDSupportedType.STRING));
assertTrue(pi.getIsReturned());
Expand Down
Loading

0 comments on commit 1da07c9

Please sign in to comment.