Search in sources :

Example 31 with DefaultAtom

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

the class DlgpWriterTest method writeValideURI.

@Test
public void writeValideURI() throws IOException {
    String uri = "/a//a///a////a/////a//////" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "´áéíóúýàèìòùỳ¨äëïöüÿâêîôûŷ" + "?¿.:,;!¡~'" + "0123456789₀₁₂₃₄₅₆₇₈₉₍₎₊₋₌ₐₑₒₓₔ⁰¹⁴⁵⁶⁷⁸⁹⁺⁽⁾⁼⁻" + "+-*%=()[]«»_—–#" + "ßæœçåÅøØĐħĦ" + "€$¤£" + "¶¦¬©®™ªº♯♮♭" + "ΑΒΔΕΦΓΗΙΘΚΛΜΝΟΠΧΡΣΤΥΩΞΨΖαβδεφγηιθκλμνοπχρστυωξψζ" + "‰≃≠≮≯≤≥≰≱≲≳Ω¼½¾ƒℓ⅓⅔⅛⅜⅝⅞⩽⩾←↑→↓↔↦⇒⇔∂∙∏∑∆∇√∞∫≈≡∀∃∈∉∪∩⊂⊃♀♂ℝℂℚℕℤℍ⊥‖∧∨⟦⟧⟨⟩∘" + // unbreakable spaces
    "  " + "////";
    Predicate p = new Predicate(new DefaultURI(uri), 1);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(new DefaultAtom(p, cst));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    Assert.assertTrue(s.contains("<" + uri + ">(<A>)."));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultURI(fr.lirmm.graphik.util.DefaultURI) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 32 with DefaultAtom

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

the class DlgpWriterTest method bugIllegalCharInPrefixedName.

@Test
public void bugIllegalCharInPrefixedName() throws IOException {
    Prefix p1 = new Prefix("a", "http://p#");
    Predicate p = new Predicate(new DefaultURI("http://p#to@to"), 1);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(p1);
    writer.write(new DefaultAtom(p, cst));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    Assert.assertTrue(s.contains("<http://p#to@to>(<A>)."));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Prefix(fr.lirmm.graphik.util.Prefix) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultURI(fr.lirmm.graphik.util.DefaultURI) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 33 with DefaultAtom

use of fr.lirmm.graphik.graal.core.DefaultAtom 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 34 with DefaultAtom

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

the class DlgpWriterTest method writeVariable.

@Test
public void writeVariable() throws IOException {
    Term x = DefaultTermFactory.instance().createVariable("x");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(new DefaultAtom(predicat, x));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    Assert.assertTrue("Variable label does not begin with upper case.", Character.isUpperCase(s.charAt(s.indexOf("(") + 1)));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 35 with DefaultAtom

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

the class Atom2SubstitutionConverterTest method basic2.

@Test
public void basic2() throws ParseException {
    // given
    Predicate p = DefaultPredicateFactory.instance().create("p", 3);
    Variable x = DefaultTermFactory.instance().createVariable("X");
    Variable y = DefaultTermFactory.instance().createVariable("Y");
    Variable z = DefaultTermFactory.instance().createVariable("Z");
    Atom queryAtom = new DefaultAtom(p, x, y, z);
    List<Term> ansList = new LinkedList<>();
    ansList.add(x);
    ansList.add(z);
    // when
    Converter<Atom, Substitution> converter = new Atom2SubstitutionConverter(queryAtom, ansList);
    Substitution s = null;
    try {
        s = converter.convert(DlgpParser.parseAtom("p(a,b,c)."));
    } catch (ConversionException e) {
        fail();
    }
    // then
    Constant a = DefaultTermFactory.instance().createConstant("a");
    Constant c = DefaultTermFactory.instance().createConstant("c");
    assertEquals(a, s.createImageOf(x));
    assertEquals(y, s.createImageOf(y));
    assertEquals(c, s.createImageOf(z));
}
Also used : ConversionException(fr.lirmm.graphik.util.stream.converter.ConversionException) Variable(fr.lirmm.graphik.graal.api.core.Variable) Substitution(fr.lirmm.graphik.graal.api.core.Substitution) Constant(fr.lirmm.graphik.graal.api.core.Constant) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Atom(fr.lirmm.graphik.graal.api.core.Atom) LinkedList(java.util.LinkedList) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Aggregations

DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)45 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)25 Term (fr.lirmm.graphik.graal.api.core.Term)25 Atom (fr.lirmm.graphik.graal.api.core.Atom)21 Test (org.junit.Test)20 LinkedList (java.util.LinkedList)17 Substitution (fr.lirmm.graphik.graal.api.core.Substitution)12 LinkedListRuleSet (fr.lirmm.graphik.graal.core.ruleset.LinkedListRuleSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)7 Rule (fr.lirmm.graphik.graal.api.core.Rule)7 RuleSet (fr.lirmm.graphik.graal.api.core.RuleSet)7 Variable (fr.lirmm.graphik.graal.api.core.Variable)6 ConversionException (fr.lirmm.graphik.util.stream.converter.ConversionException)6 Constant (fr.lirmm.graphik.graal.api.core.Constant)5 DefaultURI (fr.lirmm.graphik.util.DefaultURI)5 Pair (org.apache.commons.lang3.tuple.Pair)5 DefaultRule (fr.lirmm.graphik.graal.core.DefaultRule)4 AnalyserRuleSet (fr.lirmm.graphik.graal.rulesetanalyser.util.AnalyserRuleSet)4 RulesCompilation (fr.lirmm.graphik.graal.api.core.RulesCompilation)3