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;
}
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\""));
}
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));
}
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));
}
Aggregations