Quito Posted September 10, 2021 Posted September 10, 2021 Hi, This is a split thread from Where I began with a fairly large amount of substitutions with codes appended to the known patterns. Comment kindly provided a simpler solution MultiPatternCount+Hilite.fmp12, which beautifully resolves the problem using two Custom Functions: HiliteSingle and HiliteMulti. I start with the text field with TextColor ( string ; RGB(73;99;140)) Blue. If the pattern is detected, and the code is harvested, the known pattern changes to TextColor ( string ; RGB(0;255;0)) Green. The current problem is that it's not recognizing whole words/phrases but rather shorter patterns first. I've ordered the known patterns by counting the amount of characters and then ordering by Length in descending order (from highest to lowest number of characters). If you look at line 3, second word, "aggrediantur" and "rediantur" are both coded but, as it found "rediantur" first, "aggrediantur" was ommitted. See screenshot: Let's look at HiliteSingle: ---------- Let ( [ // Here should be a "If 1st letter of word pattern is TextColor Blue perform HiliteSingle" in order to change it to TextColor Green after processing and not go over the same word/phrase recursively with smaller known patterns. // Or otherwise replace the known pattern with its code and, when the process is finished, change it back to the known pattern pos = Position ( text ; searchString ; 1 ; 1 ) ] ; Case ( pos ; Let ( [ textBefore = Left ( text ; pos - 1 ) ; len = Length ( searchString ) ; string = Middle ( text ; pos ; len ) ; textAfter = Right ( text ; Length ( text ) - pos - len + 1 ) ] ; // Was previously TextStyleAdd (string; HighlightYellow) but I changed it to TextColor ( string ; RGB(0;255;0) ) Green for the reason mentioned above textBefore & TextColor ( string ; RGB(0;255;0) ) & HiliteSingle ( textAfter ; searchString ) ) ; text ) ) --------------- HiliteMulti doesn't seem to need any changes, so the code only seems to be missing the line immediately after Let. Can you help me a bit with this? Best regards, Daniel
comment Posted September 10, 2021 Posted September 10, 2021 This is quite confusing and I have a number of questions, but I would like to know this first: 1. What kind of punctuation will your text have? If it's only spaces, then it should be easy to add a leading and a trailing space to both text and the search phrase, thus eliminating the match of partial words. If you have other punctuation characters (such as the commas show in your screenshot), then it gets more complicated - in fact, considerably so. Which brings me to the next question: 2. Can you use the BaseElements plugin? I suspect this could be made easier by using regex.
Quito Posted September 11, 2021 Author Posted September 11, 2021 19 hours ago, comment said: This is quite confusing and I have a number of questions, but I would like to know this first: 1. What kind of punctuation will your text have? If it's only spaces, then it should be easy to add a leading and a trailing space to both text and the search phrase, thus eliminating the match of partial words. If you have other punctuation characters (such as the commas show in your screenshot), then it gets more complicated - in fact, considerably so. Which brings me to the next question: 2. Can you use the BaseElements plugin? I suspect this could be made easier by using regex. Thank you so much Comment, This suggestion got me thinking and I resolved it by replacing all spaces and punctuation with pipe (|). I also added some spaces here and there to make it easier to read. Now each word begins and ends with |, and my known patterns begin and end with | as well (see screenshot). The words are coded and the word in blue is misspelled! The next steps will be 1. Underline unknown words in the source text (not present in the "known pattern") 2. Offer suggestions for replacement With that it I will finally have a main dictionary, free from the 32KB or 2882 storage limit! Again, thank you very much! Daniel
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now