Examples of ValueFactoryImpl


Examples of org.openrdf.model.impl.ValueFactoryImpl

     *         RDFTriple in each of the given contexts.
     */
    public static Collection<Statement> tripleAsStatements(
            final RDFTriple triple, final Resource... contexts) {
        OpenRDFUtil.verifyContextNotNull(contexts);
        final ValueFactoryImpl vf = ValueFactoryImpl.getInstance();
        Resource subject;
        URI predicate;
        Value object;
        if (triple.getSubject() instanceof RDFResourceIRI) {
            try {
                subject = vf.createURI(triple.getSubject().getIRI().toString());
            } catch (IllegalArgumentException iae) {
                LOGGER.error("Subject URI was invalid: {}", triple);
                return Collections.emptyList();
            }
        } else {
            // FIXME: When blank nodes are no longer represented as IRIs
            // internally, need to fix
            // this
            if (triple.getSubject().getIRI().toString().startsWith("_:")) {
                subject = vf.createBNode(triple.getSubject().getIRI()
                        .toString().substring(2));
            } else {
                subject = vf.createBNode(triple.getSubject().getIRI()
                        .toString());
            }
        }
        predicate = vf.createURI(triple.getPredicate().getIRI().toString());
        if (triple.getObject() instanceof RDFResourceIRI) {
            try {
                object = vf.createURI(triple.getObject().getIRI().toString());
            } catch (IllegalArgumentException iae) {
                LOGGER.error("Object URI was invalid: {}", triple);
                return Collections.emptyList();
            }
        } else if (triple.getObject() instanceof RDFLiteral) {
            final RDFLiteral literalObject = (RDFLiteral) triple.getObject();
            // TODO: When updating to Sesame-2.8 the following may need to be
            // rewritten
            if (literalObject.isPlainLiteral()) {
                if (literalObject.hasLang()) {
                    object = vf.createLiteral(literalObject.getLexicalValue(),
                            literalObject.getLang());
                } else {
                    object = vf.createLiteral(literalObject.getLexicalValue());
                }
            } else {
                object = vf.createLiteral(literalObject.getLexicalValue(),
                        vf.createURI(literalObject.getDatatype().toString()));
            }
        } else {
            // FIXME: When blank nodes are no longer represented as IRIs
            // internally, need to fix
            // this
            if (triple.getObject().getIRI().toString().startsWith("_:")) {
                object = vf.createBNode(triple.getObject().getIRI().toString()
                        .substring(2));
            } else {
                object = vf.createBNode(triple.getObject().getIRI().toString());
            }
        }
        if (contexts == null || contexts.length == 0) {
            return Collections.singletonList(vf.createStatement(subject,
                    predicate, object));
        } else {
            final ArrayList<Statement> results = new ArrayList<>(
                    contexts.length);
            for (final Resource nextContext : contexts) {
                results.add(vf.createStatement(subject, predicate, object,
                        nextContext));
            }
            return results;
        }
    }
View Full Code Here

Examples of org.openrdf.model.impl.ValueFactoryImpl

    @Test
    public void testLinkExtraction() throws RepositoryException {
        assertExtract("/html/html-head-link-extractor.html");
        assertModelNotEmpty();
        final ValueFactory valueFactory = new ValueFactoryImpl();
        final URI externalLinkURI = valueFactory.createURI("http://www.myexperiment.org/workflows/16.rdf");
        assertContains(
                AbstractExtractorTestCase.baseURI,
                valueFactory.createURI("http://www.w3.org/1999/xhtml/vocab#alternate"),
                externalLinkURI

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/title"),
                valueFactory.createLiteral("RDF+XML")

        );
        assertContains(
                externalLinkURI,
                valueFactory.createURI("http://purl.org/dc/terms/format"),
                valueFactory.createLiteral("application/rdf+xml")

        );
    }
View Full Code Here

Examples of org.openrdf.model.impl.ValueFactoryImpl

    private StringWriter testNTriplesStringWriter;
    private RDFWriter testNTriplesRioWriter;

    @Before
    public void setUp() throws Exception {
        vf = new ValueFactoryImpl();
        // limit the storers to known Rio OntologyStorers to minimise false
        // negative results
        // use all parsers for renderer test
        // OWLParserFactoryRegistry parserRegistry = new
        // OWLParserFactoryRegistry();
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.