Skip to content

Commit

Permalink
Merge branch 'master' into Release
Browse files Browse the repository at this point in the history
  • Loading branch information
nbachman committed Jun 6, 2017
2 parents 18decdb + 22aa48d commit 7c8712b
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 38 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public final class SadlErrorMessages {
**/
public static final SadlErrorMessage MUST_BE_APPLIED_TO_LIST = new SadlErrorMessage("must_be_applied_to_list");
/**
* This changes the domain of property ''{0}'' which has an imported domain; are you sure that's what you want to do?
**/
public static final SadlErrorMessage IMPORTED_DOMAIN_CHANGE = new SadlErrorMessage("imported_domain_change");
/**
* List definition is empty. Remove empty list brackets from definition.
**/
public static final SadlErrorMessage EMPTY_LIST_DEFINITION = new SadlErrorMessage("empty_list_definition");
Expand Down Expand Up @@ -211,6 +215,10 @@ public final class SadlErrorMessages {
**/
public static final SadlErrorMessage UNIQUE_NAME = new SadlErrorMessage("unique_name");
/**
* This changes the range of property ''{0}'' which has an imported range; are you sure that's what you want to do?
**/
public static final SadlErrorMessage IMPORTED_RANGE_CHANGE = new SadlErrorMessage("imported_range_change");
/**
* translate(Name) called with a SadlResource which resolved to null; this needs to be caught in validation
**/
public static final SadlErrorMessage TRANSLATE_NAME_SADLRESOURCE = new SadlErrorMessage("translate_name_sadlresource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ validate_bin_op_error.description=Left side of operand ('0') can not be compared
variable_instead_of_prop=It is unusual to have a variable (''{0}'') rather than a defined property as rule predicate.
class_property_value_owl_full=Only OWL Full allows classes to have property values.
datatype_as_domain=Using a datatype as a domain--probably not what was intended?
datatype_as_domain.description=Normally the domain of a property is a class, not a datatype as datatypes do not normally have identity.
datatype_as_domain.description=Normally the domain of a property is a class, not a datatype as datatypes do not normally have identity.
imported_range_change=This changes the range of property ''{0}'' which has an imported range; are you sure that's what you want to do?
imported_range_change.description=Best practice is to define the range more broadly and then restrict it for particular classes.
imported_domain_change=This changes the domain of property ''{0}'' which has an imported domain; are you sure that's what you want to do?
imported_domain_change.description=Best practice is to define the domain more in its original definition rather than change it in imported models.
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,10 @@ SADL also includes POJava licensed under Apache License V2.0.
version="0.0.0"
unpack="false"/>

<plugin
id="org.junit"
download-size="0"
install-size="0"
version="0.0.0"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

import com.ge.research.sadl.builder.ConfigurationManagerForIdeFactory;
import com.ge.research.sadl.builder.IConfigurationManagerForIDE;
import com.ge.research.sadl.builder.MessageManager.SadlMessage;
import com.ge.research.sadl.errorgenerator.generator.SadlErrorMessages;
import com.ge.research.sadl.errorgenerator.messages.SadlErrorMessage;
import com.ge.research.sadl.external.ExternalEmfResource;
Expand Down Expand Up @@ -199,6 +200,7 @@
//import com.ge.research.sadl.server.SessionNotFoundException;
//import com.ge.research.sadl.server.server.SadlServerImpl;
import com.ge.research.sadl.utils.ResourceManager;
import com.google.common.math.IntMath;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
import com.hp.hpl.jena.ontology.AnnotationProperty;
Expand Down Expand Up @@ -4177,11 +4179,12 @@ else if (rngNode instanceof OntClass){
}

RDFNode propOwlType = null;
boolean existingRangeThisModel = false;
boolean rangeExists = false;
boolean addNewRange = false;
StmtIterator existingRngItr = getTheJenaModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (existingRngItr.hasNext()) {
RDFNode existingRngNode = existingRngItr.next().getObject();
rangeExists = true;
// property already has a range know to this model
if (rngNode.equals(existingRngNode) || (rngResource != null && rngResource.equals(existingRngNode))) {
// do nothing-- rngNode is already in range
Expand Down Expand Up @@ -4213,14 +4216,19 @@ else if (rngNode instanceof OntClass){
}
}

boolean rangeInThisModel = false;
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
rangeInThisModel = true;
}
if (domainAndRangeAsUnionClasses) {
// in this case we want to create a union class if necessary
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
// StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.range, (RDFNode)null);
// if (inModelStmtItr.hasNext()) {
if (rangeInThisModel) {
// this model (as opposed to imports) already has a range specified
addNewRange = false;
UnionClass newUnionClass = null;
existingRangeThisModel = true;
while (inModelStmtItr.hasNext()) {
RDFNode rngThisModel = inModelStmtItr.nextStatement().getObject();
if (rngThisModel.isResource()) {
Expand Down Expand Up @@ -4252,9 +4260,7 @@ else if (rngNode instanceof OntClass){
}
} // end if existing range in this model
else {
if (existingRngNode != null) {
addWarning("This changes the range of property '" + prop.getURI() + "' which has an imported range; are you sure that's what you want to do?", context);
}
inModelStmtItr.close();
// check to see if this is something new
do {
if (existingRngNode.equals(rngNode)) {
Expand All @@ -4270,6 +4276,12 @@ else if (rngNode instanceof OntClass){
} while (existingRngNode != null);
}
} // end if domainAndRangeAsUnionClasses
else {
inModelStmtItr.close();
}
if (rangeExists && !rangeInThisModel) {
addWarning(SadlErrorMessages.IMPORTED_RANGE_CHANGE.get(nodeToString(prop)), context);
}
} // end if existing range in any model, this or imports
if (rngNode != null) {
if (rngResource != null) {
Expand Down Expand Up @@ -4382,7 +4394,7 @@ private String stmtIteratorToObjectString(StmtIterator stmtitr) {
private String nodeToString(RDFNode obj) {
StringBuilder sb = new StringBuilder();
if (obj.isURIResource()) {
sb.append(obj.toString());
sb.append(uriStringToString(obj.toString()));
}
else if (obj.canAs(UnionClass.class)){
UnionClass ucls = obj.as(UnionClass.class);
Expand Down Expand Up @@ -4699,7 +4711,10 @@ else if (instUri != null) {
} catch (DontTypeCheckException e) {
// do nothing
} catch(PropertyWithoutRangeException e){
issueAcceptor.addWarning(SadlErrorMessages.PROPERTY_WITHOUT_RANGE.get(declarationExtensions.getConcreteName(prop)), propinit);
String propUri = declarationExtensions.getConceptUri(prop);
if (!propUri.equals(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI)) {
issueAcceptor.addWarning(SadlErrorMessages.PROPERTY_WITHOUT_RANGE.get(declarationExtensions.getConcreteName(prop)), propinit);
}
} catch (Exception e) {
throw new JenaProcessorException("Unexpected error checking value in range", e);
}
Expand Down Expand Up @@ -5201,8 +5216,10 @@ private boolean checkForExistingCompatibleDatatypeProperty(
private void addPropertyDomain(Property prop, OntResource cls, EObject context) throws JenaProcessorException {
boolean addNewDomain = true;
StmtIterator sitr = getTheJenaModel().listStatements(prop, RDFS.domain, (RDFNode)null);
boolean domainExists = false;
if (sitr.hasNext()) {
RDFNode existingDomain = sitr.next().getObject();
domainExists = true;
// property already has a domain known to this model
if (cls.equals(existingDomain)) {
// do nothing--cls is already in domain
Expand All @@ -5223,11 +5240,15 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
return;
}
}


boolean domainInThisModel = false;
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.domain, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
domainInThisModel = true;
}
if (domainAndRangeAsUnionClasses) {
// in this case we want to create a union class if necessary
StmtIterator inModelStmtItr = getTheJenaModel().getBaseModel().listStatements(prop, RDFS.domain, (RDFNode)null);
if (inModelStmtItr.hasNext()) {
if (domainInThisModel) {
// this model (as opposed to imports) already has a domain specified
addNewDomain = false;
UnionClass newUnionClass = null;
Expand Down Expand Up @@ -5258,9 +5279,7 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
}
} // end if existing domain in this model
else {
if (existingDomain != null) {
addWarning("This changes the domain of property '" + prop.getURI() + "' which has an imported domain; are you sure that's what you want to do?", context);
}
inModelStmtItr.close();
// check to see if this is something new
do {
if (existingDomain.equals(cls)) {
Expand All @@ -5276,6 +5295,12 @@ private void addPropertyDomain(Property prop, OntResource cls, EObject context)
} while (existingDomain != null);
}
} // end if domainAndRangeAsUnionClasses
else {
inModelStmtItr.close();
}
if (domainExists && !domainInThisModel) {
addWarning(SadlErrorMessages.IMPORTED_DOMAIN_CHANGE.get(nodeToString(prop)), context);
}
} // end if existing domain in any model, this or imports
if(cls != null){
if (!domainAndRangeAsUnionClasses && cls instanceof UnionClass) {
Expand Down Expand Up @@ -6972,12 +6997,17 @@ public ITranslator getTranslator() throws ConfigurationException {
return cm.getTranslator();
}

public List<ConceptName> getImpliedProperties(com.hp.hpl.jena.rdf.model.Resource first) {
/**
* Method to obtain the sadlimplicitmodel:impliedProperty annotation property values for the given class
* @param cls -- the Jena Resource (nominally a class) for which the values are desired
* @return -- a List of the ConceptNames of the values
*/
public List<ConceptName> getImpliedProperties(com.hp.hpl.jena.rdf.model.Resource cls) {
List<ConceptName> retlst = null;
if (first == null) return null;
if (cls == null) return null;
// check superclasses
if (first.canAs(OntClass.class)) {
OntClass ontcls = first.as(OntClass.class);
if (cls.canAs(OntClass.class)) {
OntClass ontcls = cls.as(OntClass.class);
ExtendedIterator<OntClass> eitr = ontcls.listSuperClasses();
while (eitr.hasNext()) {
OntClass supercls = eitr.next();
Expand All @@ -6997,7 +7027,7 @@ public List<ConceptName> getImpliedProperties(com.hp.hpl.jena.rdf.model.Resource
}
}
}
StmtIterator sitr = getTheJenaModel().listStatements(first, getTheJenaModel().getProperty(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI), (RDFNode)null);
StmtIterator sitr = getTheJenaModel().listStatements(cls, getTheJenaModel().getProperty(SadlConstants.SADL_IMPLICIT_MODEL_IMPLIED_PROPERTY_URI), (RDFNode)null);
if (sitr.hasNext()) {
if (retlst == null) {
retlst = new ArrayList<ConceptName>();
Expand All @@ -7016,6 +7046,55 @@ public List<ConceptName> getImpliedProperties(com.hp.hpl.jena.rdf.model.Resource
return retlst;
}

/**
* Method to obtain the sadlimplicitmodel:expandedProperty annotation property values for the given class
* @param cls -- the Jena Resource (nominally a class) for which the values are desired
* @return -- a List of the URI strings of the values
*/
public List<String> getExpandedProperties(com.hp.hpl.jena.rdf.model.Resource cls) {
List<String> retlst = null;
if (cls == null) return null;
// check superclasses
if (cls.canAs(OntClass.class)) {
OntClass ontcls = cls.as(OntClass.class);
ExtendedIterator<OntClass> eitr = ontcls.listSuperClasses();
while (eitr.hasNext()) {
OntClass supercls = eitr.next();
List<String> scips = getExpandedProperties(supercls);
if (scips != null) {
if (retlst == null) {
retlst = scips;
}
else {
for (int i = 0; i < scips.size(); i++) {
String cn = scips.get(i);
if (!scips.contains(cn)) {
retlst.add(scips.get(i));
}
}
}
}
}
}
StmtIterator sitr = getTheJenaModel().listStatements(cls, getTheJenaModel().getProperty(SadlConstants.SADL_IMPLICIT_MODEL_EXPANDED_PROPERTY_URI), (RDFNode)null);
if (sitr.hasNext()) {
if (retlst == null) {
retlst = new ArrayList<String>();
}
while (sitr.hasNext()) {
RDFNode obj = sitr.nextStatement().getObject();
if (obj.isURIResource()) {
String cn = obj.asResource().getURI();
if (!retlst.contains(cn)) {
retlst.add(cn);
}
}
}
return retlst;
}
return retlst;
}

protected boolean isLookingForFirstProperty() {
return lookingForFirstProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ private boolean handleValidationException(EObject expr, Throwable t) {
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.TYPE_CHECK_EXCEPTION.get("Null Pointer"), expr);
} else if (t instanceof DontTypeCheckException) {
return true;
} else if (t instanceof PropertyWithoutRangeException) {
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.PROPERTY_WITHOUT_RANGE.get(((PropertyWithoutRangeException)t).getPropID()), expr);
return true;
} else if (t instanceof CircularDefinitionException) {
t.printStackTrace();
}
Expand Down Expand Up @@ -1969,25 +1972,25 @@ protected TypeCheckInfo getType(SadlResource qnm) throws DontTypeCheckException,
return tci;
}
else if(conceptType.equals(OntConceptType.DATATYPE_PROPERTY)){
TypeCheckInfo propcheckinfo = getNameProperty(ConceptType.DATATYPEPROPERTY, conceptUri, expression);
TypeCheckInfo propcheckinfo = getNameProperty(qnm, ConceptType.DATATYPEPROPERTY, conceptUri, expression);
if (propcheckinfo != null) {
return propcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if(conceptType.equals(OntConceptType.CLASS_PROPERTY)){
TypeCheckInfo propcheckinfo = getNameProperty(ConceptType.OBJECTPROPERTY, conceptUri, expression);
TypeCheckInfo propcheckinfo = getNameProperty(qnm, ConceptType.OBJECTPROPERTY, conceptUri, expression);
if (propcheckinfo != null) {
return propcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if (conceptType.equals(OntConceptType.RDF_PROPERTY)) {
TypeCheckInfo rdfpropcheckinfo = getNameProperty(ConceptType.RDFPROPERTY, conceptUri, expression);
TypeCheckInfo rdfpropcheckinfo = getNameProperty(qnm, ConceptType.RDFPROPERTY, conceptUri, expression);
if (rdfpropcheckinfo != null) {
return rdfpropcheckinfo;
}
throw new PropertyWithoutRangeException();
throw new PropertyWithoutRangeException(declarationExtensions.getConcreteName(qnm));
}
else if(conceptType.equals(OntConceptType.INSTANCE)){
// this is an instance--if it is already in the ontology we can get its type. If not maybe we can get it from its declaration
Expand Down Expand Up @@ -2083,10 +2086,10 @@ private ConceptName createTypedConceptName(String conceptUri, OntConceptType con
return modelProcessor.createTypedConceptName(conceptUri, conceptType);
}

protected TypeCheckInfo getNameProperty(ConceptType propertyType, String conceptUri, EObject expression) throws DontTypeCheckException, InvalidTypeException {
protected TypeCheckInfo getNameProperty(SadlResource qnm, ConceptType propertyType, String conceptUri, EObject expression) throws DontTypeCheckException, InvalidTypeException {
OntProperty property = theJenaModel.getOntProperty(conceptUri);
if(property == null){
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.UNIDENTIFIED.toString(), expression);
getModelProcessor().addIssueToAcceptor(SadlErrorMessages.UNIDENTIFIED.toString(), qnm != null ? qnm : expression);
if (metricsProcessor != null) {
metricsProcessor.addMarker(null, MetricsProcessor.ERROR_MARKER_URI, MetricsProcessor.UNCLASSIFIED_FAILURE_URI);
}
Expand Down Expand Up @@ -2142,7 +2145,7 @@ else if (isSadlTypedList(first)) {
while (sitr2.hasNext()) {
RDFNode psuper = sitr2.next().getObject();
if (psuper.isResource()) {
TypeCheckInfo superTCInfo = getNameProperty(propertyType, psuper.asResource().getURI(), expression);
TypeCheckInfo superTCInfo = getNameProperty(null, propertyType, psuper.asResource().getURI(), expression);
if (superTCInfo != null) {
sitr2.close();
return superTCInfo;
Expand Down Expand Up @@ -3066,6 +3069,26 @@ private void checkPropertyDomain(OntModel ontModel, OntResource subj, Property p
break;
}
}
//Check for super properties
stmtitr = prop.listProperties();
while (stmtitr.hasNext()) {
if(matchFound){
break;
}
RDFNode obj = stmtitr.nextStatement().getObject();
if(obj.canAs(Property.class)){
StmtIterator stmtitr2 = ontModel.listStatements(obj.as(Property.class), RDFS.domain, (RDFNode)null);
while(stmtitr2.hasNext()){
RDFNode obj2 = stmtitr2.nextStatement().getObject();
if (obj2.isResource()) {
matchFound = checkForPropertyDomainMatch(subj, obj.as(Property.class), obj2.asResource());
}
if (matchFound) {
break;
}
}
}
}
stmtitr.close();
if (subj != null && !matchFound) {
if (varName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@ public class PropertyWithoutRangeException extends Exception {
*
*/
private static final long serialVersionUID = 1L;

private String propID = null;

public PropertyWithoutRangeException(){
super("Property does not have a range");
}

public PropertyWithoutRangeException(String pid) {
super("Property does not have a range");
propID = pid;
}

public String getPropID() {
return propID;
}
}
Loading

0 comments on commit 7c8712b

Please sign in to comment.