I will try to describe how I would approach it with my limited skills. (For example I am using AutoHotkey in Obsidian-edit-mode to open markdown-style-link which surrounds or precedes caret (cursor). When link target does not exist, then It gets created and prefilled with header based on info from the parsed link.)
Assume I have relevant indented lines available and processing them one by one, My approach in following:
- Have dictionary of prepositions to ignore {“of”, …}.
- Have dictionary of (measurement) units and it’s aliases {kg: kg, piece: piece, pieces: piece, ks: piece}.
- L := current line to process
- L := L without part starting by "# " or “//”
- While there is link in L:
- {
- Find first link in the line and store it as object of relation (you have this already implemented likely)
- B := part of L before link
- A := [] # empty array
- Parse part before found link by space character into array A of “word” strings
- If last word from A matches item from dictionary of prepositions, pop it out from array A.
- If last word starts with digits followed by letters, then split it into two ( “99units” → “99”, “units” ).
- Now If last word matches item from dictionary of units (with aliases), add corresponding unit to property of relation and pop it out from array A.
- If last word from A is number, then add it to property “quentity” of the relation
- If relation does not have defined quantity, then set quantity = 1
- // ignore rest of array A
- L := part of L after the link // this allows to process list separated by commas
- } // end of While there is link in L