How to implement BM25F,VSM or POS tagging for limited string in python?

95 Views Asked by At

I have a text file where there are only 35 string i want to find out most relevant string in the text file.How can I implement BM25F,VSM or POS to find it?

e.g

Panoramio Bahawalpur
... - Bahawalpur - Picture of Bahawalpur, Punjab Province - TripAdvisor
... Minister Syed Yousaf Raza Gillani\u00e2\u20ac\u2122s short visit to 
Bahawalpur
Bahawalpur Station Pictures - Pakistan in Photos
Noor Mahal Station , Bahawalpur Railway Station | Noor Mahal the italian style palac ...
Bahawalpur Railway Pakistan
Nur Mehal, Bahawalpur  

given input is Bahawalpur Railway Station

How to find most appropriate/relevant strings?

1

There are 1 best solutions below

0
Ali Jafar On

This is very simple task you can go with

from difflib import SequenceMatcher

it will return you the percentage that how much your string match from

def similar(a, b):

  return SequenceMatcher(None, a, b).ratio()
str = "This is hello-hi image"

print "The score of relevancy is :", similar("Hello",str) * 100 ,""

You can change the result according to your requirements. Thanks