Search in sources :

Example 16 with Resource

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

the class RepositoryConfigUtil method getRepositoryConfig.

public static RepositoryConfig getRepositoryConfig(Model model, String repositoryID) {
    Statement idStatement = getIDStatement(model, repositoryID);
    if (idStatement == null) {
        // No such config
        return null;
    }
    Resource repositoryNode = idStatement.getSubject();
    Resource context = idStatement.getContext();
    Model contextGraph = model.filter(null, null, null, context);
    return RepositoryConfig.create(contextGraph, repositoryNode);
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model)

Example 17 with Resource

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

the class RepositoryConfigUtil method getContext.

@Deprecated
public static Resource getContext(RepositoryConnection con, String repositoryID) throws RepositoryException, RepositoryConfigException {
    Resource context = null;
    Statement idStatement = getIDStatement(con, repositoryID);
    if (idStatement != null) {
        context = idStatement.getContext();
    }
    return context;
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource)

Example 18 with Resource

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

the class RDFXMLPrettyWriterTest method sequenceItemsAreAbbreviated.

@Test
public void sequenceItemsAreAbbreviated() throws RDFHandlerException, IOException {
    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.startRDF();
    Resource res = vf.createIRI("http://example.com/#");
    rdfWriter.handleStatement(vf.createStatement(res, RDF.TYPE, RDF.BAG));
    rdfWriter.handleStatement(vf.createStatement(res, vf.createIRI(RDF.NAMESPACE + "_1"), vf.createIRI("http://example.com/#1")));
    rdfWriter.handleStatement(vf.createStatement(res, vf.createIRI(RDF.NAMESPACE + "_2"), vf.createIRI("http://example.com/#2")));
    rdfWriter.endRDF();
    List<String> rdfLines = rdfOpenTags(writer.toString());
    assertEquals(Arrays.asList("<rdf:RDF", "<rdf:Bag", "<rdf:li", "<rdf:li"), rdfLines);
}
Also used : StringWriter(java.io.StringWriter) Resource(org.eclipse.rdf4j.model.Resource) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) Test(org.junit.Test)

Example 19 with Resource

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

the class RDFXMLPrettyWriterTest method outOfSequenceItemsAreNotAbbreviated.

@Test
public void outOfSequenceItemsAreNotAbbreviated() throws RDFHandlerException, IOException {
    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.startRDF();
    Resource res = vf.createIRI("http://example.com/#");
    rdfWriter.handleStatement(vf.createStatement(res, RDF.TYPE, RDF.BAG));
    rdfWriter.handleStatement(vf.createStatement(res, vf.createIRI(RDF.NAMESPACE + "_0"), vf.createIRI("http://example.com/#0")));
    rdfWriter.handleStatement(vf.createStatement(res, vf.createIRI(RDF.NAMESPACE + "_2"), vf.createIRI("http://example.com/#2")));
    rdfWriter.endRDF();
    List<String> rdfLines = rdfOpenTags(writer.toString());
    assertEquals(Arrays.asList("<rdf:RDF", "<rdf:Bag", "<rdf:_0", "<rdf:_2"), rdfLines);
}
Also used : StringWriter(java.io.StringWriter) Resource(org.eclipse.rdf4j.model.Resource) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) Test(org.junit.Test)

Example 20 with Resource

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

the class Models method findMatchingStatements.

private static List<Statement> findMatchingStatements(Statement st, Model model, Map<Resource, Resource> bNodeMapping) {
    Resource s = isBlank(st.getSubject()) ? null : st.getSubject();
    IRI p = st.getPredicate();
    Value o = isBlank(st.getObject()) ? null : st.getObject();
    Resource[] g = isBlank(st.getContext()) ? new Resource[0] : new Resource[] { st.getContext() };
    List<Statement> result = new ArrayList<Statement>();
    for (Statement modelSt : model.filter(s, p, o, g)) {
        if (statementsMatch(st, modelSt, bNodeMapping)) {
            // All components possibly match
            result.add(modelSt);
        }
    }
    return result;
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) Statement(org.eclipse.rdf4j.model.Statement) Resource(org.eclipse.rdf4j.model.Resource) Value(org.eclipse.rdf4j.model.Value) ArrayList(java.util.ArrayList)

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