use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.
the class ResourceAdapterTest method testDouble.
/**
* Test related to STANBOL-698
*/
@Test
public void testDouble() {
Graph graph = new IndexedGraph();
IRI id = new IRI("http://www.example.org/test");
IRI doubleTestField = new IRI("http://www.example.org/field/double");
LiteralFactory lf = LiteralFactory.getInstance();
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Double.NaN)));
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Double.POSITIVE_INFINITY)));
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Double.NEGATIVE_INFINITY)));
RdfValueFactory vf = new RdfValueFactory(graph);
Representation r = vf.createRepresentation(id.getUnicodeString());
Set<Double> expected = new HashSet<Double>(Arrays.asList(Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY));
Iterator<Double> dit = r.get(doubleTestField.getUnicodeString(), Double.class);
while (dit.hasNext()) {
Double val = dit.next();
Assert.assertNotNull(val);
Assert.assertTrue(expected.remove(val));
}
Assert.assertTrue(expected.isEmpty());
}
use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.
the class ResourceAdapterTest method testFloat.
@Test
public void testFloat() {
Graph graph = new IndexedGraph();
IRI id = new IRI("http://www.example.org/test");
IRI doubleTestField = new IRI("http://www.example.org/field/double");
LiteralFactory lf = LiteralFactory.getInstance();
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Float.NaN)));
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Float.POSITIVE_INFINITY)));
graph.add(new TripleImpl(id, doubleTestField, lf.createTypedLiteral(Float.NEGATIVE_INFINITY)));
RdfValueFactory vf = new RdfValueFactory(graph);
Representation r = vf.createRepresentation(id.getUnicodeString());
Set<Float> expected = new HashSet<Float>(Arrays.asList(Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY));
Iterator<Float> dit = r.get(doubleTestField.getUnicodeString(), Float.class);
while (dit.hasNext()) {
Float val = dit.next();
Assert.assertNotNull(val);
Assert.assertTrue(expected.remove(val));
}
Assert.assertTrue(expected.isEmpty());
}
use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.
the class CoolUriDereferencer method dereference.
@Override
public final Representation dereference(String uri) throws IOException {
long start = System.currentTimeMillis();
String format = SupportedFormat.RDF_XML;
InputStream in = dereference(uri, format);
long queryEnd = System.currentTimeMillis();
log.debug(" > DereferenceTime: " + (queryEnd - start));
if (in != null) {
Graph rdfData = new IndexedGraph(parser.parse(in, format, new IRI(getBaseUri())));
long parseEnd = System.currentTimeMillis();
log.debug(" > ParseTime: " + (parseEnd - queryEnd));
return valueFactory.createRdfRepresentation(new IRI(uri), rdfData);
} else {
return null;
}
}
use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.
the class LarqSearcher method find.
@Override
public final QueryResultList<Representation> find(FieldQuery parsedQuery) throws IOException {
long start = System.currentTimeMillis();
final SparqlFieldQuery query = SparqlFieldQueryFactory.getSparqlFieldQuery(parsedQuery);
query.setSparqlEndpointType(SparqlEndpointTypeEnum.LARQ);
String sparqlQuery = query.toSparqlConstruct();
long initEnd = System.currentTimeMillis();
log.debug(" > InitTime: " + (initEnd - start));
log.debug(" > SPARQL query:\n" + sparqlQuery);
InputStream in = SparqlEndpointUtils.sendSparqlRequest(getQueryUri(), sparqlQuery, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE);
long queryEnd = System.currentTimeMillis();
log.debug(" > QueryTime: " + (queryEnd - initEnd));
if (in != null) {
Graph graph;
Graph rdfData = parser.parse(in, SparqlSearcher.DEFAULT_RDF_CONTENT_TYPE, new IRI(getBaseUri()));
if (rdfData instanceof Graph) {
graph = (Graph) rdfData;
} else {
graph = new IndexedGraph(rdfData);
}
long parseEnd = System.currentTimeMillis();
log.debug(" > ParseTime: " + (parseEnd - queryEnd));
return new RdfQueryResultList(query, graph);
} else {
return null;
}
}
use of org.apache.stanbol.commons.indexedgraph.IndexedGraph in project stanbol by apache.
the class RecipesGraphProvider method activate.
@Activate
protected void activate(BundleContext context) {
recipesGraph = new IndexedGraph();
context.addBundleListener(this);
for (Bundle b : context.getBundles()) {
if (b.getState() == Bundle.ACTIVE) {
loadRecipesData(b);
}
}
}
Aggregations