Hello,
Is there an action code that can generate a list of abbreviations, for example, in academic writing? That is an action code that would pull up all the abbreviations appearing in an article and place them as a list in one note.
Thank you
Hello,
Is there an action code that can generate a list of abbreviations, for example, in academic writing? That is an action code that would pull up all the abbreviations appearing in an article and place them as a list in one note.
Thank you
The way I usually do this is (in any document) is to use a regex search to pull out occurrences of two (or perhaps three depending on your discipline) or more consecutive capital letters [A-Z]
Thanks, Rob. I donât have much experience with coding. Are you able to share an example I can modify? I have gleaned some knowledge on regex from watching Michael Beckerâs and the meetup videos, so I should be able to modify the code you will share to accomplish my goal.
Hi Stephen,
it depends on how your abbreviations are build. For all abbreviations that start with a capital letter and contain at least one more capital letter anywhere in the word the RegEx is:
\b(?:[A-Z][a-z]*){2,}
I think Iâve found a way to do this â Iâm sure there will be better ways!
The problem is in two parts:
Identify abbreviations within notes, which is easy.
Pull the abbreviations out of those notes into the text of another note, which is harderâŚ
Assume weâve got 3 notes inside the container âTextsâ, 2 of which have abbreviations and 1 doesnât.
We can identify which have abbreviations with an agent (here called âTexts with abbreviationsâ), whose $Query is: `
inside(Texts) & $Text.contains("[A-Z]{3,}")
The contains clause basically just search for a sequence of three or more ({3,}
) capital letters ([A-Z]
). This will find Text A and B, which both have abbreviations. (See @weblineâs post for a better pattern.)
Thatâs the easy part⌠(Note, we donât actually have to use the Agent to get the final result, but Iâve included it to show more easily how the regular expression worksâŚ)
To pull the abbreviations out takes a bit more work.
First, I created a dedicated set attribute $Abbreviations
. Itâs a set attribute, rather than a list, because Iâm assuming you donât want duplicates.
Secondly, we need to go through all the words in each noteâs text. (Iâve done this in the noteâs Rule, but you could equally use a Stamp).
The easiest way to do this, AFAIK, is to feed the text of the note into a set attribute one word at a time.
$MySet = $Text.split("\W+");
(.split
moves each word (W+
) into $MySet one word at a time, removing duplicates.)
Next we want to loop through MySet and compare each word to our regular abbreviations pattern ([A-Z]{3,}
). If it is a match, then we add it to the notes $Abbreviations
set atttribute.
$MySet.each(x){
if x.contains("[A-Z]{3,}")
{$Abbreviations = $Abbreviations + x}
}
You combine the two steps into a single rule, which you can see in the screenshot below.
Finally, we collect all the $Abbreviation sets for each of the notes in âTextsâ and place them one to a line in the $Text of âList of Abbreviationsâ. To do this, we give âList of Abbreviationsâ the following Rule:
$Text = collect(children(Texts),$Abbreviations).sort.replace(";","\n")
(replace(";","\n"
) simply turns a set/list separated by â;â into a vertical list.)
That should be it: youâve now got all the abbreviations into the text of a single note. Obviously, there are lots of possibilities (and Iâm sure the more experienced will be able to point out better ways), but I think this shows the general principle. E.g., you may want to have a more sophisticated regular expression match as @webline suggests above.
Hereâs the test file for you to play with, if that helps.
Abbreviation Test.tbx (102.7 KB)
HTH!
David.
You might want to consider using simple text expansion software to help you achieve this.
Even OSX supports them via Keyboard â Shortcuts.
Hello,
Thank you. I have used your regex expression to modify Davidâs code as follows:
$MySet = $Text.split("\W+");
$MySet.each(x){ if x.contains("(?:[A-Z][a-z]*){2,}"){$Abbreviations = $Abbreviations + x} }
It worked.
Hello.
Thank you, I have followed your second step with Detlefâs regex code:
$MySet = $Text.split("\W+"); $MySet.each(x){ if x.contains("(?:[A-Z][a-z]*){2,}"){$Abbreviations = $Abbreviations + x} }
And your third step with my notesâs name (MyOutput) inserted.
$Text = collect(children(MyOutput),$Abbreviations).sort.replace(";","\n")
It is a great start. It pulled out the list below which I can then go through, remove duplicates and non-abbreviations, and define for my list of abbreviations.
Pic of part:
There may be a way to refine the output but it is a great start.
For the first part, your agent query uses the name Text, which happens to be the first name of all your notes. All my children notes have different names. How can I modify it to run a similar query if I need to run such an agent for this or other assignments?
Thank you.
Iâm please it worked! I wasnât sure how it could be done at first, and I had fun finding outâŚ
Just one refinement, which will stop you having to look for duplicates manually. If you change this:
$Text = collect(children(MyOutput),$Abbreviations).sort.replace(";","\n")
to this:
$Text = collect(children(MyOutput),$Abbreviations).unique.sort.replace(";","\n")
(i.e. add .unique immediately before
.sort`) then you should remove the duplicates in the final list. (I should have put this in the original, sorryâŚ)
Also, when you post code on this forum, enclose the code in single backpacks (e.g. `code`) for inline code, and in triple backticks for lines on their own:
```
Your code goes here
```
HtH!
Hi,
I use TextExpander for test expansion, and I am unsure how it generates a list of acronyms or abbreviations. Do you mean using it to launch a script? Kindly share an example.
The agent query is actually
inside("Texts") & $Text.contains...
This means "look for any note inside the container âTextsâ AND whose $Text value contains our regular expression. It doesnât actually look at the names of the notes at all, so it shouldnât affect how you name your individual notes.
So, if the container was called âReportsâ, the query would be inside("Reports")
, and so on.
Of course, you can replace the `inside(âTextsâ) with a very wide range of other conditions, for example
$Prototype == "pDocument"
â matches any document with that prototype$Tag.contains("Draft")
â any document with a tag name âDraftâ etc.You use this sort of condition to narrow down the number of results, so youâre not searching inside every note in the file. (Note that you must use ==
not =
when youâre matching the name of an $Attribute).
The âGetting Started with Tinderboxâ and âActions and Dashboardsâ pdfs (on the Help menu) have some worked examples if you like an introduction to Agent Queries, and thereâs some more detailed help in the Help file.
Hope this helps!
Yes, that removed the duplicates
Thanks, too, for the instruction on how to share code on the forum.
Thanks. I have understood, tried it with the correct parent note name, and it worked.
BTW you could leverage code from my note creation video: Tinderbox Training Video 62- Dynamically create notes from attributes with functions.
You can have the abbreviations note create unique notes for each acronym, which you can then define.
your information is very interesting and good question but i am not idea.