-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor M.pq and M_Creator.py files * Refactor TextClean function to improve documentation and parameter handling * Rename Fx
- Loading branch information
1 parent
6b9204c
commit 24a43fc
Showing
5 changed files
with
211 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
let | ||
// Step 1: Define metadata for each parameter describing its purpose and usage | ||
metaDocumentation = type function ( | ||
mytext as (type text meta [ | ||
Documentation.FieldCaption = "Input Text", | ||
Documentation.FieldDescription = "The primary text input on which cleaning and manipulation operations will be performed.", | ||
Documentation.SampleValues = {"Example text"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]), | ||
optional characters as (type text meta [ | ||
Documentation.FieldCaption = "Characters to Replace", | ||
Documentation.FieldDescription = "A semicolon-separated list of character pairs to be replaced in the input text. Each pair should be delimited by a comma.", | ||
Documentation.SampleValues = {"a,b;c,d"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = true | ||
]), | ||
optional words as (type text meta [ | ||
Documentation.FieldCaption = "Words to Replace", | ||
Documentation.FieldDescription = "A semicolon-separated list of word pairs to be replaced in the input text. Each pair should be delimited by a comma.", | ||
Documentation.SampleValues = {"hello,hi;world,earth"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = true | ||
]), | ||
optional charactersRemove as (type text meta [ | ||
Documentation.FieldCaption = "Characters to Remove", | ||
Documentation.FieldDescription = "A string of characters that will be removed from the input text.", | ||
Documentation.SampleValues = {"abc"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]), | ||
optional fullCellContents as (type text meta [ | ||
Documentation.FieldCaption = "Full Cell Content Replace", | ||
Documentation.FieldDescription = "A semicolon-separated list of old and new content pairs for full cell replacement. Each pair should be delimited by a comma.", | ||
Documentation.SampleValues = {"old text,new text"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = true | ||
]) | ||
) as list | ||
// Step 2: Define global metadata in detail | ||
meta [ | ||
|
||
Documentation.Name = "Text.Clean", | ||
Documentation.LongDescription = | ||
" | ||
<p><b>Text.Clean</b></p> | ||
|
||
<li>------------------------------------------------------</li> | ||
|
||
<li><b> Creator: </b> Oscar Martinez </li> | ||
<li><b> Web: </b> https://bibb.pro </li> | ||
<li><b> LinkedIn: </b> https://www.linkedin.com/in/oscarmartinezv/ </li> | ||
|
||
<li>------------------------------------------------------</li> | ||
|
||
<p><b> Function Description: </b></br> | ||
<p>This function provides various text manipulation capabilities such as replacing specific characters or words, removing certain characters, and replacing entire cell contents based on user-defined parameters.</p> | ||
|
||
", | ||
Documentation.Examples = { | ||
[ | ||
Description = "Replace specific characters in a text string.", | ||
Code = "Text.Clean('example text', 'x,y')", | ||
Result = "example teyt" | ||
] | ||
} | ||
], | ||
|
||
// Define the main function and parameters | ||
myFunction = (mytext as text, optional characters as text, optional words as text, optional charactersRemove as text, optional fullCellContents as text) => | ||
|
||
let | ||
// Use the input text as the initial source | ||
Source = mytext, | ||
|
||
// Function to convert a delimited string into a list of lists | ||
ListFromString = (string as text, delimiter1 as text, delimiter2 as text) as any => | ||
let | ||
SplitPairs = Text.Split(string, delimiter1), | ||
ConvertToLists = List.Transform(SplitPairs, each Text.Split(_, delimiter2)) | ||
in | ||
ConvertToLists, | ||
|
||
// Replace characters if 'characters' parameter is provided | ||
ReplaceMatchingChar = if characters <> null then | ||
Text.Combine( | ||
List.ReplaceMatchingItems( | ||
Text.ToList(Source), | ||
ListFromString(characters, ";", ",") | ||
) | ||
) | ||
else Source, | ||
|
||
// Replace words if 'words' parameter is provided | ||
ReplaceMatchingWord = if words <> null then | ||
Text.Combine( | ||
List.ReplaceMatchingItems( | ||
Text.Split(ReplaceMatchingChar, " "), | ||
ListFromString(words, ";", ",") | ||
), " " | ||
) | ||
else ReplaceMatchingChar, | ||
|
||
// Remove characters if 'charactersRemove' parameter is provided | ||
CleanedText = if charactersRemove <> null then | ||
Text.Remove(ReplaceMatchingWord, Text.ToList(charactersRemove)) | ||
else ReplaceMatchingWord, | ||
|
||
// Trim the final text | ||
TrimmedText = Text.Trim(CleanedText), | ||
|
||
// Replace full cell contents if 'fullCellContents' parameter is provided | ||
FinalText = if fullCellContents <> null then | ||
let | ||
ReplacementList = ListFromString(fullCellContents, ";", ","), | ||
ReplacedFullContent = List.ReplaceMatchingItems({TrimmedText}, ReplacementList) | ||
in | ||
ReplacedFullContent{0} | ||
else TrimmedText | ||
|
||
in | ||
FinalText | ||
// _______________________________ \\ | ||
in | ||
|
||
Value.ReplaceType(myFunction, metaDocumentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
let | ||
// Step 1: Define metadata for each parameter describing its purpose and usage | ||
metaDocumentation = type function ( | ||
string as (type text meta [ | ||
Documentation.FieldCaption = "String", | ||
Documentation.SampleValues = {"ä,a;ö,o"}, | ||
// Documentation.AllowedValues = {"Value1", "Value2", "Value3"}, | ||
Formatting.IsMultiLine = false, | ||
Formatting.IsCode = false | ||
]) | ||
) as list | ||
// Step 2: Define global metadata in detail | ||
meta [ | ||
Documentation.Name = "Text.ListFromString", | ||
Documentation.LongDescription = | ||
" | ||
<p><b> Template Title </b></p> | ||
|
||
<li>------------------------------------------------------</li> | ||
|
||
<li><b> Web: </b> https://bibb.pro </li> | ||
<li><b> LinkedIn: </b> https://www.linkedin.com/in/oscarmartinezv/ </li> | ||
|
||
<li>------------------------------------------------------</li> | ||
|
||
<p><b> Function Description: </b></br> | ||
Converts a string separated by commas and semicolons into a list</b></br></br> | ||
|
||
<b> Returns: </b></br> | ||
A list. | ||
|
||
", | ||
Documentation.Examples = { | ||
[ | ||
Description = "Converts a string separated by commas and semicolons into a list", | ||
Code = "Text.ListFromString(""ä,a;ö,o"")", | ||
Result = "{{""ü"", ""u""},{""ö"", ""o""}}" | ||
] | ||
} | ||
], | ||
|
||
// Define the main function and parameters | ||
myFunction = (string as text) as any => | ||
|
||
let | ||
// Your original string | ||
OriginalText = string, | ||
|
||
// Split the string into rows by semicolon | ||
SplitPairs = Text.Split(OriginalText, ";"), | ||
|
||
// Convert each pair into a list by splitting by comma | ||
ConvertToLists = List.Transform(SplitPairs, each Text.Split(_, ",")) | ||
in | ||
ConvertToLists | ||
|
||
in | ||
|
||
Value.ReplaceType(myFunction, metaDocumentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters