The part of the code implements an asynchronous function for generating a correlation matrix of tags from notes. The user is prompted to select specific tags and a preferred file format for downloading the correlation matrix. The function retrieves notes associated with the selected tags, analyzes their relationships, and constructs a matrix that reflects how frequently different tags co-occur across the notes. The matrix is then formatted based on the user’s selection (CSV, JSON, or text) and downloaded to the user's device.
Function Name: Correlation Matrix for Tags
Tag Selection:
Label: "Select the Tags to Filter (leave blank to consider all)"
Type: tags
Limit: 10
Purpose: Allows the user to specify up to 10 tags to filter the notes. If left blank, all notes will be considered.
Download Format:
Label: "Format to Download"
Type: radio
Options:
CSV (Suggested)
JSON
Array (txt)
Purpose: Lets the user choose the format for downloading the correlation matrix.
Prompt User Input: The function starts by prompting the user to select tags and the download format. If the user cancels the operation, an alert is displayed, and the function exits.
Retrieve Notes: Based on the selected tags:
If specific tags are chosen, it retrieves notes containing those tags.
If no tags are selected, it retrieves all notes.
Create Tag Array: The function flattens the tags from the retrieved notes, removes duplicates, and sorts them to generate a unique list of tags.
Initialize Correlation Matrix:
A square matrix is created to count the co-occurrences of tags. The matrix is initialized with zeros.
Count Co-occurrences:
For each note, the function checks the tags and increments the count in the matrix for each unique tag pair that appears together.
Download Options:
Based on the user's selected format, the correlation matrix is generated as follows:
Document: For ever Tag, its matching pair occurrence count.
Trend: Sorts highest tag match and sorts accordantly. Ignores self tag / single tagged notes.
CSV: Rows contain the tags and their counts.
JSON: An object is created containing the variables (tags) and the matrix.
Text (Array): A simple representation of the matrix is generated.
The generated content is then downloaded to the user's device.
The function produces a correlation matrix that represents the frequency of tag co-occurrences across notes. This matrix is saved in the selected format (CSV, JSON, or text) and downloaded automatically.
downloadFile(data, fileName, type)
:
Purpose: Facilitates the download of generated content as a file. It creates a Blob from the data, generates a temporary link, and triggers a download.
getCurrentDateTime()
:
Purpose: Retrieves the current date and time formatted as YYMMDD_HHMMSS for naming the downloaded file uniquely.
To use this function, simply call CorrelationMatrixForTags(app)
within an application context where the app
object has the required methods for prompting the user and filtering notes.
The code defines an asynchronous function that creates a markdown note containing clickable links for various groups of notes within the Amplenote application. It categorizes notes based on different criteria, such as their status (archived, active, shared, etc.) and creation date (today, this week). If the note does not already exist, it generates a new note, sets its content to the specified markdown format, and navigates the user to view the note. The resulting markdown is structured for clarity, with categories as headers and descriptive links for easy navigation.
Function Name: Clickable Links for Groups
To generate a markdown note containing organized clickable links that direct users to different groups of notes in the Amplenote application.
Markdown Content Creation: The function constructs a markdown string that contains categorized links to different groups of notes. Each category is clearly labeled, and each link provides a description of what notes are included.
Note Management: The function checks if a note for clickable links already exists. If not, it creates a new note and assigns it a unique identifier (UUID).
Navigation: After creating or updating the note, the function directs the user to the newly created or updated note within the Amplenote application.
App Context (app
):
Type: Object
Purpose: Represents the Amplenote application context, allowing the function to interact with its features such as creating notes, replacing content, and navigating URLs.
groupMarkdown
:
Type: String
Purpose: Contains the markdown formatted content for the note. It includes:
Grouped Folders: Links to archived, vault, deleted, active plugin notes, etc.
Notes Containing Tasks: Link to task lists.
Untagged Notes: Link to notes without tags.
Shared Notes: Links to notes created by the user, shared publicly, shared with the user, and more.
Creation Date: Links to notes created today or this week.
Low-Level Queries: Links to notes with pending changes or being indexed.
Format: Organized in categories for clarity.
groupNoteName
:
Type: String
Purpose: The name of the note that will hold the markdown content ("Group Clickable Links"
).
groupTagName
:
Type: Array of Strings
Purpose: Tags associated with the note for organizational purposes (e.g., ['-reports/-tagger-pro']
).
groupnoteUUID
:
Type: String
Purpose: A unique identifier for the note. The function checks if it already exists; if not, it creates a new note and retrieves the new UUID.
Check for Existing Note:
The function retrieves the existing UUID for the note. If it exists, it uses that UUID; if not, it creates a new note and stores the new UUID.
Replace Note Content:
The function updates the content of the note with the generated markdown string.
Navigate to Note:
The function redirects the user to the view of the newly created or updated note using its UUID.
The output of this function is a note in the Amplenote application containing structured markdown links that allow users to easily access different groups of notes.
To use this function, invoke ClickableLinksForGroups(app)
within a suitable context where the app
object represents the Amplenote application, ensuring it has the necessary methods for managing notes.
The code defines an asynchronous function that generates a markdown note with clickable links for all unique tags associated with notes in the Amplenote application. It retrieves notes, extracts their tags, and formats them into a structured markdown format that includes links to filter notes by each tag. The resulting markdown is organized, including parent-child tag relationships, and is saved as a note in the Amplenote application. The function ensures that if any tags have parent tags that don't directly correspond to existing notes, those parent tags are included as well.
Function Name: Clickable Links for Tags
To create a markdown note containing organized clickable links that direct users to various tags within the Amplenote application.
Note Retrieval: The function fetches all notes from the Amplenote application.
Tag Extraction: It identifies and sorts all unique tags associated with the retrieved notes.
Markdown Link Creation: It generates markdown links for each tag, maintaining proper indentation for parent-child relationships.
Parent Tag Handling: The function includes parent tags for those tags that lack associated notes to ensure a comprehensive link set.
Note Management: It checks for the existence of a specific note for storing these links, creating it if necessary, and updating its content.
Navigation: Finally, it directs the user to the note containing the tag links.
App Context (app
):
Type: Object
Purpose: Represents the Amplenote application context, allowing the function to interact with features like retrieving notes, creating new notes, replacing content, and navigating to URLs.
notes
:
Type: Array
Purpose: Holds all notes retrieved from the Amplenote application.
noteTags
:
Type: Array
Purpose: Contains unique and sorted tags extracted from the notes.
formatTagToMarkdownLink
:
Type: Function
Purpose: Formats a given tag into a markdown link, considering its hierarchy for indentation.
parentTags
:
Type: Set
Purpose: Keeps track of parent tags that are not directly associated with any notes but are necessary for understanding tag relationships.
uniqueMarkdownLinks
:
Type: Set
Purpose: Stores unique markdown links to avoid duplicates while building the output.
finalMarkdownLinks
:
Type: String
Purpose: Contains the final concatenated markdown links for all tags, ready for output.
tagMarkdown
:
Type: String
Purpose: Holds the markdown content for the note, including the unique tag links and additional details.
tagNoteName
:
Type: String
Purpose: The name of the note that will store the tag links ("Tag Clickable Links"
).
tagTagName
:
Type: Array of Strings
Purpose: Tags associated with the note for organizational purposes (e.g., ['-reports/-tagger-pro']
).
tagnoteUUID
:
Type: String
Purpose: A unique identifier for the note. The function checks if it already exists; if not, it creates a new note and retrieves the new UUID.
Fetch Notes:
The function retrieves all notes from the application using app.filterNotes({ })
.
Extract and Sort Tags:
It gathers unique tags from the notes, sorts them, and stores them in noteTags
.
Markdown Link Creation:
For each tag, it generates a markdown link and checks for parent-child relationships.
Parent Tag Management:
If any parent tags are missing from noteTags
, they are added to parentTags
.
Combine Links:
The function adds all unique markdown links (including parent tags) to uniqueMarkdownLinks
.
Prepare Markdown Content:
The final markdown content, tagMarkdown
, is created, including all unique tag links and additional details.
Check for Existing Note:
The function checks if a note for clickable tags already exists. If it does, it uses that UUID; if not, it creates a new note and stores the new UUID.
Replace Note Content:
The function updates the content of the note with the generated markdown string.
Navigate to Note:
Finally, it redirects the user to the view of the newly created or updated note using its UUID.
The output of this function is a note in the Amplenote application containing structured markdown links that allow users to easily access various tags.
To use this function, invoke ClickableLinksForTags(app)
within a suitable context where the app
object represents the Amplenote application, ensuring it has the necessary methods for managing notes.