Package org.apache.stanbol.entityhub.servicesapi.model

Examples of org.apache.stanbol.entityhub.servicesapi.model.Representation


            con = repository.getConnection();
            con.begin();
            ArrayList<Representation> added = new ArrayList<Representation>();
            for(Representation representation : representations){
                if(representation != null){
                    Representation stored = store(con, representation,allowCreate,false); //reassign
                    //to check if the store was successful
                    if(stored != null){
                        added.add(stored);
                    } else { //can only be the case if allowCreate==false (update was called)
                        log.warn(String.format("Unable to update Representation %s in Yard %s because it is not present!",
View Full Code Here


    protected final Representation store(Representation representation,boolean allowCreate,boolean canNotCreateIsError) throws IllegalArgumentException, YardException{
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            Representation added = store(con,representation,allowCreate,canNotCreateIsError);
            con.commit();
            return added;
        } catch (RepositoryException e) {
            throw new YardException("Unable to remove parsed Representations", e);
        } catch (IllegalArgumentException e) {
View Full Code Here

    @Test
    public void testUriWithSpaces() throws YardException {
        Yard yard = getYard();
        String id1 = "http://www.example.com/with space";
        String id2 = "http://www.example.com/other";
        Representation test1 = create(id1,true);
        Representation test2 = create(id2,true);
        //now add a label containing space to id2
        test1.addNaturalText(NamespaceEnum.rdfs+"label","expected result","en");
        test2.addNaturalText(NamespaceEnum.rdfs+"label","space","en");
        test2.addNaturalText(NamespaceEnum.rdfs+"comment","URIs with space got separated "
            + "in queries causing parts in URIs after spaces to form full text "
            + "queries instead!","en");
        yard.update(test1);
        yard.update(test2);
        //now try to query for some combination
        assertNull("No Entity with ID 'http://www.example.com/with URIs' expected",
            yard.getRepresentation("http://www.example.com/with URIs"));
        assertNull("No Entity with ID 'http://www.example.com/with' expected",
            yard.getRepresentation("http://www.example.com/with"));
        //no check that lookups do work withspace uris
        Representation result = yard.getRepresentation(id1);
        assertNotNull("Entity with ID 'http://www.example.com/with space' expected",
            result);
        assertEquals("Entity with id '"+id1+"' expected, but got '"
            + result.getId() + "' instead", id1, result.getId());
        //finally test removal of Entities with space
        yard.remove(id1);
        assertNull("Entity with ID 'http://www.example.com/with space' got not deleted",
            yard.getRepresentation(id1));
        //and also clean up the 2nd entity used for the test
View Full Code Here

        Yard yard = getYard();

        String id1 = "urn:yard.test.testFieldQuery:representation.id1";
        String id2 = "urn:yard.test.testFieldQuery:representation.id2";
        String field = "urn:the.field:used.for.testFieldQuery";
        Representation test1 = create(id1, true);
        Representation test2 = create(id2, true);
        // change the representations to be sure to force an update even if the
        // implementation checks for changes before updating a representation
        test1.add(field, "This is the text content of a field with value1.");
        test2.add(field, "This is the text content of a field with value2.");
        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2));
        assertNotNull(updatedIterable);

        FieldQuery query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("text content")));
        QueryResultList<Representation> results = yard.find(query);
        assertEquals(2, results.size());

        // fetch the light / minimal representation
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("value2")));
        results = yard.find(query);
        assertEquals(1, results.size());
        Representation result = results.iterator().next();
        assertEquals("urn:yard.test.testFieldQuery:representation.id2", result.getId());
        assertEquals(null, result.getFirst(field));

        // fetch the full representation
        results = yard.findRepresentation(query);
        assertEquals(1, results.size());
        result = results.iterator().next();
        assertEquals("urn:yard.test.testFieldQuery:representation.id2", result.getId());
        assertEquals("This is the text content of a field with value2.", result.getFirst(field));
    }
View Full Code Here

        String id1 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id1";
        String id2 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2";
        String id3 = "urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id3";
        String similarityfield = NamespaceEnum.rdfs+"comment";
        String filterfield = "urn:the.field:used.for.testFieldQueryWithSimilarityConstraint.filter";
        Representation test1 = create(id1, true);
        Representation test2 = create(id2, true);
        Representation test3 = create(id3, true);
        // change the representations to be sure to force an update even if the
        // implementation checks for changes before updating a representation
        test1.add(similarityfield, "aaaa aaaa aaaa bbbb bbbb cccc cccc dddd dddd");
        test1.add(filterfield, "Some text content");

        test2.add(similarityfield, "aaaa bbbb bbbb bbbb bbbb eeee");
        test2.add(filterfield, "Some other content");

        test3.add(similarityfield, "eeee eeee ffff gggg");
        test3.add(filterfield, "Different content");

        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2, test3));
        assertNotNull(updatedIterable);

        // Perform a first similarity query that looks a lot like the first document
        FieldQuery query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
        QueryResultList<Representation> results = yard.find(query);
        assertEquals(2, results.size());
        Iterator<Representation> it = results.iterator();
        Representation first = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id1", first.getId());
        // assertEquals(0.99, first.getFirst("http://www.iks-project.eu/ontology/rick/query/score"));

        Representation second = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2",
            second.getId());
        // assertEquals(0.80, first.getFirst("http://www.iks-project.eu/ontology/rick/query/score"));

        // combine similarity with traditional filtering
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
View Full Code Here

        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));
        }
View Full Code Here

        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));
        }
View Full Code Here

     */
    private void addResourceDescription(UriRef iri, MGraph mGraph) {
        final Entity entity = siteManager.getEntity(iri.getUnicodeString());
        if (entity != null) {
            final RdfValueFactory valueFactory = new RdfValueFactory(mGraph);
            final Representation representation = entity.getRepresentation();
            if (representation != null) {
                valueFactory.toRdfRepresentation(representation);
            }
            final Representation metadata = entity.getMetadata();
            if (metadata != null) {
                valueFactory.toRdfRepresentation(metadata);
            }
        }
    }
View Full Code Here

   
    @Test
    public void testIncludeConfig(){
        EntityProcessor filter = new FieldValueFilter(nsPrefixProvider,"rdf:type","foaf:Person");
       
        Representation r = getRepresentation(NamespaceEnum.foaf+"Person");
        Assert.assertNotNull(filter.process(r));
       
        r = getRepresentation(NamespaceEnum.skos+"Concept");
        Assert.assertNull(filter.process(r));
       
View Full Code Here

   
    @Test
    public void testExcludeConfig(){
        EntityProcessor filter = new FieldValueFilter(nsPrefixProvider,"rdf:type","*;!foaf:Person");
       
        Representation r = getRepresentation(NamespaceEnum.foaf+"Person");
        Assert.assertNull(filter.process(r));
       
        r = getRepresentation(NamespaceEnum.skos+"Concept");
        Assert.assertNotNull(filter.process(r));
       
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.model.Representation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.