In a broader sense, what you're referring to here is known as text mining. This is where information is extracted from text according to certain criteria in order to form specific patterns and meanings, etc.
How you would go about implementing this depends on the criteria you have in mind.
For instance, let's suppose you have a blog article in text format (let's call it filepath.txt for this example).
You decide that you wish to sort words into specific categories. For instance, you could categorise the keywords hotel, flights, countries, as travel, i.e. each incidence of the three words would be replaced with data. 219
Let's assume data is a relevant category of interest. Any article that would fall under a travel category would be included in your articles of interest.
Using Python, you can then scan your file and use filedata.replace to replace your keywords with categories:
# Read file
with open('filepath.txt', 'r') as file :
filedata = file.read()
# Replace keyword
filedata = filedata.replace('How ', ' ')
<PERSON> = filedata.replace('Why ', ' ')
<PERSON> = filedata.replace('of ', ' ')
<PERSON> = filedata.replace('to ', ' ')
filedata = filedata.replace('you ', ' ')
filedata = filedata.replace('all ', ' ')
filedata = filedata.replace('and ', ' ')
filedata = filedata.replace('be ', ' ')
filedata = filedata.replace(' a ', ' ')
<PERSON> = filedata.replace(' for ', ' ')
<PERSON> = filedata.replace(' in ', ' ')
<PERSON> = filedata.replace(' is ', ' ')
<PERSON> = filedata.replace(' the ', ' ')
<PERSON> = filedata.replace(' about ', ' ')
<PERSON> = filedata.replace(' an ', ' ')
<PERSON> = filedata.replace('Data', ' data ')
<PERSON> = filedata.replace('Python', ' data ')
<PERSON> = filedata.replace('R', ' data ')
filedata = filedata.replace('machine', ' data ')
<PERSON> = filedata.replace('Linux', ' data ')
<PERSON> = filedata.replace('technology', ' data ')
<PERSON> = filedata.replace('flights', 'travel')
<PERSON> = filedata.replace('countries', 'travel')
<PERSON> = filedata.replace('hotel', 'travel')
<PERSON> = filedata.replace('analytics', 'data')
filedata= filedata.replace('CNN', 'news')
filedata= filedata.replace('weather', 'news')
filedata= filedata.replace('Trump', 'news')
filedata= filedata.replace('market', 'business')
filedata= filedata.replace('entrepreneur', 'business')
filedata= filedata.replace('financial', 'business')
# Write to file
with open('filepath2.txt', 'w') as file:
file.write(filedata)
You could then use a library such as stringr in R to see how frequently the category (which would have the keywords replaced with the category) appears:
require(stringr)
WordList <- str_split(readLines("filepath2.txt"), pattern = " ")
searchqueries<-sort(table(WordList),decreasing=TRUE)[1:100]
searchqueries
e.g. if the category appears X number of times or more, then the article is deemed relevant.
This is just one example of how you could use text mining. Again, much of it hinges on your specific criteria and how you would go about determining relevancy. But that's one way you could approach it. 219