diff --git a/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java b/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java index 66e0a0bd..93f014ae 100644 --- a/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java +++ b/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java @@ -91,8 +91,6 @@ public class CommandLineInterface { private static final Logger LOGGER = Logger.getLogger(CommandLineInterface.class); public static void main(String[] args) throws Exception { - ShexSchema schema = GenParser.parseSchema(new File("/Users/benjamingood/GitHub/GO_Shapes/shapes/go-cam-shapes.shex").toPath()); - reportSystemParams(); Options main_options = new Options(); diff --git a/minerva-core/src/main/java/org/geneontology/minerva/validation/ShexValidator.java b/minerva-core/src/main/java/org/geneontology/minerva/validation/ShexValidator.java index 76c0bb46..4602a827 100644 --- a/minerva-core/src/main/java/org/geneontology/minerva/validation/ShexValidator.java +++ b/minerva-core/src/main/java/org/geneontology/minerva/validation/ShexValidator.java @@ -51,6 +51,7 @@ import fr.inria.lille.shexjava.schema.abstrsynt.TCProperty; import fr.inria.lille.shexjava.schema.abstrsynt.TripleConstraint; import fr.inria.lille.shexjava.schema.abstrsynt.TripleExpr; +import fr.inria.lille.shexjava.schema.abstrsynt.TripleExprRef; import fr.inria.lille.shexjava.schema.parsing.GenParser; import fr.inria.lille.shexjava.util.Pair; import fr.inria.lille.shexjava.validation.RecursiveValidation; @@ -174,7 +175,7 @@ public ShexValidationReport runShapeMapValidation(Model test_model, boolean stre shapes.removeAll(shapes_to_remove); node_s_shapes.put(node, shapes); } - + for(Resource focus_node_resource : node_s_shapes.keySet()) { Set shape_nodes = node_s_shapes.get(focus_node_resource); for(String shapelabel : shape_nodes) { @@ -272,7 +273,7 @@ public Set checkForExtraProperties(Resource node_r, Model model, Set violations = new HashSet(); Set allowed_properties = this.shape_expected_property_ranges.get(shape_label).keySet(); Set actual_properties = new HashSet(); - Map prop_value = new HashMap(); //don't really care if there are multiple values, one will do. + Map prop_value = new HashMap(); //don't really care if there are multiple values, one will do. String sparql = "select distinct ?prop ?value where{ <"+node_r.getURI()+"> ?prop ?value }"; QueryExecution qe = QueryExecutionFactory.create(sparql, model); ResultSet results = qe.execSelect(); @@ -280,14 +281,8 @@ public Set checkForExtraProperties(Resource node_r, Model model, QuerySolution qs = results.next(); Resource prop = qs.getResource("prop"); RDFNode value = qs.get("value"); - String v = "value"; - if(value.isResource()) { - v = value.asResource().getURI(); - }else if(value.isLiteral()) { - v = value.asLiteral().getString(); - } actual_properties.add(prop.getURI()); - prop_value.put(prop.getURI(), v); + prop_value.put(prop.getURI(), value); } qe.close(); actual_properties.removeAll(allowed_properties); @@ -295,19 +290,29 @@ public Set checkForExtraProperties(Resource node_r, Model model, ShexViolation extra = new ShexViolation(getCurie(node_r.getURI())); Set explanations = new HashSet(); for(String prop : actual_properties) { - String value = prop_value.get(prop); + String value = "value"; + boolean value_is_uri = false; + if(prop_value.get(prop).isResource()) { + value = prop_value.get(prop).asResource().getURI(); + value_is_uri = true; + }else if(prop_value.get(prop).isLiteral()) { + value = prop_value.get(prop).asLiteral().getString(); + } ShexExplanation extra_explain = new ShexExplanation(); extra_explain.setShape(getCurie(shape_label.stringValue())); - String object = value; Set intended_range_shapes = new HashSet(); //For this CLOSED test, no shape fits in intended. Any use of the property here would be incorrect. intended_range_shapes.add("owl:Nothing"); Set node_types = getNodeTypes(model, node_r.getURI()); - Set object_types = getNodeTypes(model, value); + Set object_types = null; //TODO consider here. extra info but not really meaningful - anything in the range would be wrong. - Set matched_range_shapes = getAllMatchedShapes(value, shex_model_validator); + Set matched_range_shapes = null; + if(value_is_uri) { + object_types = getNodeTypes(model, value); + matched_range_shapes = getAllMatchedShapes(value, shex_model_validator); + } String report_prop = getCurie(prop); - ShexConstraint c = new ShexConstraint(object, report_prop, intended_range_shapes, node_types, object_types); + ShexConstraint c = new ShexConstraint(value, report_prop, intended_range_shapes, node_types, object_types); c.setMatched_range_shapes(matched_range_shapes); Set cs = new HashSet(); cs.add(c); @@ -390,6 +395,7 @@ public Model enrichSuperClasses(Model model) { } public Set getNodeTypes(Model model, String node_uri) { + String getOntTerms = "PREFIX rdf: " + "PREFIX owl: " @@ -414,6 +420,7 @@ public Set getNodeTypes(Model model, String node_uri) { } qe.close(); } catch(QueryParseException e){ + LOGGER.error(getOntTerms); e.printStackTrace(); } @@ -482,21 +489,30 @@ private Set getUnmetConstraints(Resource focus_node, String shap } } if(!good) { - String object = obj.toString(); - Set object_types = getNodeTypes(model, object); - String property = prop.toString(); - object = getCurie(object); - property = getCurie(property); - Set expected = new HashSet(); - for(String e : expected_property_ranges.get(prop_uri)) { - String curie_e = getCurie(e); - expected.add(curie_e); - } - ShexConstraint constraint = new ShexConstraint(object, property, expected, node_types, object_types); - //return all shapes that are matched by this node for explanation - Set obj_matched_shapes = getAllMatchedShapes(range_obj, shex_model_validator); - constraint.setMatched_range_shapes(obj_matched_shapes); - unmet_constraints.add(constraint); + if(obj.isURIResource()) { + String object = obj.toString(); + Set object_types = getNodeTypes(model, obj.toString()); + + String property = prop.toString(); + object = getCurie(object); + property = getCurie(property); + Set expected = new HashSet(); + for(String e : expected_property_ranges.get(prop_uri)) { + String curie_e = getCurie(e); + expected.add(curie_e); + } + ShexConstraint constraint = new ShexConstraint(object, property, expected, node_types, object_types); + //return all shapes that are matched by this node for explanation + Set obj_matched_shapes = getAllMatchedShapes(range_obj, shex_model_validator); + constraint.setMatched_range_shapes(obj_matched_shapes); + unmet_constraints.add(constraint); + }else { + ShexConstraint constraint = new ShexConstraint(obj.toString(), getCurie(prop.toString()), null, node_types, null); + //return all shapes that are matched by this node for explanation + Set obj_matched_shapes = getAllMatchedShapes(range_obj, shex_model_validator); + constraint.setMatched_range_shapes(obj_matched_shapes); + unmet_constraints.add(constraint); + } } } } @@ -609,6 +625,9 @@ public Map> getPropertyRangeMap(TripleExpr texp, Map