Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.LiteralFactory


        confidence
    }

    private void initOccurrences() {
        MGraph graph = contentItem.getMetadata();
        LiteralFactory lf = LiteralFactory.getInstance();
        Map<UriRef,Collection<NonLiteral>> suggestionMap = new HashMap<UriRef,Collection<NonLiteral>>();
        // 1) get Entity Annotations
        Map<NonLiteral,Map<EAProps,Object>> entitySuggestionMap = new HashMap<NonLiteral,Map<EAProps,Object>>();
        Iterator<Triple> entityAnnotations = graph.filter(null, RDF.type, ENHANCER_ENTITYANNOTATION);
        while (entityAnnotations.hasNext()) {
View Full Code Here


    /**
     * @return an RDF/JSON descriptions of places for the word map widget
     */
    public String getPlacesAsJSON() throws ParseException, UnsupportedEncodingException {
        MGraph g = new IndexedMGraph();
        LiteralFactory lf = LiteralFactory.getInstance();
        MGraph metadata = contentItem.getMetadata();
        for (EntityExtractionSummary p : getPlaceOccurrences()) {
            EntitySuggestion bestGuess = p.getBestGuess();
            if (bestGuess == null) {
                continue;
            }
            UriRef uri = new UriRef(bestGuess.getUri());
            Iterator<Triple> latitudes = metadata.filter(uri, GEO_LAT, null);
            if (latitudes.hasNext()) {
                g.add(latitudes.next());
            }
            Iterator<Triple> longitutes = metadata.filter(uri, GEO_LONG, null);
            if (longitutes.hasNext()) {
                g.add(longitutes.next());
                g.add(new TripleImpl(uri, Properties.RDFS_LABEL, lf.createTypedLiteral(bestGuess.getLabel())));
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        serializer.serialize(out, g, SupportedFormat.RDF_JSON);

View Full Code Here

        }
        return graph;
    }

    private void createPropertiesAsRDF(Node n, NonLiteral subject, MGraph graph) throws RepositoryException {
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        PropertyIterator pit = n.getProperties();
        while (pit.hasNext()) {
            try {
                Property p = pit.nextProperty();
                UriRef pURI = getPropertyURI(p.getName());
                if (pURI == null || excludedProperties.contains(pURI)) {
                    continue;
                }
                List<Object> values = new ArrayList<Object>();
                if (p.isMultiple()) {
                    values.addAll(JCRUtils.getTypedPropertyValues(p.getType(), p.getValues()));
                } else {
                    values.add(JCRUtils.getTypedPropertyValue(p.getType(), p.getValue()));
                }
                for (Object val : values) {
                    /*
                     * As JCR does not support retrieval of values of URI typed properties, object properties
                     * are reflected as String properties in JCR. So, when creating RDF from JCR repository,
                     * currently just look at the value of property starts with "http" prefix.
                     *
                     * TODO: Other dirty workaround may be including some prefixes to the object properties to
                     * identify them
                     *
                     * TODO: Fix this when JCR supports retrieval of URI typed property values
                     */
                    try {
                        String valStr = (String) val;
                        if (valStr.startsWith("http")) {
                            graph.add(new TripleImpl(subject, pURI, new UriRef(valStr)));
                            continue;
                        }
                    } catch (Exception e) {
                        // ignore the exception
                    }
                    graph.add(new TripleImpl(subject, pURI, literalFactory.createTypedLiteral(val)));
                }
            } catch (RepositoryException e) {
                log.warn("Failed to process property of node", e);
            }
        }
View Full Code Here

    @Test
    public void testFloat(){
        MGraph graph = new IndexedMGraph();
        UriRef id = new UriRef("http://www.example.org/test");
        UriRef doubleTestField = new UriRef("http://www.example.org/field/double");
        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));
View Full Code Here

        if (ontologyIri == null) throw new IllegalArgumentException(
                "Cannot build a UriRef resource on an anonymous public key!");
        log.debug("Searching for a meta graph entry for public key:");
        log.debug(" -- {}", publicKey);
        UriRef match = null;
        LiteralFactory lf = LiteralFactory.getInstance();
        TypedLiteral oiri = lf.createTypedLiteral(new UriRef(ontologyIri.toString()));
        TypedLiteral viri = versionIri == null ? null : lf.createTypedLiteral(new UriRef(versionIri
                .toString()));
        for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI_URIREF, oiri); it.hasNext();) {
            Resource subj = it.next().getSubject();
            log.debug(" -- Ontology IRI match found. Scanning");
            log.debug(" -- Resource : {}", subj);
View Full Code Here

                "An anonymous ontology cannot be mapped. A non-anonymous ontology ID must be forged in these cases.");
        Triple tType, tHasOiri = null, tHasViri = null;
        IRI ontologyIRI = publicKey.getOntologyIRI(), versionIri = publicKey.getVersionIRI();
        UriRef entry = buildResource(publicKey);
        tType = new TripleImpl(entry, RDF.type, ENTRY_URIREF);
        LiteralFactory lf = LiteralFactory.getInstance();
        tHasOiri = new TripleImpl(entry, HAS_ONTOLOGY_IRI_URIREF, lf.createTypedLiteral(new UriRef(
                ontologyIRI.toString())));
        if (versionIri != null) tHasViri = new TripleImpl(entry, HAS_VERSION_IRI_URIREF,
                lf.createTypedLiteral(new UriRef(versionIri.toString())));
        synchronized (graph) {
            graph.add(tType);
            if (tHasViri != null) graph.add(tHasViri);
            graph.add(tHasOiri);
        }
View Full Code Here

    public static void addPathAnnotations(String rootPath, List<NonLiteral> candidates, MGraph graph) {
        // first detect root objects
        List<NonLiteral> roots = getRootObjetsOfGraph(candidates, graph);

        // assign paths to children recursively
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        for (NonLiteral root : roots) {
            assignChildrenPaths(rootPath, root, graph, literalFactory, true);
        }
    }
View Full Code Here

    private static void checkDefaultPropertyInitialization(NonLiteral subject,
                                                           UriRef property,
                                                           String value,
                                                           MGraph graph) {
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        String oldValue = RDFBridgeHelper.getResourceStringValue(subject, property, graph);
        if (oldValue.contentEquals("")) {
            graph.add(new TripleImpl(subject, property, literalFactory.createTypedLiteral(value)));
        }
    }
View Full Code Here

        return graph;
    }

    private void putObjectPropertiesIntoGraph(CmisObject o, NonLiteral subject, MGraph metadata, MGraph g) {
        g.addAll(metadata);
        LiteralFactory literalFactory = LiteralFactory.getInstance();

        List<Property<?>> docProps = o.getProperties();
        for (Property<?> p : docProps) {
            PropertyType t = p.getType();
            UriRef pURI = getPropertyURI(p);
            if (pURI == null) {
                continue;
            }

            List<Object> values = new ArrayList<Object>();
            if (p.isMultiValued()) {
                values.addAll(CMISUtils.getTypedPropertyValues(t, p.getValues()));
            } else {
                values.add(CMISUtils.getTypedPropertyValue(t, p.getValue()));
            }

            for (Object val : values) {
                if (val != null) {
                    if (val instanceof UriRef) {
                        g.add(new TripleImpl(subject, pURI, (UriRef) val));
                    } else {
                        g.add(new TripleImpl(subject, pURI, literalFactory.createTypedLiteral(val)));
                    }
                }
            }
        }
        /*
 
View Full Code Here

        if (ontologyIri == null) throw new IllegalArgumentException(
                "Cannot build a UriRef resource on an anonymous public key!");
        log.debug("Searching for a meta graph entry for public key:");
        log.debug(" -- {}", publicKey);
        UriRef match = null;
        LiteralFactory lf = LiteralFactory.getInstance();
        TypedLiteral oiri = lf.createTypedLiteral(new UriRef(ontologyIri.toString()));
        TypedLiteral viri = versionIri == null ? null : lf.createTypedLiteral(new UriRef(versionIri
                .toString()));
        for (Iterator<Triple> it = meta.filter(null, HAS_ONTOLOGY_IRI_URIREF, oiri); it.hasNext();) {
            Resource subj = it.next().getSubject();
            log.debug(" -- Ontology IRI match found. Scanning");
            log.debug(" -- Resource : {}", subj);
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.LiteralFactory

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.