Created
May 21, 2020 20:16
-
-
Save tommymaynard/76a219efa9ff51f3c90064f04fa1b662 to your computer and use it in GitHub Desktop.
Get Synonyms for Approved and Unapproved Verbs
This file contains hidden or 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
| <# | |
| TechNet Contribution: Get Synonyms for Approved and Unapproved Verbs | |
| Previous link: https://gallery.technet.microsoft.com/Get-Synonyms-for-Approved-f6625752 | |
| Downloaded: 452 times (as of 05/21/2020) | |
| The newest version can be found here: http://tommymaynard.com/get-tmverbsynonym-1-4-2017/ | |
| As many PowerShell users are aware, cmdlets and functions should use a verb-noun naming convention with approved | |
| verbs. There are times when the verb a person may desire to use for the cmdlet or function isn't approved -- that's | |
| where this function can assist. This function will return synonyms for verbs and indicate if the synonyms are approved | |
| or not. Take a look at the write up on this function: http://tommymaynard.com/script-sharing-get-synonyms-for-approved-and-unapproved-verbs-2015. | |
| This function uses the Invoke-WebRequest cmdlet, which was introduced in PowerShell 3.0. | |
| Version 1.2: Released June 10, 2016 -- No need to register for your own API key! | |
| Version 1.3: Release July 1, 2016 -- Added Approved as $true and $false, and added verb group when approved. | |
| #> | |
| Function Get-TMVerbSynonym { | |
| <# | |
| .SYNOPSIS | |
| The Get-TMVerbSynonym advanced function returns the synonyms for a verb. | |
| .DESCRIPTION | |
| The Get-TMVerbSynonym advanced function returns the synonyms for a verb, and indicates if they are approved verbs using Get-Verb. Additionally, if the verb is approved, it will indicate the group. This advanced function relies on the thesaurus at altervista.org. | |
| .PARAMETER Verb | |
| This mandatory parameter is the verb for which the function will find synonyms. | |
| .PARAMETER Key | |
| This parameter requires an API key parameter value to use this function. Versions 1.2 and greater include an API key, so there's no need to register for one. | |
| .EXAMPLE | |
| PS > Get-TMVerbSynonym -Verb Launch | |
| Verb Group Approved Notes | |
| ---- ----- -------- ----- | |
| Abolish -- False Antonym | |
| Begin -- False -- | |
| Commence -- False -- | |
| Displace -- False -- | |
| Establish -- False -- | |
| Found -- False -- | |
| Get Common True -- | |
| Get Down -- False -- | |
| Impel -- False -- | |
| Launch -- False -- | |
| Move Common True -- | |
| Open Common True -- | |
| Open Up -- False -- | |
| Plunge -- False -- | |
| Propel -- False -- | |
| Set About -- False -- | |
| Set In Motion -- False -- | |
| Set Out -- False -- | |
| Set Up -- False -- | |
| Smooth -- False -- | |
| Smoothen -- False -- | |
| Start Lifecycle True -- | |
| Start Out -- False -- | |
| This example returns all the synonyms for the verb "launch." | |
| .EXAMPLE | |
| PS > Get-TMVerbSynonym -Verb Launch | Where-Object Approved -eq $true | |
| Verb Group Approved Notes | |
| ---- ----- -------- ----- | |
| Get Common True -- | |
| Move Common True -- | |
| Open Common True -- | |
| Start Lifecycle True -- | |
| This example returns only the synonyms for the verb "Launch" that are approved verbs. If there were no approved verbs, this example would return no results. | |
| .EXAMPLE | |
| PS> Get-TMVerbSynonym -Verb car | Format-Table -Autosize | |
| WARNING: The word "Car" may not have any verb synonyms. | |
| This example attempts to return synonyms for the word car. Since car cannot be used as a verb, it returns a warning message. This function only works when the word supplied can be used as a verb. | |
| .EXAMPLE | |
| PS> Get-TMVerbSynonym -Verb exit | Sort-Object Approved -Descending | |
| This example returns synonyms for the verb "exit," and sorts the verbs by those that are approved. At the time of writing, this example retured two approved verbs: Move and Enter. Enter is actually an antonym, and is indicated as such in the Notes property. | |
| .NOTES | |
| NAME: Get-TMVerbSynonym | |
| AUTHOR: Tommy Maynard | |
| WEB: http://tommymaynard.com | |
| VERSION: 1.2 | |
| - Skipped 1.1 | |
| - Included my key for http://thesaurus.altervista.org. This keeps from needing to register for a key. | |
| - Decreased number of spaces in help. Other help changes due to not needing to register for a key. | |
| - As API key is included, modified code to | |
| VERSION 1.3 | |
| - Modified code to handle logic outside of the object creation time. | |
| - Added Group property: Indicates name of the verb's group when verb is approved. | |
| - Changed Approved string property of Yes and No, to $true and $false. | |
| - Rewrote help where necessary to indicate changes. | |
| LASTEDIT: 07/01/2016 | |
| #> | |
| [CmdletBinding()] | |
| Param ( | |
| [Parameter(Mandatory = $true)] | |
| [string]$Verb, | |
| [string]$Key = 'fkS0rTuZ62Duag0bYgwn' | |
| #[switch]$Approved | |
| ) | |
| Begin { | |
| # Modify case: Capitalize first letter. | |
| $Verb = (Get-Culture).TextInfo.ToTitleCase($Verb) | |
| # Obtain thesaurus information on verb. | |
| try { | |
| Write-Verbose -Message "Downloading synonyms for $Verb." | |
| [xml]$Data = (Invoke-WebRequest -Uri "http://thesaurus.altervista.org/thesaurus/v1?word=$Verb&language=en_US&key=$Key&output=xml" -Verbose:$false).Content | |
| } catch [System.Net.WebException] { | |
| Write-Warning -Message "Unable to find any synonyms for $Verb. Please check your spelling." | |
| } catch { | |
| Write-Warning -Message 'Unhandled error condition in Begin Block.' | |
| } | |
| } # End Begin. | |
| Process { | |
| # Check supplied verb against thesaurus. | |
| Write-Verbose -Message "Checking for synonoms for $Verb." | |
| If ($Data) { | |
| Write-Verbose -Message 'Attempting to parse synonyms list.' | |
| try { | |
| $Words = ($Data.response.list | Where-Object Category -eq '(verb)' | | |
| Select-Object -ExpandProperty Synonyms).Split('|') | | |
| Select-Object -Unique | | |
| Sort-Object | |
| Write-Verbose -Message 'Building results.' | |
| Foreach ($Word in $Words) { | |
| $Word = (Get-Culture).TextInfo.ToTitleCase($Word) | |
| # Clear paraenthesis: (Antonym) and (Related Term) --> Antonym and Related Term. | |
| # Write to Notes variable. | |
| If ($Word -match '\(*\)') { | |
| $Notes = $Word.Split('(')[-1].Replace(')','') | |
| $Word = ($Word.Split('(')[0]).Trim() | |
| } Else { | |
| $Notes = '--' | |
| } | |
| # Determine if verb is approved. | |
| If (Get-Verb -Verb $Word) { | |
| $Approved = $true | |
| $Group = (Get-Verb -Verb $Word).Group | |
| } Else { | |
| $Approved = $false | |
| $Group = '--' | |
| } | |
| # Build Objects. | |
| [pscustomobject]@{ | |
| Verb = $Word | |
| Group = $Group | |
| Approved = $Approved | |
| Notes = $Notes | |
| } | |
| } # End Foreach. | |
| } catch [System.Management.Automation.RuntimeException] { | |
| Write-Warning -Message "The word ""$Verb"" may not have any verb synonyms." | |
| } catch { | |
| Write-Warning -Message 'Unhandled error condition in Process Block.' | |
| } | |
| } | |
| } # End Process | |
| End { | |
| } # End End. | |
| } # End Function: Get-TMVerbSynonym. |
Author
tommymaynard
commented
May 21, 2020

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment