Examples of TypedLiteral


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

            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

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

        Set<OWLOntologyID> getVersions(IRI ontologyIri) {
            if (ontologyIri == null) throw new IllegalArgumentException("Cannot get versions for a null IRI.");
            Set<OWLOntologyID> keys = new HashSet<OWLOntologyID>();
            LiteralFactory lf = LiteralFactory.getInstance();
            TypedLiteral iri = lf.createTypedLiteral(new UriRef(ontologyIri.toString()));
            // Exclude aliases.
            for (Iterator<Triple> it = graph.filter(null, HAS_ONTOLOGY_IRI_URIREF, iri); it.hasNext();) {
                Resource sub = it.next().getSubject();
                if (sub instanceof UriRef) keys.add(buildPublicKey((UriRef) sub));
            }
View Full Code Here

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

        if (value instanceof UriRef) {
            return valueFactory.createReference((UriRef) value);
        } else if (value instanceof PlainLiteral) {
            return valueFactory.createText((Literal) value);
        } else if (value instanceof TypedLiteral) {
            TypedLiteral literal = (TypedLiteral) value;
            if (literal.getDataType() == null) { // if no dataType is defined
                // return a Text without a language
                return valueFactory.createText(literal);
            } else {
                XsdDataTypeEnum mapping = RdfResourceUtils.XSD_DATATYPE_VALUE_MAPPING.get(literal.getDataType());
                if (mapping != null) {
                    if (mapping.getMappedClass() != null) {
                        try {
                            return literalFactory.createObject(mapping.getMappedClass(), literal);
                        } catch (RuntimeException e){
                            log.info("Unable to convert Literal value {} to Java Class {} because of {} with message {}",
                                new Object[]{literal,mapping.getMappedClass().getSimpleName(),
                                             e.getClass().getSimpleName(),e.getMessage()});
                            log.trace("Exception:",e);
                            //STANBOL-698: Decide what to do in such cases
                            //(a) throw an exception
                            // throw e;
                            //(b) ignore illegal values
                            //return null;
                            //(c) use the lexical form
                            return literal.getLexicalForm();
                        }
                    } else { // if no mapped class
                        // bypass the LiteralFactory and return the string
                        // representation
                        return literal.getLexicalForm();
                    }
                } else { // if dataType is not supported
                    /*
                     * this could indicate two things: 1) the SimpleLiteralFactory supports a new DataType and
                     * because of that it creates Literals with this Type 2) Literals with this data type
                     * where created by other applications. In the first case one need to update the
                     * enumeration. In the second case using the LexicalForm should be OK Rupert Westenthaler
                     * 2010.10.28
                     */
                    log.warn("Missing Mapping for DataType {} -> return String representation",
                        literal.getDataType().getUnicodeString());
                    return literal.getLexicalForm();
                }
            }
        } else {
            log.warn("Unsupported Resource Type {} -> return String by using the toString method",
                value.getClass());
View Full Code Here

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

    @Test
    public void dateStorage() {
        MGraph graph = getEmptyMGraph();
        Date date = new Date(0);
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
        Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
        graph.add(triple);
        Assert.assertTrue(graph.contains(triple));
    }
View Full Code Here

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

    @Test
    public void dateStorage2() {
        MGraph graph = getEmptyMGraph();
        Date date = new Date(0);
        LiteralFactory literalFactory = LiteralFactory.getInstance();
        TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
        System.out.println(dateLiteral);
        UriRef property = new UriRef("http://example.com/property");
        Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
        graph.add(triple);
View Full Code Here

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

        graph.add(new TripleImpl(id, FOAF_PRIMARY_TOPIC_OF, metaId));
        graph.add(new TripleImpl(metaId, FOAF_PRIMARY_TOPIC, metaId));
        graph.add(new TripleImpl(metaId, RDF.type, FOAF_DOCUMENT));
        //add the site to the metadata
        //TODO: this should be the HTTP URI and not the id of the referenced site
        TypedLiteral siteName = literalFactory.createTypedLiteral(sign.getSite());
        graph.add(new TripleImpl(metaId, EntityToRDF.signSite, siteName));
       
    }
View Full Code Here

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

     * texts without language.
     */
    @Test
    public void testTypedLiteralToTextConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        TypedLiteral stringLiteral = literalFactory.createTypedLiteral("This is a stirng value");
        //also add an integer to test that other typed literals are not used as texts
        TypedLiteral integerLiteral = literalFactory.createTypedLiteral(new Integer(5));
        Representation rep = createRepresentation(null);
        rep.add(field, Arrays.asList(stringLiteral,integerLiteral));
        //test if the literal is returned when asking for natural language text without language
        Iterator<Text> noLangTexts = rep.get(field, (String)null);
        assertTrue(noLangTexts.hasNext());
View Full Code Here

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

    @SuppressWarnings("unchecked")
    @Test
    public void testTypedLiteralToValueConversion(){
        String field = "urn:test.RdfRepresentation:test.field";
        Integer integerValue = 5;
        TypedLiteral integerLiteral = literalFactory.createTypedLiteral(integerValue);
        Date dateValue = new Date();
        TypedLiteral dateLiteeral = literalFactory.createTypedLiteral(dateValue);
        Double doubleValue = Math.PI;
        TypedLiteral doubleLiteral = literalFactory.createTypedLiteral(doubleValue);
        String stringValue = "This is a string literal value";
        TypedLiteral stringLiteral = literalFactory.createTypedLiteral(stringValue);
        Representation rep = createRepresentation(null);
        Collection<TypedLiteral> typedLiterals =
            Arrays.asList(integerLiteral,doubleLiteral,stringLiteral,dateLiteeral);
        rep.add(field, typedLiterals);
       
View Full Code Here

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

        if(value instanceof UriRef){
            return valueFactory.createReference((UriRef)value);
        } else if(value instanceof PlainLiteral){
            return valueFactory.createText((Literal)value);
        } else if(value instanceof TypedLiteral){
            TypedLiteral literal = (TypedLiteral) value;
            if(literal.getDataType() == null){ //if no dataType is defined
                //return a Text without a language
                return valueFactory.createText(literal);
            } else {
                XsdDataTypeEnum mapping = RdfResourceUtils.XSD_DATATYPE_VALUE_MAPPING.get(literal.getDataType());
                if(mapping != null){
                    if(mapping.getMappedClass() != null){
                        return literalFactory.createObject(mapping.getMappedClass(), literal);
                    } else { //if no mapped class
                        //bypass the LiteralFactory and return the string representation
                        return literal.getLexicalForm();
                    }
                } else { //if dataType is not supported
                    /*
                     * this could indicate two things:
                     * 1) the SimpleLiteralFactory supports a new DataType and
                     *    because of that it creates Literals with this Type
                     * 2) Literals with this data type where created by other
                     *    applications.
                     * In the first case one need to update the enumeration. In
                     * the second case using the LexicalForm should be OK
                     * Rupert Westenthaler 2010.10.28
                     */
                    log.warn("Missing Mapping for DataType "+literal.getDataType().getUnicodeString()
                            +" -> return String representation");
                    return literal.getLexicalForm();
                }
            }
        } else {
            log.warn("Unsupported Resource Type "+value.getClass()+" -> return String by using the toString method");
            return value.toString();
View Full Code Here

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

                            jldValue.setLanguage(plain.getLanguage().toString());
                        }
                        strValue = plain.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof TypedLiteral) {
                        TypedLiteral typedObject = (TypedLiteral) currentTriple.getObject();
                        String type = typedObject.getDataType().getUnicodeString();
                        jldValue.setType(type);
                        strValue = typedObject.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof UriRef) {
                        UriRef uriRef = (UriRef) currentTriple.getObject();
                        jldValue.setType(JsonLdCommon.ID);
                        strValue = uriRef.getUnicodeString();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.