Package org.apache.stanbol.entityhub.servicesapi.yard

Examples of org.apache.stanbol.entityhub.servicesapi.yard.Yard


    @Test
    public void testFieldQueryWithSimilarityConstraint() throws YardException {
        // NOTE: this does not test if the updated view of the representation is
        // stored, but only that the update method works correctly
        Yard yard = getYard();
        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"));
        query.setConstraint(filterfield, new TextConstraint(Arrays.asList("other")));
        results = yard.find(query);
        assertEquals(1, results.size());
        it = results.iterator();
        first = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2", first.getId());
    }
View Full Code Here


     *
     * @return the Yard used by this Cache or <code>null</code> if currently not
     *         available.
     */
    public Yard getCacheYard() {
        Yard yard = (Yard) yardTracker.getService();
        if (yard != null && !initWithYard) {
            try {
                initWithCacheYard(yard);
            } catch (YardException e) {
                //this case can be recovered because initWithYard will not be
View Full Code Here

     * Cache!
     * --------------------------------------------------------------------------
     */
    @Override
    public Representation store(Representation representation) throws IllegalArgumentException, YardException {
        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            return yard.store(applyCacheMappings(yard, representation));
        }
    }
View Full Code Here

        }
    }

    @Override
    public Representation update(Representation representation) throws YardException, IllegalArgumentException {
        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            return yard.update(applyCacheMappings(yard, representation));
        }
    }
View Full Code Here

     * Methods that forward calls to the Yard configured for this Cache
     * --------------------------------------------------------------------------
     */
    @Override
    public Representation create() throws YardException {
        Yard yard = getCacheYard();
        if (yard == null) {
            return createRepresentation(null);
        } else {
            return yard.create();
        }
    }
View Full Code Here

        }
    }

    @Override
    public Representation create(String id) throws IllegalArgumentException, YardException {
        Yard yard = getCacheYard();
        if (yard == null) {
            return createRepresentation(id);
        } else {
            return yard.create(id);
        }
    }
View Full Code Here

        return InMemoryValueFactory.getInstance().createRepresentation(id);
    }

    @Override
    public QueryResultList<Representation> find(FieldQuery query) throws YardException, IllegalArgumentException {
        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            return yard.find(query);
        }
    }
View Full Code Here

        }
    }

    @Override
    public QueryResultList<String> findReferences(FieldQuery query) throws YardException, IllegalArgumentException {
        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            return yard.findReferences(query);
        }
    }
View Full Code Here

        }
    }

    @Override
    public QueryResultList<Representation> findRepresentation(FieldQuery query) throws YardException, IllegalArgumentException {
        Yard yard = getCacheYard();
        if (yard == null) {
            throw new YardException(String.format("The Yard %s for this cache is currently not available", yardId));
        } else {
            return yard.findRepresentation(query);
        }
    }
View Full Code Here

        return yardId + " Cache";
    }

    @Override
    public FieldQueryFactory getQueryFactory() {
        Yard yard = getCacheYard();
        if (yard == null) {
            return DefaultQueryFactory.getInstance();
        } else {
            return yard.getQueryFactory();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.yard.Yard

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.