diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/tdb/RDFServiceTDB.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/tdb/RDFServiceTDB.java index b2f0995d1..89843a11f 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/tdb/RDFServiceTDB.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/tdb/RDFServiceTDB.java @@ -208,7 +208,7 @@ public class RDFServiceTDB extends RDFServiceJena { ModelSerializationFormat serializationFormat) throws RDFServiceException { return super.isEquivalentGraph(graphURI, - adjustForNonNegativeIntegers(serializedGraph), + adjustForIntegers(serializedGraph), serializationFormat); } @@ -231,25 +231,38 @@ public class RDFServiceTDB extends RDFServiceJena { } /** - * Convert all of the references to "nonNegativeInteger" to "integer" in - * this serialized graph. - * - * This isn't rigorous: it could fail if another property contained the text - * "nonNegativeInteger" in its name, or if that text were used as part of a - * string literal. If that happens before this TDB bug is fixed, we'll need - * to improve this method. - * + * Convert all of the references to integer compatible type to "integer" in the serialized graph. + * + * TDB converts every valid literal that is compatible with xsd:integer to xsd:integer. + * + * This assumes that every literal has been typed validly. But if the type / lexical value aren't matched, + * you've probably got bigger problems. + * * It also isn't scalable: if we wanted real scalability, we would write to * a temporary file as we converted. */ - private InputStream adjustForNonNegativeIntegers(InputStream serializedGraph) + private InputStream adjustForIntegers(InputStream serializedGraph) throws RDFServiceException { try { String raw = IOUtils.toString(serializedGraph, "UTF-8"); - String modified = raw.replace("nonNegativeInteger", "integer"); + String modified = raw; + modified = modified.replaceAll(integerPattern, "^^"); return new ByteArrayInputStream(modified.getBytes("UTF-8")); } catch (IOException e) { throw new RDFServiceException(e); } } + + private final String integerPattern = + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^" + "|" + + "\\^\\^"; }