Package org.openrdf.model.impl

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


    @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

    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

    @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

    private void checkTriple(String predicate, VerificationMode verificationMode)
    throws TripleHandlerException {
        final String DOCUMENT_URI = "http://an.html.page";
        final TripleHandler mockTripleHandler = mock(TripleHandler.class);
        final ValueFactory valueFactory = new ValueFactoryImpl();
        ExtractionContext extractionContext = new ExtractionContext(
                "test-extractor",
                valueFactory.createURI(DOCUMENT_URI)
        );
        final IgnoreAccidentalRDFa ignoreAccidentalRDFa = new IgnoreAccidentalRDFa(mockTripleHandler, true);
        ignoreAccidentalRDFa.openContext(extractionContext);
        ignoreAccidentalRDFa.receiveTriple(
                valueFactory.createURI(DOCUMENT_URI),
                valueFactory.createURI(predicate),
                valueFactory.createURI("http://www.myedu.com/modules/20110519065453/profile.css"),
                valueFactory.createURI(DOCUMENT_URI),
                extractionContext
        );
        ignoreAccidentalRDFa.close();

        verify(
View Full Code Here

  {
    String ns1 = "a:";
    String ns2 = "b:";
    String ns3 = "c:";

    ValueFactory vf = new ValueFactoryImpl();
    URI uri1 = vf.createURI(ns1, "r1");
    URI uri2 = vf.createURI(ns2, "r2");
    URI uri3 = vf.createURI(ns3, "r3");
    Statement st = vf.createStatement(uri1, uri2, uri3);

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.handleNamespace("", ns1);
    rdfWriter.handleNamespace("", ns2);
View Full Code Here

  {
    String ns1 = "a:";
    String ns2 = "b:";
    String ns3 = "c:";

    ValueFactory vf = new ValueFactoryImpl();
    URI uri1 = vf.createURI(ns1, "r1");
    URI uri2 = vf.createURI(ns2, "r2");
    URI uri3 = vf.createURI(ns3, "r3");
    Statement st = vf.createStatement(uri1, uri2, uri3);

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.handleNamespace("1", ns1);
    rdfWriter.handleNamespace("_", ns2);
View Full Code Here

  /**
   * Creates a new parser base that, by default, will use an instance of
   * {@link ValueFactoryImpl} to create Value objects.
   */
  public TupleQueryResultParserBase() {
    this(new ValueFactoryImpl());
  }
View Full Code Here

  /**
   * Creates a new RDFParserBase that will use a {@link ValueFactoryImpl} to
   * create RDF model objects.
   */
  public RDFParserBase() {
    this(new ValueFactoryImpl());
  }
View Full Code Here

  private List<TransactionOperation> txn;

  private List<Value> parsedValues = new ArrayList<Value>();

  public TransactionSAXParser() {
    this(new ValueFactoryImpl());
  }
View Full Code Here

TOP

Related Classes of org.openrdf.model.impl.ValueFactoryImpl

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.