The search algorithm of names in the text

There are a few texts for a couple of thousand words each. there is a list(a few hundred) names (Alexander, Ivan, etc.).
If the name are the words with a capital letter, then consider this a first and last name.
Is there a more efficient way of finding the name but stupid overkill?

although it is not important, but the language is PHP
October 8th 19 at 02:15
4 answers
October 8th 19 at 02:17
More efficient algorithms certainly exist, but I wouldn't waste time on optimization, if a few texts a couple of thousand words is all that is necessary to process. There is a high probability that the creation of the optimal program will take more time than working sub-optimally.
October 8th 19 at 02:19
What have the names and whether they are necessary I did not understand. PHP I know at the level
<?php echo "Hello world" ?>
.
But I know bash quite well. And I would do it:
for FILE in *txt ; do
comm -12 <(cat $FILE | sed 's/[!?., ]/\n/g'|sort -u) <(sort FILE_WITH_NAME_LIST)
done

Times requested algorithm, then it does the following: turns the file into a sequence of strings, where each string is one word. Also assumes that the file names is also the same sequence, and then the comm is still overkill for matches.
To compare this method with php nor proizvoditelnosti nor the complexity, alas, can not.
Developing the idea, I will assume that it is possible to submit the text and a list of the names as arrays in PHP and make a cut at the intersection of those arrays. - Randall.V commented on October 8th 19 at 02:22
October 8th 19 at 02:21
Maybe I don't understand, it wants scaleval the author, but to realize the selection can be as follows:
split the string into individual pieces (explode), unless they are separated just by spaces or any symbol. Then similarly divide separately the name to a character array and check the first character to uppercase.
Wrote while in my mind, do not think for illiteracy) - Randall.V commented on October 8th 19 at 02:24
October 8th 19 at 02:23
array_uintersect
yep, just have more names then cycle quickly to run to check. - Randall.V commented on October 8th 19 at 02:26

Find more questions by tags Algorithms