Skip to content

Commit

Permalink
improves reporting for when a type coercion in neo goes wrong
Browse files Browse the repository at this point in the history
see #34
  • Loading branch information
matentzn committed Jul 14, 2020
1 parent c540b9a commit d5c4fce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
7 changes: 7 additions & 0 deletions src/main/java/ebi/spot/neo4j2owl/N2OLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public void log(Object msg) {
public void error(Object msg) {
//log.error(msg.toString());
System.err.println("ERROR: "+msg + " " + getTimePassed());
errorInterpreter(msg.toString());
}

private void errorInterpreter(String msg) {
if(msg.contains("Property values can only be of primitive types or arrays thereof")) {
System.err.println("Debugging assistant: This error often (not always!) occurs in conjunction with the dynamic type coercing function (example: properties with more than 1 datatype associated with it in the ontology, say 200 Boolean values and 10 String values, get coerced to Boolean). Search the log the the 'Typing report for' the property for more information.");
}
}

public void info(Object msg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ private String computeDatatype(String h) {
return dt_config.get();
} else {
Optional<String> dt_counter = this.relationTypeCounter.computeTypeForRelation(h);
String explanation = this.relationTypeCounter.getExplanationForTyping(h);
if(dt_counter.isPresent()) {
return dt_counter.get();
String dt = dt_counter.get();
log.info(h+ " relation was assigned to the '"+dt+"' datatype." );
log.info(explanation);
return dt;
} else {
String explanation = this.relationTypeCounter.getExplanationForTyping(h);
log.warning("Cant decide datatype of annotation property. Ambiguous typing for "+h+": "+explanation);
}
}
Expand Down
35 changes: 5 additions & 30 deletions src/main/java/ebi/spot/neo4j2owl/importer/N2OUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,14 @@ public class N2OUtils {
private static final OWLDataFactory df = OWLManager.getOWLDataFactory();
private static final DLSyntaxObjectRenderer ren = new DLSyntaxObjectRenderer();

public static <T> T inTx(GraphDatabaseService db, Callable<T> callable) {
try {
return inTxFuture(DEFAULT, db, callable).get();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("Error executing in separate transaction: "+e.getMessage(), e);
}
}

public static Set<String> getLabels(OWLEntity c, OWLOntology o) {
Set<String> labels = new HashSet();
Iterator var3 = EntitySearcher.getAnnotations(c, o, df.getRDFSLabel()).iterator();
static Set<String> getLabels(OWLEntity c, OWLOntology o) {
Set<String> labels = new HashSet<>();

while(var3.hasNext()) {
OWLAnnotation a = (OWLAnnotation)var3.next();
for (OWLAnnotation a : EntitySearcher.getAnnotations(c, o, df.getRDFSLabel())) {
OWLAnnotationValue value = a.getValue();
if (value instanceof OWLLiteral) {
String val = ((OWLLiteral)value).getLiteral();
String val = ((OWLLiteral) value).getLiteral();
labels.add(val);
}
}
Expand All @@ -70,6 +59,7 @@ public static Object extractValueFromOWLAnnotationValue(OWLAnnotationValue aval)
} else {
return literal.getLiteral();
}
// "xsd:long", literal.getDatatypePrefixedName()
}
return "neo4j2owl_UnknownValue";
}
Expand All @@ -85,21 +75,6 @@ public static void writeToFile(File dir, Map<String, List<String>> dataout, Stri
}
}


public static <T> Future<T> inTxFuture(ExecutorService pool, GraphDatabaseService db, Callable<T> callable) {
try {
return pool.submit(() -> {
try (Transaction tx = db.beginTx()) {
T result = callable.call();
tx.success();
return result;
}
});
} catch (Exception e) {
throw new RuntimeException("Error executing in separate transaction", e);
}
}

public final static ExecutorService DEFAULT = createDefaultPool();

public static ExecutorService createDefaultPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ String getExplanationForTyping(String rel) {
Map<String, Integer> ctm = mapCounter.get(rel);
int sum = ctm.values().stream().mapToInt(Integer::intValue).sum();
if(sum>0) {
if(ctm.keySet().size()!=1) {
s.append("STRONG WARNING: More than one type recorded, ambiguous typing! ");
}
for (String type : ctm.keySet()) {
Integer ct = ctm.get(type);
double d = ((double) ct) / sum;
s.append(type).append(": ").append(ctm.get(type)).append(" (").append(String.format("%.2f", d)).append(");");
s.append(type).append(": ").append(ctm.get(type)).append(" (").append(String.format("%.2f", d)).append("); ");
}
} else {
s.append("No typing information recorded.");
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/ebi/spot/neo4j2owl/N2OProcedureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ private void runSmallTest(String ontologyUrl, String configUrl) throws KernelExc

Result importResult = db.execute(call);
Map<String, Object> resMap = importResult.next();
assertEquals(28L, resMap.get("elementsLoaded"));
assertEquals(9L, resMap.get("classesLoaded"));
assertEquals(32L, resMap.get("elementsLoaded"));
assertEquals(12L, resMap.get("classesLoaded"));
assertEquals("", resMap.get("extraInfo"));
assertEquals(9L, db.execute("MATCH (n:Class) RETURN count(n) AS count").next().get("count"));
assertEquals(12L, db.execute("MATCH (n:Class) RETURN count(n) AS count").next().get("count"));
db.shutdown();
}

Expand Down Expand Up @@ -93,10 +93,10 @@ public void owl2Export() throws Exception {
Result exportResult = db.execute("CALL ebi.spot.neo4j2owl.exportOWL()");
Map<String,Object> resMapExport = exportResult.next();

assertEquals(28L, resMap.get("elementsLoaded"));
assertEquals(9L, resMap.get("classesLoaded"));
assertEquals(32L, resMap.get("elementsLoaded"));
assertEquals(12L, resMap.get("classesLoaded"));
assertEquals("", resMap.get("extraInfo"));
assertEquals(9L, db.execute("MATCH (n:Class) RETURN count(n) AS count").next().get("count"));
assertEquals(12L, db.execute("MATCH (n:Class) RETURN count(n) AS count").next().get("count"));

String ontologyString = (String)resMapExport.get("o");
OWLOntologyManager man1 = OWLManager.createOWLOntologyManager();
Expand Down

0 comments on commit d5c4fce

Please sign in to comment.