diff --git a/docs/fix/Fix-functions-and-Cookbook.md b/docs/fix/Fix-functions-and-Cookbook.md index 58acb51..240fd49 100644 --- a/docs/fix/Fix-functions-and-Cookbook.md +++ b/docs/fix/Fix-functions-and-Cookbook.md @@ -65,6 +65,8 @@ Options: include(""[, ...]) ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+include+{") + ##### `nothing` Does nothing. It is used for benchmarking in Catmandu. @@ -75,6 +77,8 @@ nothing() [Example in Playground](https://metafacture.org/playground/?example=nothing) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+nothing+{") + ##### `put_filemap` Defines an external map for [lookup](#lookup) from a file or a URL. Maps with more than 2 columns are supported but are reduced to a defined key and a value column. @@ -102,6 +106,8 @@ Options: - `key_column`: Defines the column to be used for keys. Uses zero index. (Default: `0`) - `value_column`: Defines the column to be used for values. Uses zero index. (Default: `1`) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+put_filemap+{") + ##### `put_map` Defines an internal map for [lookup](#lookup) from key/value pairs. @@ -116,6 +122,8 @@ put_map("", [Example in Playground](https://metafacture.org/playground/?example=put_map) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+put_map+{") + ##### `put_rdfmap` Defines an external RDF map for lookup from a file or an HTTP(S) resource. @@ -129,6 +137,8 @@ put_rdfmap("", "", target: "", select_lang [Example in Playground](https://metafacture.org/playground/?example=put_rdfmap) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+put_rdfmap+{") + ##### `put_var` Defines a single global variable that can be referenced with `$[]`. @@ -139,6 +149,8 @@ put_var("", "") [Example in Playground](https://metafacture.org/playground/?example=put_var) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+put_var+{") + ##### `put_vars` Defines multiple global variables that can be referenced with `$[]`. @@ -152,6 +164,8 @@ put_vars( [Example in Playground](https://metafacture.org/playground/?example=put_vars) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+put_vars+{") + #### Record-level functions ##### `add_field` @@ -164,6 +178,8 @@ add_field("", "") [Example in Playground](https://metafacture.org/playground/?example=add_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+add_field+{") + ##### `array` Converts a hash/object into an array. @@ -179,6 +195,8 @@ array("foo") # {"name":"value"} => ["name", "value"] ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+array+{") + ##### `call_macro` Calls a named macro, i.e. a list of statements that have been previously defined with the [`do put_macro`](#do-put_macro) bind. @@ -200,6 +218,8 @@ call_macro(""[, ...]) [Example in Playground](https://metafacture.org/playground/?example=call_macro) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+call_macro+{") + ##### `copy_field` Copies a field from an existing field. @@ -210,6 +230,7 @@ copy_field("", "") [Example in Playground](https://metafacture.org/playground/?example=copy_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+copy_field+{") ##### `format` @@ -221,6 +242,8 @@ Replaces the value with a formatted (`sprintf`-like) version. format("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+format+{") + ##### `hash` Converts an array into a hash/object. @@ -235,6 +258,8 @@ hash("foo") # ["name", "value"] => {"name":"value"} ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+hash+{") + ##### `move_field` Moves a field from an existing field. Can be used to rename a field. @@ -245,6 +270,7 @@ move_field("", "") [Example in Playground](https://metafacture.org/playground/?example=move_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+move_field+{") ##### `parse_text` @@ -256,6 +282,8 @@ Parses a text into an array or hash of values. parse_text("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+parse_text+{") + ##### `paste` Joins multiple field values into a new field. Can be combined with additional literal strings. @@ -279,6 +307,8 @@ paste("my.string", "~Hi", "a", "~how are you?") [Example in Playground](https://metafacture.org/playground/?example=paste) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+paste+{") + ##### `print_record` Prints the current record as JSON either to standard output or to a file. @@ -312,6 +342,8 @@ print_record(destination: "record-%2$s.json", id: "001", pretty: "true") print_record(destination: "record-%03d.json.gz", header: "After transformation: ") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+print_record+{") + ##### `random` Creates (or replaces) a field with a random number (less than the specified maximum). @@ -320,6 +352,8 @@ Creates (or replaces) a field with a random number (less than the specified maxi random("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+random+{") + ##### `remove_field` Removes a field. @@ -330,6 +364,8 @@ remove_field("") [Example in Playground](https://metafacture.org/playground/?example=remove_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+remove_field+{") + ##### `rename` Replaces a regular expression pattern in subfield names of a field. Does not change the name of the source field itself. @@ -340,6 +376,8 @@ rename("", "", "") [Example in Playground](https://metafacture.org/playground/?example=rename) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+rename+{") + ##### `retain` Deletes all fields except the ones listed (incl. subfields). @@ -350,6 +388,8 @@ retain(""[, ...]) [Example in Playground](https://metafacture.org/playground/?example=retain) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+retain+{") + ##### `set_array` Creates a new array (with optional values). @@ -361,6 +401,8 @@ set_array("", ""[, ...]) [Example in Playground](https://metafacture.org/playground/?example=set_array) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+set_array+{") + ##### `set_field` Creates (or replaces) a field with a defined value. @@ -369,6 +411,8 @@ Creates (or replaces) a field with a defined value. set_field("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+set_field+{") + ##### `set_hash` Creates a new hash (with optional values). @@ -378,6 +422,8 @@ set_hash("") set_hash("", "subfieldName": ""[, ...]) ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+set_hash+{") + ##### `timestamp` Creates (or replaces) a field with the current timestamp. @@ -392,6 +438,8 @@ Options: timestamp(""[, format: ""][, timezone: ""][, language: ""]) ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+timestamp+{") + ##### `vacuum` Deletes empty fields, arrays and objects. @@ -402,6 +450,8 @@ vacuum() [Example in Playground](https://metafacture.org/playground/?example=vacuum) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+vacuum+{") + #### Field-level functions ##### `append` @@ -414,6 +464,8 @@ append("", "") [Example in Playground](https://metafacture.org/playground/?example=append) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+append+{") + ##### `capitalize` Upcases the first character in a field value. @@ -424,6 +476,8 @@ capitalize("") [Example in Playground](https://metafacture.org/playground/?example=capitalize) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+capitalize+{") + ##### `count` Counts the number of elements in an array or a hash and replaces the field value with this number. @@ -432,6 +486,8 @@ Counts the number of elements in an array or a hash and replaces the field value count("") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+count+{") + ##### `downcase` Downcases all characters in a field value. @@ -442,6 +498,8 @@ downcase("") [Example in Playground](https://metafacture.org/playground/?example=downcase) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+downcase+{") + ##### `filter` Only keeps field values that match the regular expression pattern. Works only with array of strings/repeated fields. @@ -450,6 +508,8 @@ Only keeps field values that match the regular expression pattern. Works only wi filter("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+filter+{") + ##### `flatten` Flattens a nested array field. @@ -460,6 +520,8 @@ flatten("") [Example in Playground](https://metafacture.org/playground/?example=flatten) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+flatten+{") + ##### `from_json` Replaces the string with its JSON deserialization. @@ -472,6 +534,8 @@ Options: from_json(""[, error_string: ""]) ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+from_json+{") + ##### `index` Returns the index position of a substring in a field and replaces the field value with this number. @@ -480,6 +544,8 @@ Returns the index position of a substring in a field and replaces the field valu index("", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+index+{") + ##### `isbn` Extracts an ISBN and replaces the field value with the normalized ISBN; optionally converts and/or validates the ISBN. @@ -496,6 +562,8 @@ isbn(""[, to: ""][, verify_check_digit: ""][, [Example in Playground](https://metafacture.org/playground/?example=isbn) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+isbn+{") + ##### `join_field` Joins an array of strings into a single string. @@ -506,6 +574,8 @@ join_field("", "") [Example in Playground](https://metafacture.org/playground/?example=join_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+join_field+{") + ##### `lookup` Looks up matching values in a map and replaces the field value with this match. [External files](#put_filemap), [internal maps](#put_map) as well as [RDF resources](#put_rdfmap) can be used. @@ -565,6 +635,8 @@ lookup("path.to.field", "map-name", __default: "NA") lookup("path.to.field", "map-name", print_unknown: "true", destination: "unknown.txt") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+lookup+{") + ##### `prepend` Adds a string at the beginning of a field value. @@ -575,6 +647,8 @@ prepend("", "") [Example in Playground](https://metafacture.org/playground/?example=prepend) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+prepend+{") + ##### `replace_all` Replaces a regular expression pattern in field values with a replacement string. Regexp capturing is possible; refer to capturing groups by number (`$`) or name (`${}`). @@ -585,6 +659,8 @@ replace_all("", "", "") [Example in Playground](https://metafacture.org/playground/?example=replace_all) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+replace_all+{") + ##### `reverse` Reverses the character order of a string or the element order of an array. @@ -593,6 +669,8 @@ Reverses the character order of a string or the element order of an array. reverse("") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+reverse+{") + ##### `sort_field` Sorts strings in an array. Alphabetically and A-Z by default. Optional numerical and reverse sorting. @@ -605,6 +683,8 @@ sort_field("", numeric: "true") [Example in Playground](https://metafacture.org/playground/?example=sort_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+sort_field+{") + ##### `split_field` Splits a string into an array and replaces the field value with this array. @@ -615,6 +695,8 @@ split_field("", "") [Example in Playground](https://metafacture.org/playground/?example=split_field) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+split_field+{") + ##### `substring` Replaces a string with its substring as defined by the start position (offset) and length. @@ -623,6 +705,8 @@ Replaces a string with its substring as defined by the start position (offset) a substring("", "", "") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+substring+{") + ##### `sum` Sums numbers in an array and replaces the field value with this number. @@ -631,6 +715,8 @@ Sums numbers in an array and replaces the field value with this number. sum("") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+sum+{") + ##### `to_json` Replaces the value with its JSON serialization. @@ -644,6 +730,8 @@ Options: to_json(""[, pretty: ""][, error_string: ""]) ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+to_json+{") + ##### `trim` Deletes whitespace at the beginning and the end of a field value. @@ -654,6 +742,8 @@ trim("") [Example in Playground](https://metafacture.org/playground/?example=trim) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+trim+{") + ##### `uniq` Deletes duplicate values in an array. @@ -664,6 +754,7 @@ uniq("") [Example in Playground](https://metafacture.org/playground/?example=uniq) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+uniq+{") ##### `upcase` @@ -675,6 +766,8 @@ upcase("") [Example in Playground](https://metafacture.org/playground/?example=upcase) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+upcase+{") + ##### `uri_encode` Encodes a field value as URI. Aka percent-encoding. @@ -694,6 +787,8 @@ E.g.: uri_encode("path.to.field", plus_for_space:"false", safe_chars:"") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+uri_encode+{") + ### Selectors #### `reject` @@ -708,12 +803,16 @@ end [Example in Playground](https://metafacture.org/playground/?example=reject) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixMethod.java+"+reject+{") + ### Binds #### `do list` Iterates over each element of an array. In contrast to Catmandu, it can also iterate over a single object or string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixBind.java+"+list+{") + ```perl do list(path: "") ... @@ -738,6 +837,8 @@ end Iterates over each _named_ element of an array (like [`do list`](#do-list) with a variable name). If multiple arrays are given, iterates over the _corresponding_ elements from each array (i.e., all elements with the same array index, skipping elements whose arrays have already been exhausted). +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixBind.java+"+list_as+{") + ```perl do list_as(element_1: ""[, ...]) ... @@ -769,6 +870,8 @@ end [Example in Playground](https://metafacture.org/playground/?example=do_once) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixBind.java+"+once+{") + In order to execute multiple blocks only once, tag them with unique identifiers: ```perl @@ -807,6 +910,8 @@ call_macro(""[, ...]) [Example in Playground](https://metafacture.org/playground/?example=do_put_macro) +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixBind.java+"+put_macro+{") + ### Conditionals Conditionals start with `if` in case of affirming the condition or `unless` rejecting the condition. @@ -843,36 +948,52 @@ end Executes the functions if/unless the field contains the value. If it is an array or a hash all field values must contain the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+all_contain+{") + ##### `any_contain` Executes the functions if/unless the field contains the value. If it is an array or a hash one or more field values must contain the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+any_contain+{") + ##### `none_contain` Executes the functions if/unless the field does not contain the value. If it is an array or a hash none of the field values may contain the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+none_contain+{") + ##### `str_contain` Executes the functions if/unless the first string contains the second string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+str_contain+{") + #### `equal` ##### `all_equal` Executes the functions if/unless the field value equals the string. If it is an array or a hash all field values must equal the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+all_equal+{") + ##### `any_equal` Executes the functions if/unless the field value equals the string. If it is an array or a hash one or more field values must equal the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+any_equal+{") + ##### `none_equal` Executes the functions if/unless the field value does not equal the string. If it is an array or a hash none of the field values may equal the string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+none_equal+{") + ##### `str_equal` Executes the functions if/unless the first string equals the second string. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+str_equal+{") + #### `exists` Executes the functions if/unless the field exists. @@ -880,6 +1001,7 @@ Executes the functions if/unless the field exists. ```perl if exists("") ``` +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+exists+{") #### `in` @@ -887,6 +1009,8 @@ Executes the functions if/unless the field value [is contained in](https://perld _Also aliased as [`is_contained_in`](#is_contained_in)._ +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+in+{") + #### `is_contained_in` _Alias for [`in`](#in)._ @@ -895,22 +1019,32 @@ _Alias for [`in`](#in)._ Executes the functions if/unless the field value is an array. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_array+{") + #### `is_empty` Executes the functions if/unless the field value is empty. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_empty+{") + #### `is_false` Executes the functions if/unless the field value equals `false` or `0`. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_false+{") + #### `is_hash` _Alias for [`is_object`](#is_object)._ +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_hash+{") + #### `is_number` Executes the functions if/unless the field value is a number. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_number+{") + #### `is_object` Executes the functions if/unless the field value is a hash (object). @@ -921,24 +1055,37 @@ _Also aliased as [`is_hash`](#is_hash)._ Executes the functions if/unless the field value is a string (and not a number). +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_string+{") + #### `is_true` Executes the functions if/unless the field value equals `true` or `1`. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+is_true+{") + + #### `match` ##### `all_match` Executes the functions if/unless the field value matches the regular expression pattern. If it is an array or a hash all field values must match the regular expression pattern. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+all_match+{") + ##### `any_match` Executes the functions if/unless the field value matches the regular expression pattern. If it is an array or a hash one or more field values must match the regular expression pattern. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+any_match+{") + ##### `none_match` Executes the functions if/unless the field value does not match the regular expression pattern. If it is an array or a hash none of the field values may match the regular expression pattern. +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+none_match+{") + ##### `str_match` Executes the functions if/unless the string matches the regular expression pattern. + +[Java Code](https://github.com/search?type=code&q=repo:metafacture/metafacture-fix+path:FixConditional.java+"+str_match+{")