Package org.apache.clerezza.rdf.core

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


                "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


        Iterator<Triple> startPosIterator = enhancements.filter(textAnnotation,
                ENHANCER_START, null);
        Iterator<Triple> endPosIterator = enhancements.filter(textAnnotation,
                ENHANCER_END, null);
        //start end is optional, but if start is present, that also end needs to be set
        TypedLiteral startPosLiteral;
        TypedLiteral endPosLiteral;
        if(startPosIterator.hasNext()){
            //NOTE: TextAnnotations might be use to select whole sections of a text
            //      (e.g. see STANBOL-617) in those cases adding the text of the
            //      whole section is not feasible.
            //assertNotNull("If fise:start is present the fise:selection-context MUST also be present (uri: "+textAnnotation+")!",
            //    selectionContextResource);
            Resource resource = startPosIterator.next().getObject();
            //only a single start position is supported
            assertFalse("fise:start MUST HAVE only a single value (uri: "+textAnnotation+")!",startPosIterator.hasNext());
            assertTrue("fise:start MUST be a typed Literal (uri: "+textAnnotation+")!",resource instanceof TypedLiteral);
            startPosLiteral = (TypedLiteral) resource;
            assertEquals("fise:start MUST use xsd:int as data type (uri: "+textAnnotation+")",XSD.int_, startPosLiteral.getDataType());
            resource = null;
            Integer start = LiteralFactory.getInstance().createObject(Integer.class, startPosLiteral);
            assertNotNull("Unable to parse Integer from TypedLiteral "+startPosLiteral,start);
            //now get the end
            //end must be defined if start is present
            assertTrue("If fise:start is present also fise:end MUST BE defined (uri: "+textAnnotation+")!",endPosIterator.hasNext());
            resource = endPosIterator.next().getObject();
            //only a single end position is supported
            assertFalse("fise:end MUST HAVE only a single value (uri: "+textAnnotation+")!",endPosIterator.hasNext());
            assertTrue("fise:end values MUST BE TypedLiterals (uri: "+textAnnotation+")",resource instanceof TypedLiteral);
            endPosLiteral = (TypedLiteral) resource;
            assertEquals("fise:end MUST use xsd:int as data type (uri: "+textAnnotation+")",XSD.int_, endPosLiteral.getDataType());
            resource = null;
            Integer end = LiteralFactory.getInstance().createObject(Integer.class, endPosLiteral);
            assertNotNull("Unable to parse Integer from TypedLiteral "+endPosLiteral,end);
            //check for equality of the selected text and the text on the selected position in the content
            //System.out.println("TA ["+start+"|"+end+"]"+selectedText.getLexicalForm()+"<->"+content.substring(start,end));
View Full Code Here

                "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

        ContentItem contentItem = ciFactory.createContentItem(uri, new ByteArraySource(content,
                "text/plain; charset=UTF-8"));

        TripleCollection tc = new SimpleMGraph();
        TypedLiteral literal = LiteralFactory.getInstance().createTypedLiteral("Michael Jackson");
        UriRef subject = new UriRef("dummyUri");
        tc.add(new TripleImpl(subject, new UriRef("http://xmlns.com/foaf/0.1/givenName"), literal));
        contentItem.addPart(new UriRef(uri.getUnicodeString() + "_additionalMetadata"), tc);

        ContentItemBackend ciBackend = new ContentItemBackend(contentItem, true);
View Full Code Here

                            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

            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

        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

        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

    @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

    @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

TOP

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

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.