I am working on a school project and have a function that recognized a comment and finds the information from the comment and writes it down to a file. When how could I check an input string against a list of strings of information. Like if I have an input

input = "How many fingers do I have?"

How do I check which of these is closest to it?

fingers = "You have 10."
pigs = "yummy"

I want it to respond with fingers. I want to match it with the variable name and not the variable's value.

有帮助吗?

解决方案

I suggest you to read this chapter. This is a chapter from Natural Language Processing with Python, by Steven Bird, Ewan Klein and Edward Loper.

Detecting patterns is a central part of Natural Language Processing. Words ending in -ed tend to be past tense verbs (5). Frequent use of will is indicative of news text (3). These observable patterns — word structure and word frequency — happen to correlate with particular aspects of meaning, such as tense and topic. But how did we know where to start looking, which aspects of form to associate with which aspects of meaning?

The goal of this chapter is to answer the following questions:

How can we identify particular features of language data that are salient for classifying it? How can we construct models of language that can be used to perform language processing tasks automatically? What can we learn about language from these models?

It all described in python, and it's very efficient.

http://www.nltk.org/book/ch06.html

Also, processing the text by using a keyword that matches a variable name is not good and not efficient. I won't recommend it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top