DlgpParser extends AbstractCloseableIterator<Object> implements Parser<Object> { public static Atom parseAtom(String s) throws ParseException { try { return (Atom) parse(s); } catch (ClassCastException e) { throw new DlgpParseException("Wrong object type.", e); } } DlgpParser(Reader reader);  DlgpParser();  DlgpParser(File file);  DlgpParser(String s);  DlgpParser(InputStream in); @Override boolean hasNext(); @Override Object next(); @Override void close(); static EffectiveConjunctiveQuery parseEffectiveQuery(String s); static ConjunctiveQuery parseQuery(String s); static Atom parseAtom(String s); static Rule parseRule(String s); static NegativeConstraint parseNegativeConstraint(String s); static CloseableIterator<Atom> parseAtomSet(String s);  }
@Test public void parseAtom() throws ParseException { Atom a = DlgpParser.parseAtom("p(a, X)."); Assert.assertTrue(a.getTerm(1).isVariable()); }
@Test public void parseAtomWithPrefix() throws ParseException { Atom a = DlgpParser.parseAtom("@prefix ex: <http: Assert.assertTrue(a.getTerm(1).isVariable()); }
@Test(expected = ParseException.class) public void parseAtomWrongObject() throws ParseException { DlgpParser.parseAtom("p(X) :- q(X)."); }
@Test(expected = ParseException.class) public void parseAtomSyntax() throws ParseException { DlgpParser.parseAtom("p(a)"); }
@Test(expected = ParseException.class) public void parseAtomTwoObject() throws ParseException { DlgpParser.parseAtom("p(a). p(b)."); }
@Test(expected = ParseException.class) public void parseAtomNoObject() throws ParseException { DlgpParser.parseAtom(""); }
@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); }
@Test public void parseWithChevron() throws ParseException { Atom a1 = DlgpParser.parseAtom("p(a)."); Atom a2 = DlgpParser.parseAtom("<p>(<a>)."); Assert.assertEquals(a1, a2); }
@Test public void uriWithUnicode() throws ParseException { String uri = "\\u007C\\u003e\\u0020\\u262D"; Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); Assert.assertEquals("|> \u262D", a.getPredicate().getIdentifier().toString()); }
@Test public void uriWithUnicode2() throws ParseException { String uri = "\\U0000007C\\U0000003e\\U00000020\\U0000262D"; Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); Assert.assertEquals("|> \u262D", a.getPredicate().getIdentifier().toString()); }
@Test public void uriWithUnicode4Bytes() throws ParseException { String uri = "\\U00010000\\u003e\\U00000020"; Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); String s = new String(Character.toChars(0x10000)); Assert.assertEquals( s + "> ",a.getPredicate().getIdentifier().toString()); }
@Test public void uriValide() throws ParseException { String uri = "/a + "´áéíóúýàèìòùỳ¨äëïöüÿâêîôûŷ" + "?¿.:,;!¡~'" + "0123456789₀₁₂₃₄₅₆₇₈₉₍₎₊₋₌ₐₑₒₓₔ⁰¹⁴⁵⁶⁷⁸⁹⁺⁽⁾⁼⁻" + "+-*%=()[]«»_—–#" + "ßæœçåÅøØĐħĦ" + "€$¤£" + "¶¦¬©®™ªº♯♮♭" + "ΑΒΔΕΦΓΗΙΘΚΛΜΝΟΠΧΡΣΤΥΩΞΨΖαβδεφγηιθκλμνοπχρστυωξψζ" + "‰≃≠≮≯≤≥≰≱≲≳Ω¼½¾ƒℓ⅓⅔⅛⅜⅝⅞⩽⩾←↑→↓↔↦⇒⇔∂∙∏∑∆∇√∞∫≈≡∀∃∈∉∪∩⊂⊃♀♂ℝℂℚℕℤℍ⊥‖∧∨⟦⟧⟨⟩∘" + " " + " Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); Assert.assertEquals(uri, a.getPredicate().getIdentifier().toString()); Assert.assertEquals(uri, a.getTerm(0).getIdentifier().toString()); }
@Test public void uriValidePercent() throws ParseException { String uri = "%"; Atom a = DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); Assert.assertEquals(uri, a.getPredicate().getIdentifier().toString()); Assert.assertEquals(uri, a.getTerm(0).getIdentifier().toString()); }
@Test(expected = DlgpParseException.class) public void uriNotValideSpace() throws ParseException { String uri = "/ /"; DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">)."); }
@Test(expected = DlgpParseException.class) public void uriNotValideGreaterThan() throws ParseException { String uri = "/>/"; System.out.println(DlgpParser.parseAtom("<" + uri + ">(<" + uri + ">).")); ; }