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

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


        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 =
View Full Code Here


     * Used by {@link #testRetrival()} to validate that an Entity is correctly
     * retrieved by the tested {@link ClerezzaYard}s.
     * @param entity key - URI; value - expected RDF data
     */
    private void validateEntity(ClerezzaYard yard, Entry<UriRef,TripleCollection> entity) {
        Representation rep = yard.getRepresentation(entity.getKey().getUnicodeString());
        assertNotNull("The Representation for "+entity.getKey()
            + "is missing in the "+yard.getId(), rep);
        assertTrue("RdfRepresentation expected", rep instanceof RdfRepresentation);
        TripleCollection repGraph = ((RdfRepresentation)rep).getRdfGraph();
        for(Iterator<Triple> triples = entity.getValue().iterator();triples.hasNext();){
View Full Code Here

    @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
        /*
         * The triple within this Statement is internally used to "mark" the
         * URI of the Representation as
         */
        test.add(RDF.type.getUnicodeString(), representationType);
    }
View Full Code Here

    @SuppressWarnings({"unchecked","rawtypes"})
    @Override
    public Representation process(Representation source) {
        Object context = backend.createURI(source.getId());
        Representation result  = appendMode ? source : vf.createRepresentation(source.getId());
        /*
         * NOTE: LDPath will return Node instances of the RDFRepositroy if no
         * transformation is defined for a statement (line) in the configured
         * LDpath program (the ":: xsd:int" at the end). this Nodes need to be
         * converted to valid Entityhub Representation values.
         * As we can not know the generic type used by the RDFRepository
         * implementation of the indexing source this is a little bit tricky.
         * What this does is:
         *   - for URIs it creates References
         *   - for plain literal it adds natural texts
         *   - for typed literals it uses the NodeTransformer registered with
         *     the LDPath (or more precise the Configuration object parsed to
         *     the LDPath in the constructor) to transform the values to
         *     Java objects. If no transformer is found or an Exeption occurs
         *     than the lexical form is used and added as String to the
         *     Entityhub.
         */
        Map<String,Collection<Object>> resultMap = (Map<String,Collection<Object>>)program.execute(backend, context);
        for(Entry<String,Collection<Object>> entry : resultMap.entrySet()){
            NodeTransformer fieldTransformer = program.getField(entry.getKey()).getTransformer();
            if(fieldTransformer == null || fieldTransformer instanceof IdentityTransformer<?>){
                //we need to convert the RDFBackend Node to an Representation object
                for(Object value : entry.getValue()){
                    if(backend.isURI(value)){
                        result.addReference(entry.getKey(), backend.stringValue(value));
                    } else if(backend.isLiteral(value)){ //literal
                        Locale locale = backend.getLiteralLanguage(value);
                        if(locale != null){ //text with language
                            String lang = locale.getLanguage();
                            result.addNaturalText(entry.getKey(), backend.stringValue(value),
                                lang.isEmpty() ? null : lang);
                        } else { // no language
                            URI type = backend.getLiteralType(value);
                            if(type != null){ //typed literal -> need to transform
                                NodeTransformer nt = transformer.get(type.toString());
                                if(nt != null){ //add typed literal
                                    try {
                                        result.add(entry.getKey(), nt.transform(backend, value));
                                    } catch (RuntimeException e) {
                                       log.info("Unable to transform {} to dataType {} -> will use lexical form",value,type);
                                       result.add(entry.getKey(),backend.stringValue(value));
                                    }
                                } else { //no transformer
                                    log.info("No transformer for type {} -> will use lexical form",type);
                                    result.add(entry.getKey(),backend.stringValue(value));
                                   
                                }
                            } else { //no langauge and no type -> literal with no language
                                result.addNaturalText(entry.getKey(), backend.stringValue(value));
                            }
                        }
                    } else { //bNode
                        log.info("Ignore bNode {} (class: {})",value,value.getClass());
                    }
                } //end for all values
            } else { //already a transformed values
                result.add(entry.getKey(), entry.getValue()); //just add all values
            }
        }
        return result;
    }
View Full Code Here

    @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
        /*
         * The triple within this Statement is internally used to "mark" the
         * URI of the Representation as
         */
        test.add(NamespaceEnum.rdf+"type", representationType);
    }
View Full Code Here

        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

     */
    @Test
    public void testStoreToContextEnabledYard() throws YardException{
        //add a new entity to yard 2
        String context2added = "http://www.test.org/addedEntity";
        Representation rep = RdfValueFactory.getInstance().createRepresentation(
            context2added);
        rep.addReference(rdfType.stringValue(), skosConcept.stringValue());
        rep.addNaturalText(skosPrefLabel.stringValue(), "added Entity", "en");
        rep.addNaturalText(skosPrefLabel.stringValue(), "hinzugefüte Entity", "de");
        yard2.store(rep);
        //test visibility to other yards
        Assert.assertFalse(yard1.isRepresentation(context2added));
        Assert.assertTrue(yard2.isRepresentation(context2added));
        Assert.assertTrue(unionYard.isRepresentation(context2added));
View Full Code Here

     * retrieved by the tested {@link SesameYard}s.
     * @param entity key - URI; value - expected RDF data
     * @throws YardException
     */
    private void validateEntity(Yard yard, URI subject) throws YardException {
        Representation rep = yard.getRepresentation(subject.stringValue());
        assertNotNull("The Representation for "+subject
            + "is missing in the "+yard.getId(), rep);
        assertTrue("RdfRepresentation expected", rep instanceof RdfRepresentation);
        //check the RDF type to validate that some data are present
        assertEquals(skosConcept.stringValue(), rep.getFirstReference(rdfType.stringValue()).getReference());
    }
View Full Code Here

                entity("The Entityhub is currently unavailable.")
                .header(HttpHeaders.ACCEPT, accepted).build();
        }
        //(1) if an id is parsed we need to ignore all other representations
        if(id != null && !"*".equals(id)){
            Representation r = parsed.get(id);
            if(r == null){
                return Response.status(Status.BAD_REQUEST)
                .entity(String.format("Parsed RDF data do not contain any "
                    + "Information about the parsed id '%s'",id))
                    .header(HttpHeaders.ACCEPT, accepted).build();
View Full Code Here

        }
        RepositoryConnection con = null;
        try {
            con = repository.getConnection();
            con.begin();
            Representation rep = getRepresentation(con, sesameFactory.createURI(id), true);
            con.commit();
            return rep;
        } catch (RepositoryException e) {
            throw new YardException("Unable to get Representation "+id, e);
        } finally {
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.