Search in sources :

Example 26 with IndexedGraph

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());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with IndexedGraph

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());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) TripleImpl(org.apache.clerezza.commons.rdf.impl.utils.TripleImpl) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory) LiteralFactory(org.apache.clerezza.rdf.core.LiteralFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with IndexedGraph

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;
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) InputStream(java.io.InputStream) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 29 with IndexedGraph

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;
    }
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Graph(org.apache.clerezza.commons.rdf.Graph) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) RdfQueryResultList(org.apache.stanbol.entityhub.query.clerezza.RdfQueryResultList) InputStream(java.io.InputStream) SparqlFieldQuery(org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph)

Example 30 with IndexedGraph

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);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) IndexedGraph(org.apache.stanbol.commons.indexedgraph.IndexedGraph) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)34 Graph (org.apache.clerezza.commons.rdf.Graph)27 IRI (org.apache.clerezza.commons.rdf.IRI)20 HashSet (java.util.HashSet)9 InputStream (java.io.InputStream)8 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)8 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)8 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)8 Triple (org.apache.clerezza.commons.rdf.Triple)7 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)6 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)5 RdfQueryResultList (org.apache.stanbol.entityhub.query.clerezza.RdfQueryResultList)5 Test (org.junit.Test)5 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)4 RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)4 Entity (org.apache.stanbol.entityhub.servicesapi.model.Entity)4 BeforeClass (org.junit.BeforeClass)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3