Package org.apache.stanbol.entityhub.model.clerezza

Examples of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation


                } else {
                    return null;
                }
            }
            //get the graph for the Representation and add it to the store
            RdfRepresentation toAdd = ((RdfValueFactory)getValueFactory()).toRdfRepresentation(representation);
            //log.info("  > add "+toAdd.size()+" triples to Yard "+getId());
            Iterator<Triple> it = toAdd.getRdfGraph().filter(toAdd.getNode(), null, null);
            if(!it.hasNext()){
                //TODO: Note somewhere that this Triple is reserved and MUST NOT
                //      be used by externally.
                graph.add(new TripleImpl(toAdd.getNode(), MANAGED_REPRESENTATION, TRUE_LITERAL));
            } else {
                while(it.hasNext()){
                    graph.add(it.next());
                }
            }
View Full Code Here


        }
    }
   
    @Test
    public void testModificationsOnReadWirteYard() throws YardException{
        RdfRepresentation rep = RdfValueFactory.getInstance().createRepresentation(
            "http://www.test.org/addedEntity");
        rep.addReference(RDF.type.getUnicodeString(), SKOS.Concept.getUnicodeString());
        rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "added Entity", "en");
        rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "hinzugefüte Entity", "de");
       
        readwriteYard.store(rep);
        //test that the data where added and modified in the read/wirte grpah
        validateEntity(readwriteYard,
            singletonMap(rep.getNode(), rep.getRdfGraph()).entrySet().iterator().next());
        readwriteYard.remove(rep.getId());
        Assert.assertNull("Representation "+rep.getId()+" was not correctly "
            + "deleted from "+readwriteYard.getId(),
            readwriteYard.getRepresentation(rep.getId()));
    }
View Full Code Here

            + "deleted from "+readwriteYard.getId(),
            readwriteYard.getRepresentation(rep.getId()));
    }
    @Test(expected=YardException.class)
    public void testStoreOnReadOnlyYard() throws YardException{
        RdfRepresentation rep = RdfValueFactory.getInstance().createRepresentation(
            "http://www.test.org/addedEntity");
        rep.addReference(RDF.type.getUnicodeString(), SKOS.Concept.getUnicodeString());
        rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "added Entity", "en");
        rep.addNaturalText(SKOS.prefLabel.getUnicodeString(), "hinzugefüte Entity", "de");
        readonlyYard.store(rep);
    }
View Full Code Here

     * @param context
     * @return
     */
    private Representation site2Representation(String id){
        RdfValueFactory valueFactory = RdfValueFactory.getInstance();
        RdfRepresentation rep = valueFactory.createRepresentation(id);
        String namespace = NamespaceEnum.entityhub.getNamespace();
        rep.add(namespace+"localMode", site.supportsLocalMode());
        rep.add(namespace+"supportsSearch", site.supportsSearch());
        SiteConfiguration config = site.getConfiguration();
        rep.add("http://www.w3.org/2000/01/rdf-schema#label", config.getName());
        rep.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", valueFactory.createReference(namespace+"ReferencedSite"));
        if(config.getDescription() != null){
            rep.add("http://www.w3.org/2000/01/rdf-schema#description", config.getDescription());
        }
        if(config.getAttribution() != null){
            rep.add("http://creativecommons.org/ns#attributionName", config.getAttribution());
        }
        if(config.getAttributionUrl() != null){
            rep.add("http://creativecommons.org/ns#attributionURL", config.getAttributionUrl());
        }
        //add the licenses
        if(config.getLicenses() != null){
            int count = 0;
            for(License license : config.getLicenses()){
                String licenseUrl;
                if(license.getUrl() != null){
                    licenseUrl = license.getUrl();
                } else {
                   
                    licenseUrl = id+(!id.endsWith("/")?"/":"")+
                        LICENSE_PATH+'/'+LICENSE_NAME+(count>0?count:"");
                    count++;
                }
                //if defined add the name to dc:license
                if(license.getName() != null){
                    rep.add("http://purl.org/dc/terms/license", licenseUrl);
                }
                //link to the license via cc:license
                rep.add("http://creativecommons.org/ns#license", licenseUrl);
            }
        }
        if(config.getEntityPrefixes() != null){
            for(String prefix : config.getEntityPrefixes()){
                rep.add(namespace+"entityPrefix", prefix);
            }
        } else { //all entities are allowed/processed
            rep.add(namespace+"entityPrefix", "*");
        }
        if(config instanceof ReferencedSiteConfiguration){
            ReferencedSiteConfiguration refConfig = (ReferencedSiteConfiguration)config;
            if(refConfig.getCacheStrategy() != null){
                rep.add(namespace+"cacheStrategy", valueFactory.createReference(namespace+"cacheStrategy-"+refConfig.getCacheStrategy().name()));
            }
            //add the accessUri and queryUri
            if(refConfig.getAccessUri() != null){
                rep.add(namespace+"accessUri", valueFactory.createReference(refConfig.getAccessUri()));
            }
            if(refConfig.getQueryUri() != null){
                rep.add(namespace+"queryUri", valueFactory.createReference(refConfig.getQueryUri()));
            }
        }
        return rep;
    }
View Full Code Here

        }
        return rep;
    }
    private Representation license2Representation(String id, License license) {
        RdfValueFactory valueFactory = RdfValueFactory.getInstance();
        RdfRepresentation rep = valueFactory.createRepresentation(id);
       
        if(license.getName() != null){
            rep.add("http://purl.org/dc/terms/license", license.getName());
            rep.add("http://www.w3.org/2000/01/rdf-schema#label", license.getName());
            rep.add("http://purl.org/dc/terms/title", license.getName());
        }
        if(license.getText() != null){
            rep.add("http://www.w3.org/2000/01/rdf-schema#description", license.getText());
           
        }
        rep.add("http://creativecommons.org/ns#licenseUrl",
            license.getUrl() == null ? id:license.getUrl());
        return rep;
    }
View Full Code Here

        log.debug("Requesting signature of entity {}", entityURI);
        MGraph graph = target != null ? target : new IndexedMGraph();
        // Query the Entity Hub
        Entity signature = referencedSiteManager.getEntity(entityURI);
        if (signature != null) {
            RdfRepresentation rdfSignature = RdfValueFactory.getInstance().toRdfRepresentation(
                signature.getRepresentation());
            graph.addAll(rdfSignature.getRdfGraph());
        }
        return graph;
    }
View Full Code Here

        //A RdfReference needs to be used as context
        RdfReference context = valueFactory.createReference(uri);
        //create the representation that stores results in an intermediate
        //graph (we do not want partial results on an error
        MGraph ldPathResults = new SimpleMGraph();
        RdfRepresentation result = valueFactory.createRdfRepresentation(uri, ldPathResults);
        //execute the LDPath Program and write results to the RDF Graph
        for(at.newmedialab.ldpath.model.fields.FieldMapping<?,Object> mapping : ldpathProgram.getFields()) {
          Collection<?> values;
          try {
            values = mapping.getValues(rdfBackend, context);
            } catch (RuntimeException e){
                throw new DereferenceException(uri, e);
            }
            if(values != null && !values.isEmpty()){
                String fieldName = mapping.getFieldName();
                if(langs.isEmpty()){
                    result.add(fieldName,values);
                } else { //filter for languages
                    for(Object value : values){
                        if((!(value instanceof Text)) ||
                                langs.contains(((Text)value).getLanguage())){
                            result.add(fieldName, value);
                        } //else text with filtered language ... do not add
                    }
                }
            }
        }
View Full Code Here

            fieldMapper = this.fieldMapper;
        }
        //execute the field mappings
        writeLock.lock();
        try {
            RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri, graph);
            fieldMapper.applyMappings(rep, clerezzaRep, valueFactory);
             if(log.isTraceEnabled()){
            log.trace("dereferenced via Mappings {}", ModelUtils.getRepresentationInfo(clerezzaRep));
          }
        } finally {
View Full Code Here

            log.trace("dereferenced all of {}", ModelUtils.getRepresentationInfo(rep));
          }
            if(rep instanceof RdfRepresentation){
                graph.addAll(((RdfRepresentation)rep).getRdfGraph());
            } else {
                RdfRepresentation clerezzaRep = valueFactory.createRdfRepresentation(uri,graph);
                //convert all values for all fields
                for (Iterator<String> fields = rep.getFieldNames(); fields.hasNext();) {
                    String field = fields.next();
                    for (Iterator<Object> fieldValues = rep.get(field); fieldValues.hasNext();) {
                        clerezzaRep.add(field, fieldValues.next());
                    }
                }
            }
        } finally {
            writeLock.unlock();
View Full Code Here

    private static TripleCollection toGraph(Representation rep, Set<UriRef> includeFields, Set<String> languages){
        if (rep instanceof RdfRepresentation) {
            return ((RdfRepresentation) rep).getRdfGraph();
        } else {
            //create the Clerezza Represenation
            RdfRepresentation clerezzaRep = vf.createRepresentation(rep.getId());
            //Copy all values field by field
            for (Iterator<String> fields = rep.getFieldNames(); fields.hasNext();) {
                String field = fields.next();
                if(includeFields == null || includeFields.contains(field)){
                    for (Iterator<Object> fieldValues = rep.get(field); fieldValues.hasNext();) {
                        Object value = fieldValues.next();
                        if(languages == null || //we need not to filter languages
                                !(value instanceof Text) || //filter only Text values
                                languages.contains(((Text)value).getLanguage())){
                            clerezzaRep.add(field, value);
                        }
                    }
                }
            }
            return clerezzaRep.getRdfGraph();
        }
       
    }
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation

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.