Search in sources :

Example 6 with Literal

use of fr.lirmm.graphik.graal.api.core.Literal in project graal by graphik-team.

the class AbstractAtomSet method getLiterals.

@Override
public Set<Literal> getLiterals() throws AtomSetException {
    Set<Literal> terms = new HashSet<Literal>();
    CloseableIterator<Atom> atomIt = this.iterator();
    try {
        while (atomIt.hasNext()) {
            Iterator<Term> termIt = atomIt.next().iterator();
            while (termIt.hasNext()) {
                Term t = termIt.next();
                if (t.isLiteral()) {
                    terms.add((Literal) t);
                }
            }
        }
    } catch (Exception e) {
        throw new AtomSetException(e);
    }
    return terms;
}
Also used : Literal(fr.lirmm.graphik.graal.api.core.Literal) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) Term(fr.lirmm.graphik.graal.api.core.Term) Atom(fr.lirmm.graphik.graal.api.core.Atom) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) HashSet(java.util.HashSet)

Example 7 with Literal

use of fr.lirmm.graphik.graal.api.core.Literal in project graal by graphik-team.

the class DlgpWriterTest method bugDoubleQuoteInStringLiteral.

@Test
public void bugDoubleQuoteInStringLiteral() throws IOException {
    Literal l = DefaultTermFactory.instance().createLiteral(URIUtils.XSD_STRING, "test\"test");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(new DefaultAtom(predicat, l));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    Assert.assertTrue(s.contains("\"test\\\"test\""));
}
Also used : Literal(fr.lirmm.graphik.graal.api.core.Literal) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 8 with Literal

use of fr.lirmm.graphik.graal.api.core.Literal in project graal by graphik-team.

the class AtomTest method testGetLiterals.

/**
 * Test method for
 * {@link fr.lirmm.graphik.graal.core.DefaultAtom#getLiterals()}.
 */
@Theory
public void testGetLiterals(AtomFactory factory) {
    // given
    Atom a = factory.create(TestUtils.pXONE);
    // when
    Set<Literal> literals = a.getLiterals();
    // then
    Assert.assertEquals(1, literals.size());
    Assert.assertTrue(literals.contains(TestUtils.ONE));
}
Also used : Literal(fr.lirmm.graphik.graal.api.core.Literal) Atom(fr.lirmm.graphik.graal.api.core.Atom) Theory(org.junit.experimental.theories.Theory)

Example 9 with Literal

use of fr.lirmm.graphik.graal.api.core.Literal in project graal by graphik-team.

the class TermTest method literalConstructorTest.

@SuppressWarnings("deprecation")
@Test
public void literalConstructorTest() {
    int value = 1;
    Literal term = DefaultTermFactory.instance().createLiteral(1);
    Assert.assertTrue(Term.Type.LITERAL.equals(term.getType()));
    Assert.assertTrue(term.isConstant());
    Assert.assertTrue(term.isLiteral());
    Assert.assertFalse(term.isVariable());
    Assert.assertTrue(term.getValue().equals(value));
}
Also used : Literal(fr.lirmm.graphik.graal.api.core.Literal) Test(org.junit.Test)

Aggregations

Literal (fr.lirmm.graphik.graal.api.core.Literal)9 Atom (fr.lirmm.graphik.graal.api.core.Atom)4 Term (fr.lirmm.graphik.graal.api.core.Term)3 URI (fr.lirmm.graphik.util.URI)3 Test (org.junit.Test)3 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)2 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)1 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)1 DefaultURI (fr.lirmm.graphik.util.DefaultURI)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 Resource (org.eclipse.rdf4j.model.Resource)1 Theory (org.junit.experimental.theories.Theory)1