Search in sources :

Example 1 with DefaultURI

use of fr.lirmm.graphik.util.DefaultURI in project graal by graphik-team.

the class DlgpWriterTest method bug76.

@Test
public void bug76() throws IOException {
    Prefix p1 = new Prefix("a", "http://p#");
    Prefix p2 = new Prefix("b", "http://p#p/");
    Predicate p = new Predicate(new DefaultURI("http://p#p/toto"), 1);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    DlgpWriter writer = new DlgpWriter(os);
    writer.write(p1);
    writer.write(p2);
    writer.write(new DefaultAtom(p, cst));
    writer.flush();
    String s = new String(os.toByteArray(), "UTF-8");
    writer.close();
    Assert.assertTrue(s.contains("b:toto(<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 2 with DefaultURI

use of fr.lirmm.graphik.util.DefaultURI in project graal by graphik-team.

the class DlgpWriterTest method writeURIForbiddenChars.

@Test
public void writeURIForbiddenChars() throws IOException {
    Predicate p = new Predicate(new DefaultURI("/< >\"{}|^`\\/"), 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();
    System.out.println(s);
    Assert.assertEquals("</\\u003c\\u0020\\u003e\\u0022\\u007b\\u007d\\u007c\\u005e\\u0060\\u005c/>(<A>).\n", s);
}
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 3 with DefaultURI

use of fr.lirmm.graphik.util.DefaultURI in project graal by graphik-team.

the class AbstractRDFListener method handleStatement.

@Override
public void handleStatement(Statement st) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(st.toString());
    }
    Predicate predicate = new Predicate(new DefaultURI(st.getPredicate().toString()), 2);
    Term subject = DefaultTermFactory.instance().createConstant(new DefaultURI(st.getSubject().toString()));
    Term object;
    fr.lirmm.graphik.util.URI datatype;
    if (st.getObject() instanceof Literal) {
        Literal l = (Literal) st.getObject();
        if (l.getDatatype() == null) {
            datatype = URIUtils.RDF_LANG_STRING;
        } else {
            datatype = new fr.lirmm.graphik.util.DefaultURI(l.getDatatype().getNamespace(), l.getDatatype().getLocalName());
        }
        String value = l.getLabel();
        if (datatype.equals(URIUtils.RDF_LANG_STRING)) {
            value += "@" + l.getLanguage();
        }
        object = DefaultTermFactory.instance().createLiteral(datatype, value);
    } else {
        object = DefaultTermFactory.instance().createConstant(new DefaultURI(st.getObject().toString()));
    }
    DefaultAtom a = new DefaultAtom(predicate, subject, object);
    this.createAtom(a);
}
Also used : DefaultURI(fr.lirmm.graphik.util.DefaultURI) Literal(org.eclipse.rdf4j.model.Literal) DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Term(fr.lirmm.graphik.graal.api.core.Term) DefaultURI(fr.lirmm.graphik.util.DefaultURI) Predicate(fr.lirmm.graphik.graal.api.core.Predicate)

Example 4 with DefaultURI

use of fr.lirmm.graphik.util.DefaultURI 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 5 with DefaultURI

use of fr.lirmm.graphik.util.DefaultURI 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)

Aggregations

Predicate (fr.lirmm.graphik.graal.api.core.Predicate)5 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)5 DefaultURI (fr.lirmm.graphik.util.DefaultURI)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 Prefix (fr.lirmm.graphik.util.Prefix)2 Term (fr.lirmm.graphik.graal.api.core.Term)1 Literal (org.eclipse.rdf4j.model.Literal)1