Package org.eclipse.rdf4j.rio.helpers
Class NTriplesUtil
java.lang.Object
org.eclipse.rdf4j.rio.helpers.NTriplesUtil
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
append
(BNode bNode, Appendable appendable) Appends the N-Triples representation of the givenBNode
to the givenAppendable
.static void
append
(IRI uri, Appendable appendable) Appends the N-Triples representation of the givenIRI
to the givenAppendable
.static void
append
(IRI uri, Appendable appendable, boolean escapeUnicode) Appends the N-Triples representation of the givenIRI
to the givenAppendable
.static void
append
(Literal lit, Appendable appendable) Appends the N-Triples representation of the givenLiteral
to the givenAppendable
.static void
append
(Literal lit, Appendable appendable, boolean xsdStringToPlainLiteral, boolean escapeUnicode) Appends the N-Triples representation of the givenLiteral
to the givenAppendable
, optionally ignoring the xsd:string datatype as it is implied for RDF-1.1.static void
append
(Resource resource, Appendable appendable) Appends the N-Triples representation of the givenResource
to the givenAppendable
.static void
append
(Triple triple, Appendable appendable) Appends the N-Triples (non-standard) representation of the givenTriple
to the givenAppendable
.static void
append
(Value value, Appendable appendable) Appends the N-Triples representation of the givenValue
to the givenAppendable
.static void
append
(Value value, Appendable appendable, boolean xsdStringToPlainLiteral, boolean escapeUnicode) Appends the N-Triples representation of the givenValue
to the givenAppendable
, optionally not serializing the datatype aLiteral
with the xsd:string datatype as it is implied for RDF-1.1.static String
escapeString
(String label) Escapes a Unicode string to an all-ASCII character sequence.Any special characters are escaped using backslashes ( " becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes ( \uxxxx and \Uxxxxxxxx).static void
escapeString
(String label, Appendable appendable) Escapes a Unicode string to an all-ASCII character sequence.static void
escapeString
(String label, Appendable appendable, boolean escapeUnicode) Escapes a Unicode string to an N-Triples compatible character sequence.Any special characters are escaped using backslashes (" becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes (\uxxxx and \Uxxxxxxxx) if the option is selected.static boolean
isDot
(int c) Checks whether the supplied character is Dot '.'.static boolean
isLetter
(int c) Deprecated.static boolean
isLetterOrNumber
(int c) Deprecated.static boolean
isLiberalCharactersButNotDot
(int c) Checks whether the supplied character is in list of liberal characters according to the N-Triples specification except Dot.static boolean
isNumber
(int c) Deprecated.static boolean
isUnderscore
(int c) Checks whether the supplied character is Underscore.static boolean
Checks whether the supplied character is valid character as per N-Triples specification.static BNode
parseBNode
(String nTriplesBNode, ValueFactory valueFactory) Parses an N-Triples bNode, creates an object for it using the supplied ValueFactory and returns this object.static Literal
parseLiteral
(String nTriplesLiteral, ValueFactory valueFactory) Parses an N-Triples literal, creates an object for it using the supplied ValueFactory and returns this object.static Resource
parseResource
(String nTriplesResource, ValueFactory valueFactory) Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this object.static Triple
parseTriple
(String nTriplesTriple, ValueFactory valueFactory) Parses an RDF-star triple (non-standard N-Triples), creates an object for it using the supplied ValueFactory and returns this object.static IRI
parseURI
(String nTriplesURI, ValueFactory valueFactory) Parses an N-Triples URI, creates an object for it using the supplied ValueFactory and returns this object.static Value
parseValue
(String nTriplesValue, ValueFactory valueFactory) Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this object.static String
toHexString
(int decimal, int stringLength) Converts a decimal value to a hexadecimal string representation of the specified length.static String
toNTriplesString
(BNode bNode) Creates an N-Triples string for the supplied blank node.static String
toNTriplesString
(IRI uri) Creates an N-Triples string for the supplied URI.static String
toNTriplesString
(Literal lit) Creates an N-Triples string for the supplied literal.static String
toNTriplesString
(Literal lit, boolean xsdStringToPlainLiteral) Creates an N-Triples string for the supplied literal, optionally ignoring the xsd:string datatype as it is implied for RDF-1.1.static String
toNTriplesString
(Resource resource) Creates an N-Triples string for the supplied resource.static String
toNTriplesString
(Triple triple) Creates an N-Triples (non-standard) string for the supplied RDF-star triple.static String
toNTriplesString
(Value value) Creates an N-Triples string for the supplied value.static String
toNTriplesString
(Value value, boolean xsdStringToPlainLiteral) Creates an N-Triples string for the supplied value.If the supplied value is aLiteral
, it optionally ignores the xsd:string datatype, since this datatype is implicit in RDF-1.1.static String
Unescapes an escaped Unicode string.
-
Constructor Details
-
NTriplesUtil
public NTriplesUtil()
-
-
Method Details
-
parseValue
public static Value parseValue(String nTriplesValue, ValueFactory valueFactory) throws IllegalArgumentException Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesValue
- The N-Triples value to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed value.
- Throws:
IllegalArgumentException
- If the supplied value could not be parsed correctly.
-
parseResource
public static Resource parseResource(String nTriplesResource, ValueFactory valueFactory) throws IllegalArgumentException Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesResource
- The N-Triples resource to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed resource.
- Throws:
IllegalArgumentException
- If the supplied resource could not be parsed correctly.
-
parseURI
public static IRI parseURI(String nTriplesURI, ValueFactory valueFactory) throws IllegalArgumentException Parses an N-Triples URI, creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesURI
- The N-Triples URI to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed URI.
- Throws:
IllegalArgumentException
- If the supplied URI could not be parsed correctly.
-
parseBNode
public static BNode parseBNode(String nTriplesBNode, ValueFactory valueFactory) throws IllegalArgumentException Parses an N-Triples bNode, creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesBNode
- The N-Triples bNode to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed bNode.
- Throws:
IllegalArgumentException
- If the supplied bNode could not be parsed correctly.
-
parseLiteral
public static Literal parseLiteral(String nTriplesLiteral, ValueFactory valueFactory) throws IllegalArgumentException Parses an N-Triples literal, creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesLiteral
- The N-Triples literal to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed literal.
- Throws:
IllegalArgumentException
- If the supplied literal could not be parsed correctly.
-
parseTriple
Parses an RDF-star triple (non-standard N-Triples), creates an object for it using the supplied ValueFactory and returns this object.- Parameters:
nTriplesTriple
- The RDF-star triple to parse.valueFactory
- The ValueFactory to use for creating the object.- Returns:
- An object representing the parsed triple.
- Throws:
IllegalArgumentException
- If the supplied triple could not be parsed correctly.
-
toNTriplesString
-
toNTriplesString
Creates an N-Triples string for the supplied value.If the supplied value is aLiteral
, it optionally ignores the xsd:string datatype, since this datatype is implicit in RDF-1.1.- Parameters:
value
- The value to write.xsdStringToPlainLiteral
- True to omit serialising the xsd:string datatype and false to always serialise the datatype for literals.- Returns:
- string
-
append
Appends the N-Triples representation of the givenValue
to the givenAppendable
.- Parameters:
value
- The value to write.appendable
- The object to append to.- Throws:
IOException
-
append
public static void append(Value value, Appendable appendable, boolean xsdStringToPlainLiteral, boolean escapeUnicode) throws IOException Appends the N-Triples representation of the givenValue
to the givenAppendable
, optionally not serializing the datatype aLiteral
with the xsd:string datatype as it is implied for RDF-1.1.- Parameters:
value
- The value to write.appendable
- The object to append to.xsdStringToPlainLiteral
- True to omit serializing the xsd:string datatype and false to always serialize the datatype for literals.escapeUnicode
-- Throws:
IOException
-
toNTriplesString
-
append
Appends the N-Triples representation of the givenResource
to the givenAppendable
.- Parameters:
resource
- The resource to write.appendable
- The object to append to.- Throws:
IOException
-
toNTriplesString
-
append
Appends the N-Triples representation of the givenIRI
to the givenAppendable
.- Parameters:
uri
- The IRI to write.appendable
- The object to append to.- Throws:
IOException
-
append
Appends the N-Triples representation of the givenIRI
to the givenAppendable
.- Parameters:
uri
-appendable
-escapeUnicode
-- Throws:
IOException
-
toNTriplesString
-
append
Appends the N-Triples representation of the givenBNode
to the givenAppendable
.- Parameters:
bNode
-appendable
-- Throws:
IOException
-
toNTriplesString
-
toNTriplesString
Creates an N-Triples string for the supplied literal, optionally ignoring the xsd:string datatype as it is implied for RDF-1.1.- Parameters:
lit
- The literal to write.xsdStringToPlainLiteral
- True to omit serializing the xsd:string datatype and false to always serialize the datatype for literals.- Returns:
- String
-
append
Appends the N-Triples representation of the givenLiteral
to the givenAppendable
.- Parameters:
lit
-appendable
-- Throws:
IOException
-
append
public static void append(Literal lit, Appendable appendable, boolean xsdStringToPlainLiteral, boolean escapeUnicode) throws IOException Appends the N-Triples representation of the givenLiteral
to the givenAppendable
, optionally ignoring the xsd:string datatype as it is implied for RDF-1.1.- Parameters:
lit
- The literal to write.appendable
- The object to append to.xsdStringToPlainLiteral
- True to omit serializing the xsd:string datatype and false to always serialize the datatype for literals.escapeUnicode
- True to escape non-ascii/non-printable characters using Unicode escapes (\uxxxx and \Uxxxxxxxx), false to print without escaping.- Throws:
IOException
-
toNTriplesString
-
append
Appends the N-Triples (non-standard) representation of the givenTriple
to the givenAppendable
.- Parameters:
triple
-appendable
-- Throws:
IOException
-
isLetterOrNumber
Deprecated.Checks whether the supplied character is a letter or number according to the N-Triples specification.- Parameters:
c
-- Returns:
- true if it is a letter or a number
- See Also:
-
isLetter
Deprecated.Checks whether the supplied character is a letter according to the N-Triples specification.N-Triples letters are A - Z and a - z.- Parameters:
c
-- Returns:
- true if c is an ascii leter
-
isNumber
Deprecated.Checks whether the supplied character is a number according to the N-Triples specification.N-Triples numbers are 0 - 9.- Parameters:
c
-- Returns:
- true if the character is a number
-
isValidCharacterForBNodeLabel
public static boolean isValidCharacterForBNodeLabel(int c) Checks whether the supplied character is valid character as per N-Triples specification.- Parameters:
c
-- Returns:
- true if valid
- See Also:
-
isLiberalCharactersButNotDot
public static boolean isLiberalCharactersButNotDot(int c) Checks whether the supplied character is in list of liberal characters according to the N-Triples specification except Dot.- Parameters:
c
-- Returns:
- true if valid
-
isUnderscore
public static boolean isUnderscore(int c) Checks whether the supplied character is Underscore.- Parameters:
c
-- Returns:
- true if it is an underscore
-
isDot
public static boolean isDot(int c) Checks whether the supplied character is Dot '.'.- Parameters:
c
-- Returns:
- true if it is a dot
-
escapeString
Escapes a Unicode string to an all-ASCII character sequence.Any special characters are escaped using backslashes ( " becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes ( \uxxxx and \Uxxxxxxxx).- Parameters:
label
-- Returns:
- an escaped string (unicode to ascii plus codepoints).
-
escapeString
Escapes a Unicode string to an all-ASCII character sequence. Any special characters are escaped using backslashes ( " becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes ( \uxxxx and \Uxxxxxxxx).- Parameters:
label
-appendable
-- Throws:
IOException
-
escapeString
public static void escapeString(String label, Appendable appendable, boolean escapeUnicode) throws IOException Escapes a Unicode string to an N-Triples compatible character sequence.Any special characters are escaped using backslashes (" becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes (\uxxxx and \Uxxxxxxxx) if the option is selected.- Parameters:
label
-appendable
-escapeUnicode
-- Throws:
IOException
-
unescapeString
Unescapes an escaped Unicode string. Any Unicode sequences ( \uxxxx and \Uxxxxxxxx) are restored to the value indicated by the hexadecimal argument and any backslash-escapes ( \", \\, etc.) are decoded to their original form.- Parameters:
s
- An escaped Unicode string.- Returns:
- The unescaped string.
- Throws:
IllegalArgumentException
- If the supplied string is not a correctly escaped N-Triples string.
-
toHexString
Converts a decimal value to a hexadecimal string representation of the specified length.- Parameters:
decimal
- A decimal value.stringLength
- The length of the resulting string.- Returns:
- padded string
-
ASCIIUtil.isLetter(int)