@Override public String ntriplesString() { return this.field.ntriplesString(); }
@Override public String ntriplesString() { return this.field.ntriplesString(); }
@Override public boolean equals(@Nullable Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof IRI) { IRI other = (IRI) obj; return remainder.equals(other.remainder) && other.namespace.equals(namespace); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public boolean equals(@Nullable Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof IRI) { IRI other = (IRI) obj; return remainder.equals(other.remainder) && other.namespace.equals(namespace); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public boolean equals(@Nullable Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof IRI) { IRI other = (IRI) obj; return remainder.equals(other.remainder) && other.namespace.equals(namespace); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (obj instanceof RDFResourceIRI) { RDFResourceIRI other = (RDFResourceIRI) obj; return resource.equals(other.resource); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (obj instanceof RDFResourceIRI) { RDFResourceIRI other = (RDFResourceIRI) obj; return resource.equals(other.resource); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } if (obj instanceof RDFResourceIRI) { RDFResourceIRI other = (RDFResourceIRI) obj; return resource.equals(other.resource); } // Commons RDF IRI equals() contract if (obj instanceof org.apache.commons.rdf.api.IRI) { org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) obj; return ntriplesString().equals(iri.ntriplesString()); } return false; }
@Override public String ntriplesString() { final StringBuilder sb = new StringBuilder(); sb.append('"'); // Escape special characters sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\ replace("\"", "\\\""). // escaped to \" replace("\r", "\\r"). // escaped to \r replace("\n", "\\n")); // escaped to \n sb.append('"'); if (getLanguageTag().isPresent()) { sb.append("@"); sb.append(getLanguageTag().get()); } else if (!getDatatype().equals(Types.XSD_STRING)) { sb.append("^^"); sb.append(getDatatype().ntriplesString()); } return sb.toString(); }
@Override public String ntriplesString() { final StringBuilder sb = new StringBuilder(); sb.append(QUOTE); // Escape special characters sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\ replace("\"", "\\\""). // escaped to \" replace("\r", "\\r"). // escaped to \r replace("\n", "\\n")); // escaped to \n sb.append(QUOTE); // getLanguageTag().ifPresent(s -> sb.append("@" + s)); if (getLanguageTag().isPresent()) { sb.append("@"); sb.append(getLanguageTag().get()); } else if (!getDatatype().equals(Types.XSD_STRING)) { sb.append("^^"); sb.append(getDatatype().ntriplesString()); } return sb.toString(); }
@Override public String ntriplesString() { StringBuilder sb = new StringBuilder(); sb.append(QUOTE); // Escape special characters sb.append(getLexicalForm().replace("\\", "\\\\"). // escaped to \\ replace("\"", "\\\""). // escaped to \" replace("\r", "\\r"). // escaped to \r replace("\n", "\\n")); // escaped to \n sb.append(QUOTE); // getLanguageTag().ifPresent(s -> sb.append("@" + s)); if (getLanguageTag().isPresent()) { sb.append("@"); sb.append(getLanguageTag().get()); } else if (!getDatatype().equals(Types.XSD_STRING)) { sb.append("^^"); sb.append(getDatatype().ntriplesString()); } return sb.toString(); }
@Override public String toString() { return dataset.stream() .map(q -> format("%1$s %2$s %3$s %4$s .", q.getSubject().ntriplesString(), q.getPredicate().ntriplesString(), q.getObject().ntriplesString(), q.getGraphName().map(BlankNodeOrIRI::ntriplesString).orElse(""))) .collect(joining("\n")); } }
@Override public String toString() { return asDataset().stream() .map(q -> format("%1$s %2$s %3$s %4$s .", q.getSubject().ntriplesString(), q.getPredicate().ntriplesString(), q.getObject().ntriplesString(), q.getGraphName().map(BlankNodeOrIRI::ntriplesString).orElse(""))) .collect(joining("\n")); } }
@Override public boolean test(Triple t) { // Lacking the requirement for .equals() we have to be silly // and test ntriples string equivalance if (subject != null && !t.getSubject().ntriplesString() .equals(subject.ntriplesString())) { return false; } if (predicate != null && !t.getPredicate().ntriplesString() .equals(predicate.ntriplesString())) { return false; } if (object != null && !t.getObject().ntriplesString() .equals(object.ntriplesString())) { return false; } return true; } };
@Override public String toString() { return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " " + getObject().ntriplesString() + " " + getGraphName().map(g -> g.ntriplesString() + " ").orElse("") + "."; }
@Override public String toString() { return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " " + getObject().ntriplesString() + " ."; }
@Override public String toString() { return getSubject().ntriplesString() + " " + getPredicate().ntriplesString() + " " + getObject().ntriplesString() + " ."; }
@Test public void testCreateIRI() throws Exception { final IRI example = factory.createIRI("http://example.com/"); assertEquals("http://example.com/", example.getIRIString()); assertEquals("<http://example.com/>", example.ntriplesString()); final IRI term = factory.createIRI("http://example.com/vocab#term"); assertEquals("http://example.com/vocab#term", term.getIRIString()); assertEquals("<http://example.com/vocab#term>", term.ntriplesString()); // and now for the international fun! // make sure this file is edited/compiled as UTF-8 final IRI latin1 = factory.createIRI("http://accént.example.com/première"); assertEquals("http://accént.example.com/première", latin1.getIRIString()); assertEquals("<http://accént.example.com/première>", latin1.ntriplesString()); final IRI cyrillic = factory.createIRI("http://example.испытание/Кириллица"); assertEquals("http://example.испытание/Кириллица", cyrillic.getIRIString()); assertEquals("<http://example.испытание/Кириллица>", cyrillic.ntriplesString()); final IRI deseret = factory.createIRI("http://𐐀.example.com/𐐀"); assertEquals("http://𐐀.example.com/𐐀", deseret.getIRIString()); assertEquals("<http://𐐀.example.com/𐐀>", deseret.ntriplesString()); }
@Test public void testCreateIRI() throws Exception { IRI example; try { example = factory.createIRI("http://example.com/"); } catch (UnsupportedOperationException ex) { Assume.assumeNoException("createIRI not supported", ex); return; } assertEquals("http://example.com/", example.getIRIString()); assertEquals("<http://example.com/>", example.ntriplesString()); IRI term = factory.createIRI("http://example.com/vocab#term"); assertEquals("http://example.com/vocab#term", term.getIRIString()); assertEquals("<http://example.com/vocab#term>", term.ntriplesString()); // and now for the international fun! IRI latin1 = factory.createIRI("http://accént.example.com/première"); assertEquals("http://accént.example.com/première", latin1.getIRIString()); assertEquals("<http://accént.example.com/première>", latin1.ntriplesString()); IRI cyrillic = factory.createIRI("http://example.испытание/Кириллица"); assertEquals("http://example.испытание/Кириллица", cyrillic.getIRIString()); assertEquals("<http://example.испытание/Кириллица>", cyrillic.ntriplesString()); IRI deseret = factory.createIRI("http://𐐀.example.com/𐐀"); assertEquals("http://𐐀.example.com/𐐀", deseret.getIRIString()); assertEquals("<http://𐐀.example.com/𐐀>", deseret.ntriplesString()); }
@Test public void testCreateIRIRelative() throws Exception { // Although relative IRIs are defined in // http://www.w3.org/TR/rdf11-concepts/#section-IRIs // it is not a requirement for an implementation to support // it (all instances of an relative IRI should eventually // be possible to resolve to an absolute IRI) try { factory.createIRI("../relative"); } catch (UnsupportedOperationException | IllegalArgumentException ex) { Assume.assumeNoException(ex); return; } IRI relative = factory.createIRI("../relative"); assertEquals("../relative", relative.getIRIString()); assertEquals("<../relative>", relative.ntriplesString()); IRI relativeTerm = factory.createIRI("../relative#term"); assertEquals("../relative#term", relativeTerm.getIRIString()); assertEquals("<../relative#term>", relativeTerm.ntriplesString()); IRI emptyRelative = factory.createIRI(""); // <> equals the base URI assertEquals("", emptyRelative.getIRIString()); assertEquals("<>", emptyRelative.ntriplesString()); }