Search in sources :

Example 61 with Literal

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

the class RepositoryConfigUtil method getIDStatement.

private static Statement getIDStatement(Model model, String repositoryID) {
    Literal idLiteral = SimpleValueFactory.getInstance().createLiteral(repositoryID);
    Model idStatementList = model.filter(null, REPOSITORYID, idLiteral);
    if (idStatementList.size() == 1) {
        return idStatementList.iterator().next();
    } else if (idStatementList.isEmpty()) {
        return null;
    } else {
        throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID);
    }
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model)

Example 62 with Literal

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

the class RepositoryConfigUtil method getRepositoryIDs.

public static Set<String> getRepositoryIDs(Model model) throws RepositoryException {
    Set<String> idSet = new LinkedHashSet<String>();
    model.filter(null, REPOSITORYID, null).forEach(idStatement -> {
        if (idStatement.getObject() instanceof Literal) {
            Literal idLiteral = (Literal) idStatement.getObject();
            idSet.add(idLiteral.getLabel());
        }
    });
    return idSet;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Literal(org.eclipse.rdf4j.model.Literal)

Example 63 with Literal

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

the class RepositoryConfigUtil method getIDStatement.

private static Statement getIDStatement(RepositoryConnection con, String repositoryID) throws RepositoryException, RepositoryConfigException {
    Literal idLiteral = con.getRepository().getValueFactory().createLiteral(repositoryID);
    List<Statement> idStatementList = Iterations.asList(con.getStatements(null, REPOSITORYID, idLiteral, true));
    if (idStatementList.size() == 1) {
        return idStatementList.get(0);
    } else if (idStatementList.isEmpty()) {
        return null;
    } else {
        throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID);
    }
}
Also used : Statement(org.eclipse.rdf4j.model.Statement) Literal(org.eclipse.rdf4j.model.Literal)

Example 64 with Literal

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

the class SimpleLiteralTest method testStringEmpty.

/**
 * Test method for {@link org.eclipse.rdf4j.model.impl.SimpleLiteral#SimpleLiteral(java.lang.String)}.
 */
@Test
public final void testStringEmpty() throws Exception {
    Literal test = new SimpleLiteral("");
    assertEquals("", test.getLabel());
    assertFalse(test.getLanguage().isPresent());
    assertEquals(XMLSchema.STRING, test.getDatatype());
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 65 with Literal

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

the class LiteralsTest method testCreateLiteralObjectLong.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectLong() throws Exception {
    Object obj = new Long(42);
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.LONG);
    assertEquals(l.getLabel(), "42");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Aggregations

Literal (org.eclipse.rdf4j.model.Literal)96 Test (org.junit.Test)52 IRI (org.eclipse.rdf4j.model.IRI)34 Value (org.eclipse.rdf4j.model.Value)17 BNode (org.eclipse.rdf4j.model.BNode)14 Model (org.eclipse.rdf4j.model.Model)13 Statement (org.eclipse.rdf4j.model.Statement)13 Resource (org.eclipse.rdf4j.model.Resource)9 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)8 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)7 InputStream (java.io.InputStream)6 Date (java.util.Date)6 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 IOException (java.io.IOException)4 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)4 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)4 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)4 QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)4 SPARQLResultsJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser)4 ArrayList (java.util.ArrayList)3