# Utility functions Utility functions help you perform common operations on your data within your data mappings. You make them available by including the ```xmlns:su="com.spinque.tools.importStream.Utils"``` namespace: ```xml ``` Below is a description of the most commonly used utility functions: ## su:e The su:e function generates an identifier for a resource based on its type and zero to five identifiers provided: ```java String e(String type[, String id1, String id2, String id3, String id4, String id5]) ``` You use su:e to create an identifier for a resource when it is impossible or undesirable to create a [URI](../glossary/#uri) for it. If you want to create a [URI](../glossary/#uri), use function [su:uri](#su-uri). You call su:e with only the resource type when your data does not contain an identifier for the resource. Su:e then returns the type with an universally unique identifier appended to it. Given the following virtual XML fragment: ```xml Pulp Fiction
``` the mapping: ```xml ``` generates these triples: ```rdf (_:@movie:62b7c7c9-0c43-442e-b71b-abe6be4b39f3-0-8d0d, rdf:type, rdfs:Resource) (_:@movie:62b7c7c9-0c43-442e-b71b-abe6be4b39f3-0-8d0d, https://schema.org/title, "Pulp Fiction") ``` When your data contains (an) identifier(s) for the resource you call su:e with the type and 1 to 5 identifiers. Su:e then returns the type with the identifier(s) appended to it. Given the following virtual XML fragment: ```xml tt0110912 Pulp Fiction
``` the mapping: ```xml ``` generates these triples: ```rdf (_:@movie:tt0110912, rdf:type, rdfs:Resource) (_:@movie:tt0110912, https://schema.org/title, "Pulp Fiction") ``` ## su:parseDate The su:parseDate function parses a date in a provided format and converts it into a string with the format 'yyyy-MM-dd': ```java String parseDate(String date, String languageTag, String format[, String format2, ..., String format10]) ``` Given the following virtual XML fragment: ```xml tt0110912 28-10-1994
``` the mapping: ```xml ``` generates these triples: ```rdf (_:@movie:tt0110912, rdf:type, rdfs:Resource) (_:@movie:tt0110912, https://schema.org/datePublished, "1994-10-28") ``` If your data contains dates in different formats, you can enter additional formats to provide for them to be parsed as well. ## su:split The su:split function breaks a string around matches of a given regular expression and returns an XPath nodeset that you can iterate over in your mapping: ```java XNodeSet split(String content, String separatorRegex[, int limit]) ``` Su:split is often used to create separate entities for a field that holds multiple values. The genre field in the following virtual XML fragment contains two values separated by a comma: ```xml tt0110912 Crime, Drama
``` The mapping splits the genre field on commas, producing a list of genres. The for-each element that receives this list activates its code for all items. The normalize-space(.) function returns the current item, the name of a genre: ```xml ``` The mapping thus generates these triples: ```rdf (_:@movie:tt0110912, https://schema.org/genre, _:genre:Crime) (_:genre:Crime, rdf:type, https://imdb.com/schema/Genre) (_:@movie:tt0110912, https://schema.org/genre, _:genre:Drama) (_:genre:Drama, rdf:type, https://imdb.com/schema/Genre) ``` ## su:uri The su:uri function generates a [URI](../glossary/#uri) based on a base and one to four paths provided: ```java String uri(String base, String path1[, String path2, String path3, String path4]) ``` If you want to create another type of identifier, use function [su:e](#su-e). Given the following virtual XML fragment: ```xml tt0110912 Pulp Fiction
``` the mapping: ```xml ``` generates these triples: ```rdf (https://imdb.com/data/movie/tt0110912, rdf:type, rdfs:Resource) (https://imdb.com/data/movie/tt0110912, https://schema.org/title, "Pulp Fiction") ```