Jump to content

Code the occurrence of known patterns (Whole words/Phrases only) in the given text


This topic is 929 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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:

90105658_ScreenShot2021-09-10at15_38_48.png.c9ecbfd9c1d3cf239e9ba277b2a5fd59.png

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

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

1420058424_ScreenShot2021-09-11at12_43_23.png.257d121a63aa9d595b7bd7c9324f0561.png

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

Link to comment
Share on other sites

This topic is 929 days old. Please don't post here. Open a new topic instead.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.