python - How could I search specific strings from a text file? -
my file looks this:
review/summary: beautiful basic pump... review/text: ... not plenty sizes or colors. fits true size on size 8-1/2 feet.bottom soles slick... needs kind of texturing or tread help prevent slipping. review/text: it's amazing.firstly, 1 not original gil zero, gil 0 td, means not have technique.however, it's comfortable sneaker i've ever know. without expensive technique, it's mid-sole more soft , much more durable. , upper changed real leather, it's became more fit able foot. changes makes improve sneaker expensive original one, great design of real great sneaker, not useless, mutual people not superstar, technique. , on court, found plenty cushion , give more speed, first-class 1 guard or little forward.
i want extract strings such quick service
, excellent service
, amazon great
, excellent client service
my code looks this:
def ethos(file): f = open(file) raw = f.read() tokens = nltk.sent_tokenize(raw) text = nltk.text(tokens) sents = [] matching_strings = ['thanks amazon' , 'great service' , 'reasonable shipping time' , 'quick service'] tokens in text: if tokens in matching_strings: sents.append(tokens) homecoming sents
my output blank, kindly allow me know how approach correctly, i'm new language processing
i've never used nltk, i'll create guess @ solution. since tokens sentences, need matching strings in token , not other way around have now. loop should this:
for tokens in text: match in matching_strings: if match in tokens: sents.append(tokens) break homecoming sents
python nltk
No comments:
Post a Comment