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

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


     * instance is already {@link #close() closed}
     * @return the yard
     * @throws IllegalStateException if the site was already {@link #close() closed}
     */
    protected Yard getYard() {
        Yard yard = this.yard;
        if(yard == null){
            throw new IllegalStateException("This ManagedSite is no longer active");
        }
        return yard;
    }
View Full Code Here


        assertEquals(destination.getClass(), SolrYardIndexingDestination.class);
        //initialise
        assertTrue(destination.needsInitialisation());
        destination.initialise();
        //test that the returned Yard instance is functional
        Yard yard = destination.getYard();
        assertNotNull(yard);
        assertEquals(yard.getClass(), SolrYard.class);
        Representation rep = yard.getValueFactory().createRepresentation("http://www.example.com/entity#123");
        rep.add(NamespaceEnum.rdfs+"label", "test");
        rep.add(NamespaceEnum.rdfs+"description", "Representation to test storage while indexing");
        rep.add(RdfResourceEnum.entityRank.getUri(), Float.valueOf(0.8f));
        yard.store(rep);
        //finalise
        destination.finalise();
        //test the archives
        File expectedSolrArchiveFile =
            new File(config.getDistributionFolder(),config.getName()+".solrindex.zip");
View Full Code Here

     * This tests if this functions as expected
     * @throws YardException
     */
    @Test
    public void testRemovalOfTypeRepresentationStatement() throws YardException {
        Yard yard = getYard();
        ValueFactory vf = yard.getValueFactory();
        Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
        Representation test = create();
        //the rdf:type Representation MUST NOT be within the Representation
        Assert.assertFalse(test.get(RDF.type.getUnicodeString()).hasNext());
        //now add the statement and see if an IllegalStateException is thrown
View Full Code Here

        //override the ldpath instance used for the initialisation with
        //the one using the IndexingDestination
        //this is OK, because parsing ldpath programs anyway does only need
        //the "value factory" role of the RDFBackend and does not actually
        //access any data.
        Yard yard = indexingConfig.getIndexingDestination().getYard();
        YardBackend backend = new YardBackend(yard);
        this.ldPath = new EntityhubLDPath(backend,yard.getValueFactory());
    }
View Full Code Here

     * This tests if this functions as expected
     * @throws YardException
     */
    @Test
    public void testRemovalOfTypeRepresentationStatement() throws YardException {
        Yard yard = getYard();
        ValueFactory vf = yard.getValueFactory();
        Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
        Representation test = create();
        //the rdf:type Representation MUST NOT be within the Representation
        Assert.assertFalse(test.get(NamespaceEnum.rdf+"type").hasNext());
        //now add the statement and see if an IllegalStateException is thrown
View Full Code Here

        con.add(bnode1, property2, value);
        con.add(bnode1, loop1, bnode2);
        con.add(bnode2, loop2, bnode1);
        con.commit();
        con.close();
        Yard yard = getYard();
        Representation rep = yard.getRepresentation(subject.stringValue());
        Assert.assertTrue(rep instanceof RdfRepresentation);
        Model model = ((RdfRepresentation)rep).getModel();
        //Assert for the indirect statements to be present in the model
        Assert.assertFalse(model.filter(null, property2, null).isEmpty());
        Assert.assertFalse(model.filter(null, loop1, null).isEmpty());
View Full Code Here

     * STANBOL-1065</a>
     * @throws YardException
     */
    @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
        yard.remove(id2);
    }
View Full Code Here

   
    @Test
    public void testFieldQuery() 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.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

    @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 null;
        }
    }
    @Override
    public final FieldQueryFactory getQueryFactory() {
        Yard entityhubYard = getYard();
        return entityhubYard==null? //if no yard available
                DefaultQueryFactory.getInstance(): //use the default
                    entityhubYard.getQueryFactory(); //else return the query factory used by the yard
    }
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.