use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class DlgpParserTest method backslashedDoubleQuoteTest.
// /////////////////////////////////////////////////////////////////////////
// MISCS
// /////////////////////////////////////////////////////////////////////////
@Test
public void backslashedDoubleQuoteTest() throws ParseException {
Atom a = DlgpParser.parseAtom("p(\"test\\\"test\").");
Term identifier = a.getTerm(0);
Assert.assertTrue(identifier instanceof Literal);
URI datatype = ((Literal) identifier).getDatatype();
Assert.assertEquals(URIUtils.XSD_STRING, datatype);
Object value = ((Literal) identifier).getValue();
Assert.assertEquals("test\"test", value);
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class Atom2SubstitutionConverterTest method githubIssue2variant1.
@Test
public void githubIssue2variant1() throws ParseException {
// given
Predicate p = DefaultPredicateFactory.instance().create("p", 1);
Variable x = DefaultTermFactory.instance().createVariable("X");
Variable y = DefaultTermFactory.instance().createVariable("Y");
Atom queryAtom = new DefaultAtom(p, x);
List<Term> ansList = new LinkedList<>();
ansList.add(x);
ansList.add(y);
// when
Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
Substitution s = null;
try {
s = converter.convert(DlgpParser.parseAtom("p(a)."));
} catch (ConversionException e) {
fail();
}
// then
Constant a = DefaultTermFactory.instance().createConstant("a");
assertEquals(a, s.createImageOf(x));
assertEquals(y, s.createImageOf(y));
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class Atom2SubstitutionConverterTest method basic.
@Test
public void basic() throws ParseException {
// given
Predicate p = DefaultPredicateFactory.instance().create("p", 1);
Variable x = DefaultTermFactory.instance().createVariable("X");
Atom queryAtom = new DefaultAtom(p, x);
List<Term> ansList = new LinkedList<>();
ansList.add(x);
// when
Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
Substitution s = null;
try {
s = converter.convert(DlgpParser.parseAtom("p(a)."));
} catch (ConversionException e) {
fail();
}
// then
Constant a = DefaultTermFactory.instance().createConstant("a");
assertEquals(a, s.createImageOf(x));
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class DlgpWriter method writeStandardAtom.
@Override
protected void writeStandardAtom(Atom atom) throws IOException {
this.writePredicate(atom.getPredicate());
this.write('(');
boolean isFirst = true;
for (Term t : atom.getTerms()) {
if (isFirst) {
isFirst = false;
} else {
this.write(", ");
}
this.writeTerm(t);
}
this.write(')');
}
use of fr.lirmm.graphik.graal.api.core.Term in project graal by graphik-team.
the class DlgpWriterTest method writeConstant.
@Test
public void writeConstant() throws IOException {
Term a = DefaultTermFactory.instance().createConstant("A");
ByteArrayOutputStream os = new ByteArrayOutputStream();
DlgpWriter writer = new DlgpWriter(os);
writer.write(new DefaultAtom(predicat, a));
writer.flush();
String s = new String(os.toByteArray(), "UTF-8");
writer.close();
char c = s.charAt(s.indexOf("(") + 1);
Assert.assertTrue("Constant label does not begin with lower case.", Character.isLowerCase(c) || c == '<');
}
Aggregations