Split out selector implementation to address java compilation issue
This commit is contained in:
parent
39b2399e3c
commit
70ba4cedab
2 changed files with 35 additions and 36 deletions
|
@ -16,6 +16,7 @@ import org.apache.jena.rdf.model.Property;
|
|||
import org.apache.jena.rdf.model.RDFNode;
|
||||
import org.apache.jena.rdf.model.Resource;
|
||||
import org.apache.jena.rdf.model.Selector;
|
||||
import org.apache.jena.rdf.model.SimpleSelector;
|
||||
import org.apache.jena.rdf.model.Statement;
|
||||
import org.apache.jena.rdf.model.StmtIterator;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
|
||||
|
@ -191,42 +192,7 @@ public class RDFServiceVirtuoso extends RDFServiceSparql {
|
|||
// If the object is a numeric literal
|
||||
if (object.isLiteral() && isNumeric(object.asLiteral().getDatatypeURI())) {
|
||||
// Find a matching statement in the triple store, based on normalized numeric values
|
||||
StmtIterator matching = fromTripleStoreModel.listStatements(new Selector() {
|
||||
@Override
|
||||
public boolean test(Statement statement) {
|
||||
RDFNode objectToMatch = statement.getObject();
|
||||
|
||||
// Both values are numeric, so compare them as parsed doubles
|
||||
if (objectToMatch.isLiteral()) {
|
||||
String num1 = object.asLiteral().getString();
|
||||
String num2 = objectToMatch.asLiteral().getString();
|
||||
|
||||
return Double.parseDouble(num1) == Double.parseDouble(num2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimple() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource getSubject() {
|
||||
return subject.asResource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property getPredicate() {
|
||||
return predicate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RDFNode getObject() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
StmtIterator matching = fromTripleStoreModel.listStatements(new VirtuosoDoubleSelector(subject.asResource(), predicate, object));
|
||||
|
||||
// For every matching statement
|
||||
// Rewrite the object as the one in the file model (they are the same, just differ in datatype)
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.rdfservice.impl.virtuoso;
|
||||
|
||||
import org.apache.jena.rdf.model.Property;
|
||||
import org.apache.jena.rdf.model.RDFNode;
|
||||
import org.apache.jena.rdf.model.Resource;
|
||||
import org.apache.jena.rdf.model.SimpleSelector;
|
||||
import org.apache.jena.rdf.model.Statement;
|
||||
|
||||
public class VirtuosoDoubleSelector extends SimpleSelector {
|
||||
public VirtuosoDoubleSelector() {
|
||||
}
|
||||
|
||||
public VirtuosoDoubleSelector(Resource subject, Property predicate, RDFNode object) {
|
||||
super(subject, predicate, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Statement statement) {
|
||||
RDFNode objectToMatch = statement.getObject();
|
||||
|
||||
// Both values are numeric, so compare them as parsed doubles
|
||||
if (objectToMatch.isLiteral()) {
|
||||
String num1 = object.asLiteral().getString();
|
||||
String num2 = objectToMatch.asLiteral().getString();
|
||||
|
||||
return Double.parseDouble(num1) == Double.parseDouble(num2);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue