I'd like to replace a string to fix the notation in python.
For example, suppose you have "green onion", "long onion", "kujo onion" in the text. I want to replace all the words that contain "leeks" with "leeks".
I can't find anything that suits what I want to do even after searching.
With replace () you can only replace one word, and it takes a long time to write all the patterns.
Is there any good way?
Is it possible to replace a green onion, a long onion, or a Kujo onion instead of specifying a green onion? If there are many types, it is difficult to grasp everything and it is difficult to write all patterns.
Answer # 1
Replace all words that contain "leeks" with "leeks"
To do this, you first need to do a morphological analysis.
I only need to know the word to replace.
Answer # 2
Carnegie Hall, Negitro, Koganegiku, Magical Teacher Negima, Negishi Systex, Takamine Guitar, etc.
In simpler terms, are onions and leeks together?
(The above is obviously a bad example. The onion and the onion are different depending on what you want to make)
It takes a lot of work to maintain a dictionary manually, or to search for word-like sequences by summing up the frequency of neighborhoods of characters from large-scale text data.
Also, I think that it is quite difficult to automatically judge whether you can put together as a representative just because they match. Whether it can be adopted as a hierarchical relationship of concepts is a process that must be made from information that is still manpowered or manually organized.
Is it possible to replace a green onion, a long onion, or a Kujo onion instead of a green onion? If there are many types, it is difficult to grasp everything and it is difficult to write all patterns.
If there is a kind of data that is difficult to understand,if it is true, when writing in a pattern, "how much should have been rewritten "Is there anything that should be rewritten and how much has been leaked?"I can't measure.
It's trying to make a system that doesn't know how well it works.
If "There are so many kinds that it is difficult to grasp everything" is correct, it is better to avoid rewriting with patterns.
Is it true that there are so many kinds that are difficult to grasp?
(Since there are many users and error collection can be done gradually after operation, it may be coarse at first, but it would be nice to talk like that)
Answer # 3
It is better to use regular expressions Is it not? Use the
In : import re In : target = 'Green onion, long onion and Kujo onion are onions' In : re.sub ('(blue | long | kujo) leek', 'leek', target) Out : 'Onions, leeks and leeks are leeks'
'(Blue | Long | Kujo) Leek'is a word that is blue, long or Kujo followed by a leek
Answer # 4
Please try google search.
A variety of information can be obtained quickly from the answers.
Although it is necessary to judge whether the information is good or bad, it should be the same for the answers on the QA site.
Answer # 5
If you try to do it straightforwardly, complex natural language processing is likely to be required.
However, whether or not you really need it depends on the purpose of use. So please indicate what you want to use.
- python - i want to replace only the exact string
- python 27 - i want to check if | is included in the string in python
- python - i want to extract the character string excluding the blank characters at the end of the line
- python - how to assign two functions to a string
- i want to replace and delete the character string acquired from gmail with google apps script and output it to google spreadshee
- python - how to cycle the input string
- python - could not convert string to float error
- python - i want to replace the y axis of the graph drawn with matplotlob with a character string
- i want to handle backslashes in string replacement in python
- python3 string array combination code creation
- converting time sequence of number string using python
- python 3x - i want to read a string from a file in python
- python - i read the character string in the file and judge it, but i cannot judge the decimal
- python - beautifulsoup with a specific string
- in cgi script of python, i want to get the query string when the query string of the url is "? value"
- python - i want to judge and extract the character string of a specific column by pandas with a numerical value
- error when deleting a word (conjunction) using replace and strip in python and storing sentences individually in a list
- python 3x - python3 string processing
- python3 string type'b'is attached
- i don't know the format of pascal string in python struct
- python3 string type'b'is attached
- i don't know how to output python predicted value
- i want to replace every other character using python regular expression
- call function dynamically in python
- i want to check python files
- python - regarding the problem of replacing unintended characters when replacing strings
- object oriented in python tkinter
- about output to excel using python openpyxl library
- i want to process sql data in python and create a graph (i made it, but it is heavy)
- python - optuna light-library import error in gbm parameter tuning