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

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


     */
    private static MGraph executeLDPath(RDFBackend<Object> backend,
                                 String ldpath,
                                 Set<String> contexts ) throws LDPathParseException {
        MGraph data = new IndexedMGraph();
        RdfValueFactory vf = new RdfValueFactory(data);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        Program<Object> program = ldPath.parseProgram(getReader(ldpath));
        if(log.isDebugEnabled()){
            log.debug("Execute on Context(s) '{}' LDPath program: \n{}",
                contexts,program.getPathExpression(backend));
        }
        /*
         * NOTE: We do not need to process the Representations returned by
         * EntityhubLDPath#exdecute, because the RdfValueFactory used uses
         * the local variable "MGraph data" to backup all created
         * RdfRepresentation. Because of this all converted data will be
         * automatically added the MGraph. The only thing we need to do is to
         * wrap the MGraph in the response.
         */
        for(String context : contexts){
            ldPath.execute(vf.createReference(context), program);
        }
        return data;
    }
View Full Code Here


     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(Entityhub entityhub,FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        EntityhubBackend backend = new EntityhubBackend(entityhub);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

        LiteralFactory lf = LiteralFactory.getInstance();
        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();
View Full Code Here

        LiteralFactory lf = LiteralFactory.getInstance();
        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();
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

     * @param headers the http headers of the request
     * @return the response
     */
    private Response executeLDPathQuery(FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
        QueryResultList<Representation> result;
        ValueFactory vf = new RdfValueFactory(new IndexedMGraph());
        SiteBackend backend = new SiteBackend(site,vf);
        EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
        //copy the selected fields, because we might need to delete some during
        //the preparation phase
        Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
View Full Code Here

     * Transforms a site to a Representation that can be serialised
     * @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());
View Full Code Here

        // (3) Parse the Representtion(s) form the entity stream
        if(content.getMediaType().isCompatible(MediaType.APPLICATION_JSON_TYPE)){
            //parse from json
            throw new UnsupportedOperationException("Parsing of JSON not yet implemented :(");
       } else if(isSupported(content.getMediaType())){ //from RDF serialisation
            RdfValueFactory valueFactory = RdfValueFactory.getInstance();
            Map<String,Representation> representations = new HashMap<String,Representation>();
            Set<NonLiteral> processed = new HashSet<NonLiteral>();
            Parser parser = ContextHelper.getServiceFromContext(Parser.class, servletContext);
            MGraph graph = new IndexedMGraph();
            try {
                parser.parse(graph,content.getEntityStream(), content.getMediaType().toString());
            } catch (UnsupportedParsingFormatException e) {
                //String acceptedMediaType = httpHeaders.getFirst("Accept");
                //throw an internal server Error, because we check in
                //isReadable(..) for supported types and still we get here a
                //unsupported format -> therefore it looks like an configuration
                //error the server (e.g. a missing Bundle with the required bundle)
                String message = "Unable to create the Parser for the supported format"
                    +content.getMediaType()+" ("+e+")";
                log.error(message,e);
                throw new WebApplicationException(
                    Response.status(Status.INTERNAL_SERVER_ERROR).
                    entity(message).
                    header(HttpHeaders.ACCEPT, acceptedMediaType).build());
            } catch (Exception e){
                String message = "Unable to create the Parser for the supported format "
                    +content.getMediaType()+" ("+e+")";
                log.error(message,e);
                throw new WebApplicationException(
                    Response.status(Status.INTERNAL_SERVER_ERROR).
                    entity(message).
                    header(HttpHeaders.ACCEPT, acceptedMediaType).build());
               
            }
            for(Iterator<Triple> st = graph.iterator();st.hasNext();){
                NonLiteral resource = st.next().getSubject();
                if(resource instanceof UriRef && processed.add(resource)){
                    //build a new representation
                    representations.put(((UriRef)resource).getUnicodeString(),
                        valueFactory.createRdfRepresentation((UriRef)resource, graph));
                }
            }
            return representations;
        } else { //unsupported media type
            String message = String.format(
View Full Code Here

            }
        }
        // now write the results (requires write lock)
        ci.getLock().writeLock().lock();
        try {
            RdfValueFactory factory = RdfValueFactory.getInstance();
            Map<String,Representation> entityData = new HashMap<String,Representation>();
            for (Entry<NamedEntity,List<Suggestion>> entitySuggestions : suggestions.entrySet()) {
                List<UriRef> subsumed = textAnnotations.get(entitySuggestions.getKey());
                List<NonLiteral> annotationsToRelate = new ArrayList<NonLiteral>(subsumed);
                annotationsToRelate.add(entitySuggestions.getKey().getEntity());
                for (Suggestion suggestion : entitySuggestions.getValue()) {
                    log.debug("Add Suggestion {} for {}", suggestion.getEntity().getId(),
                        entitySuggestions.getKey());
                    EnhancementRDFUtils.writeEntityAnnotation(this, literalFactory, graph, ci.getUri(),
                        annotationsToRelate, suggestion, nameField,
                        // TODO: maybe we want labels in a different
                        // language than the
                        // language of the content (e.g. Accept-Language
                        // header)?!
                        contentLangauge == null ? DEFAULT_LANGUAGE : contentLangauge);
                    if (dereferenceEntities) {
                        entityData.put(suggestion.getEntity().getId(), suggestion.getEntity()
                                .getRepresentation());
                    }
                }
            }
            // if dereferneceEntities is true the entityData will also contain
            // all
            // Representations to add! If false entityData will be empty
            for (Representation rep : entityData.values()) {
                graph.addAll(factory.toRdfRepresentation(rep).getRdfGraph());
            }
        } finally {
            ci.getLock().writeLock().unlock();
        }
View Full Code Here

TOP

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

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.