protected String toString(final Literal v) { if (null == v) { return "null"; } return NTriplesUtil.toNTriplesString(v); }
/** * Decode a previously encoded URI. * * @param encodedValue * the encoded value * @param valueFactory * the factory to use for constructing the URI * @return the decoded URI * @see #encodeValue(Value) */ public static IRI decodeURI(String encodedValue, ValueFactory valueFactory) { if (encodedValue != null) { return NTriplesUtil.parseURI(encodedValue, valueFactory); } return null; }
/** * Decode a previously encoded Resource. * * @param encodedValue * the encoded value * @param valueFactory * the factory to use for constructing the Resource * @return the decoded Resource * @see #encodeValue(Value) */ public static Resource decodeResource(String encodedValue, ValueFactory valueFactory) { if (encodedValue != null) { return NTriplesUtil.parseResource(encodedValue, valueFactory); } return null; }
/** * Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this * object. * * @param nTriplesValue * The N-Triples value to parse. * @param valueFactory * The ValueFactory to use for creating the object. * @return An object representing the parsed value. * @throws IllegalArgumentException * If the supplied value could not be parsed correctly. */ public static Value parseValue(String nTriplesValue, ValueFactory valueFactory) throws IllegalArgumentException { if (nTriplesValue.startsWith("<")) { return parseURI(nTriplesValue, valueFactory); } else if (nTriplesValue.startsWith("_:")) { return parseBNode(nTriplesValue, valueFactory); } else if (nTriplesValue.startsWith("\"")) { return parseLiteral(nTriplesValue, valueFactory); } else { throw new IllegalArgumentException("Not a legal N-Triples value: " + nTriplesValue); } }
/** * Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this * object. * * @param nTriplesResource * The N-Triples resource to parse. * @param valueFactory * The ValueFactory to use for creating the object. * @return An object representing the parsed resource. * @throws IllegalArgumentException * If the supplied resource could not be parsed correctly. */ public static Resource parseResource(String nTriplesResource, ValueFactory valueFactory) throws IllegalArgumentException { if (nTriplesResource.startsWith("<")) { return parseURI(nTriplesResource, valueFactory); } else if (nTriplesResource.startsWith("_:")) { return parseBNode(nTriplesResource, valueFactory); } else { throw new IllegalArgumentException("Not a legal N-Triples resource: " + nTriplesResource); } }
@Override protected void setup(Context context) throws IOException, InterruptedException { SimpleValueFactory vf = SimpleValueFactory.getInstance(); Configuration conf = context.getConfiguration(); String s = conf.get(SUBJECT); if (s!= null) { subj = NTriplesUtil.parseResource(s, vf); } String p = conf.get(PREDICATE); if (p!= null) { pred = NTriplesUtil.parseURI(p, vf); } String o = conf.get(OBJECT); if (o!= null) { obj = NTriplesUtil.parseValue(o, vf); } String cs[] = conf.getStrings(CONTEXTS); if (cs != null) { ctx = new ArrayList<>(); for (String c : cs) { if ("NONE".equals(c)) { ctx.add(null); } else { ctx.add(NTriplesUtil.parseResource(c, vf)); } } } }
int endLabelIdx = findEndOfLabel(nTriplesLiteral); label = unescapeString(label); IRI dtURI = parseURI(datatype, valueFactory); return valueFactory.createLiteral(label, dtURI);
/** * Decode a previously encoded value. * * @param encodedValue * the encoded value * @param valueFactory * the factory to use for constructing the Value * @return the decoded Value * @see #encodeValue(Value) */ public static Value decodeValue(String encodedValue, ValueFactory valueFactory) { if (encodedValue != null) { return NTriplesUtil.parseValue(encodedValue, valueFactory); } return null; }
/** * Escapes a Unicode string to an all-ASCII character sequence. Any special characters are escaped using * backslashes (<tt>"</tt> becomes <tt>\"</tt>, etc.), and non-ascii/non-printable characters are escaped * using Unicode escapes (<tt>\uxxxx</tt> and <tt>\Uxxxxxxxx</tt>). * * @throws IOException */ public static void escapeString(String label, Appendable appendable) throws IOException { escapeString(label, appendable, true); }
private void writeIRI(IRI iri) throws IOException { NTriplesUtil.append(iri, writer); }
escapeString(lit.getLabel(), appendable); appendable.append("\""); if (!ignoreDatatype) { appendable.append("^^"); append(lit.getDatatype(), appendable);
/** * Parser method returning Statement from a single HBase Result Cell * @param c HBase Result Cell * @return Statements */ public static Statement parseStatement(Cell c) { ByteBuffer bb = ByteBuffer.wrap(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength()); byte[] sb = new byte[bb.getInt()]; byte[] pb = new byte[bb.getInt()]; byte[] ob = new byte[bb.getInt()]; bb.get(sb); bb.get(pb); bb.get(ob); byte[] cb = new byte[bb.remaining()]; bb.get(cb); ValueFactory vf = SimpleValueFactory.getInstance(); return vf.createStatement(NTriplesUtil.parseResource(new String(sb, UTF8), vf), NTriplesUtil.parseURI(new String(pb, UTF8), vf), NTriplesUtil.parseValue(new String(ob,UTF8), vf), cb.length == 0 ? null : NTriplesUtil.parseResource(new String(cb,UTF8), vf)); }
/** * Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this * object. * * @param nTriplesValue * The N-Triples value to parse. * @param valueFactory * The ValueFactory to use for creating the object. * @return An object representing the parsed value. * @throws IllegalArgumentException * If the supplied value could not be parsed correctly. */ public static Value parseValue(String nTriplesValue, ValueFactory valueFactory) throws IllegalArgumentException { if (nTriplesValue.startsWith("<")) { return parseURI(nTriplesValue, valueFactory); } else if (nTriplesValue.startsWith("_:")) { return parseBNode(nTriplesValue, valueFactory); } else if (nTriplesValue.startsWith("\"")) { return parseLiteral(nTriplesValue, valueFactory); } else { throw new IllegalArgumentException("Not a legal N-Triples value: " + nTriplesValue); } }
int endLabelIdx = findEndOfLabel(nTriplesLiteral); label = unescapeString(label); IRI dtURI = parseURI(datatype, valueFactory); return valueFactory.createLiteral(label, dtURI);
/** * Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this * object. * * @param nTriplesResource * The N-Triples resource to parse. * @param valueFactory * The ValueFactory to use for creating the object. * @return An object representing the parsed resource. * @throws IllegalArgumentException * If the supplied resource could not be parsed correctly. */ public static Resource parseResource(String nTriplesResource, ValueFactory valueFactory) throws IllegalArgumentException { if (nTriplesResource.startsWith("<")) { return parseURI(nTriplesResource, valueFactory); } else if (nTriplesResource.startsWith("_:")) { return parseBNode(nTriplesResource, valueFactory); } else { throw new IllegalArgumentException("Not a legal N-Triples resource: " + nTriplesResource); } }
/** * Decode a previously encoded value. * * @param encodedValue * the encoded value * @param valueFactory * the factory to use for constructing the Value * @return the decoded Value * @see #encodeValue(Value) */ public static Value decodeValue(String encodedValue, ValueFactory valueFactory) { if (encodedValue != null) { return NTriplesUtil.parseValue(encodedValue, valueFactory); } return null; }
/** * Escapes a Unicode string to an all-ASCII character sequence. Any special characters are escaped using * backslashes (<tt>"</tt> becomes <tt>\"</tt>, etc.), and non-ascii/non-printable characters are escaped * using Unicode escapes (<tt>\uxxxx</tt> and <tt>\Uxxxxxxxx</tt>). * * @throws IOException */ public static void escapeString(String label, Appendable appendable) throws IOException { escapeString(label, appendable, true); }
private void writeIRI(IRI iri) throws IOException { NTriplesUtil.append(iri, writer); }
escapeString(lit.getLabel(), appendable); appendable.append("\""); if (!ignoreDatatype) { appendable.append("^^"); append(lit.getDatatype(), appendable);
protected String toString(final IRI v) { if (null == v) { return "null"; } return NTriplesUtil.toNTriplesString(v); }