Search in sources :

Example 6 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class ModelsTest method testSubjectURI.

public void testSubjectURI() {
    model1.add(foo, bar, foo);
    model1.add(foo, foo, foo);
    model1.add(baz, foo, foo);
    model1.add(bar, foo, foo);
    Resource result = Models.subjectIRI(model1).orElse(null);
    assertNotNull(result);
    assertTrue(result.equals(bar) || result.equals(foo));
}
Also used : Resource(org.eclipse.rdf4j.model.Resource)

Example 7 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class ModelsTest method testSubject.

public void testSubject() {
    model1.add(foo, bar, foo);
    model1.add(foo, foo, foo);
    model1.add(bar, foo, foo);
    model1.add(baz, foo, foo);
    Resource result = Models.subject(model1).orElse(null);
    assertNotNull(result);
    assertTrue(result.equals(bar) || result.equals(foo) || result.equals(baz));
}
Also used : Resource(org.eclipse.rdf4j.model.Resource)

Example 8 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class StatementsTest method testMultipleContexts.

@Test
public void testMultipleContexts() {
    Resource c1 = vf.createIRI("urn:c1");
    Resource c2 = vf.createIRI("urn:c1");
    Resource c3 = vf.createIRI("urn:c1");
    Model m = Statements.create(vf, FOAF.AGE, RDF.TYPE, RDF.PROPERTY, new TreeModel(), c1, c2, null, c3);
    assertFalse(m.isEmpty());
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, (Resource) null));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c1));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c2));
    assertTrue(m.contains(FOAF.AGE, RDF.TYPE, RDF.PROPERTY, c3));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Model(org.eclipse.rdf4j.model.Model) Test(org.junit.Test)

Example 9 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RDFCollectionsTest method testRemove.

@Test
public void testRemove() {
    Resource head = vf.createBNode();
    Model m = RDFCollections.asRDF(values, head, new TreeModel());
    // add something to the model that is not part of the RDF collection.
    m.add(RDF.TYPE, RDF.TYPE, RDF.PROPERTY);
    // remove the entire collection
    RDFCollections.extract(m, head, st -> m.remove(st));
    assertFalse(m.contains(null, RDF.FIRST, a));
    assertFalse(m.contains(null, RDF.FIRST, b));
    assertFalse(m.contains(null, RDF.FIRST, c));
    assertFalse(m.contains(head, null, null));
    assertTrue(m.contains(RDF.TYPE, RDF.TYPE, RDF.PROPERTY));
}
Also used : TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Resource(org.eclipse.rdf4j.model.Resource) Model(org.eclipse.rdf4j.model.Model) TreeModel(org.eclipse.rdf4j.model.impl.TreeModel) Test(org.junit.Test)

Example 10 with Resource

use of org.eclipse.rdf4j.model.Resource in project rdf4j by eclipse.

the class RepositoryConfigUtil method updateRepositoryConfigs.

/**
 * Update the specified RepositoryConnection with the specified set of RepositoryConfigs. This will
 * overwrite all existing configurations in the Repository that have a Repository ID occurring in these
 * RepositoryConfigs. Note: this method does NOT commit the updates on the connection.
 *
 * @param con
 *        the repository connection to perform the update on
 * @param configs
 *        The RepositoryConfigs that should be added to or updated in the Repository. The
 *        RepositoryConfig's ID may already occur in the Repository, in which case all previous
 *        configuration data for that Repository will be cleared before the RepositoryConfig is added.
 * @throws RepositoryException
 * @throws RepositoryConfigException
 */
@Deprecated
public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryConfig... configs) throws RepositoryException, RepositoryConfigException {
    ValueFactory vf = con.getRepository().getValueFactory();
    con.begin();
    for (RepositoryConfig config : configs) {
        Resource context = getContext(con, config.getID());
        if (context != null) {
            con.clear(context);
        } else {
            context = vf.createBNode();
        }
        con.add(context, RDF.TYPE, REPOSITORY_CONTEXT);
        Model graph = new LinkedHashModel();
        config.export(graph);
        con.add(graph, context);
    }
    con.commit();
}
Also used : Resource(org.eclipse.rdf4j.model.Resource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel)

Aggregations

Resource (org.eclipse.rdf4j.model.Resource)90 IRI (org.eclipse.rdf4j.model.IRI)37 Value (org.eclipse.rdf4j.model.Value)30 Test (org.junit.Test)16 Statement (org.eclipse.rdf4j.model.Statement)15 Model (org.eclipse.rdf4j.model.Model)12 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)12 BNode (org.eclipse.rdf4j.model.BNode)11 IOException (java.io.IOException)9 Literal (org.eclipse.rdf4j.model.Literal)9 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)7 StringWriter (java.io.StringWriter)6 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)6 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)6 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)6 TreeModel (org.eclipse.rdf4j.model.impl.TreeModel)6 RepositoryConnection (org.eclipse.rdf4j.repository.RepositoryConnection)6 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)5 ArrayList (java.util.ArrayList)4